@amaabca/sensitive-param-filter

中文文档
1.2.10发布于 2024/09/06MITCommonJS零依赖近 30 天下载 2322

A package for filtering sensitive data (parameters, keys) from a variety of JS objects

原始使用文档
文档目录7 节
  1. Installation
  2. Usage
  3. Details
  4. Key Features
  5. Options
  6. Default Values
  7. License & Contributing

Sensitive Param Filter

Build Status

sensitive-param-filter is a zero-dependency package designed to filter sensitive values from JavaScript objects. This package can be used to scrub logs, filer data before outputting to a UI, etc. The defaults provided with sensitive-param-filter should work well for most applications.

Installation

Install sensitive-param-filter to your project via either npm:

npm install @amaabca/sensitive-param-filter

or yarn:

yarn add @amaabca/sensitive-param-filter

Usage

const { SensitiveParamFilter } = require('@amaabca/sensitive-param-filter')
const paramFilter = new SensitiveParamFilter()
const rawObject = {
  Authorization: 'Bearer somedatatoken',
  body: {
    info: '{ "amount": 28.64, "credit_card": "4242424242424242", "cvv": "123" }'
  },
  method: 'POST',
  url: 'https://pay.example.com?user=bob.bobbington&password=asecurepassword1234'
}
const filteredObject = paramFilter.filter(rawObject)
// filteredObject = {
//   Authorization: 'FILTERED',
//   body: {
//     info: '{ "amount": 28.64, "credit_card": "FILTERED", "cvv": "FILTERED" }'
//   },
//   method: 'POST',
//   url: 'https://pay.example.com?user=bob.bobbington&password=FILTERED'
// }

Details

sensitive-param-filter examines keys to determine which values to filter. Key matching is done in a case-insensitive, partial-macthing manner (that is, if the param AUTH is provided, Authorization, AUTHENTICATION, etc. will be filtered).

Key Features

  • Does not modify input objects
  • Performs a deep copy of the input object (note that booleans, numbers, and strings - which are immutable - are technically copied by reference)
  • Can be configued to filter out or leave "unexpected" objects (such as functions)
  • Handles circular references
  • Filters valid JSON strings
  • Filters valid and malformed URL query params
  • Filters Errors, Arrays, Maps, Sets, and simple objects

Options

const { SPFDefaultParams, SensitiveParamFilter } = require('@amaabca/sensitive-param-filter')
const filter = new SensitiveParamFilter({
  filterUnknown: false,
  params: SPFDefaultParams.concat(['data', 'email']),
  replacement: '***',
  whitelist: ['authentic', 'encryption_standard']
})
  • filterUnknown: Indicates whether "unexpected" objects (such as functions) should be filtered or returned as-is. Defaults to true

  • params: An array of string params to filter. These entries will be combined into a regex that is used by sensitive-param-filter. Setting this option overwrites the default array (SPFDefaultParams).

  • replacement: The object to replace filtered values with. Defaults to 'FILTERED'.

  • whitelist: An array of strings to exclude from filtering. For example, if pass_through is including in the whitelist, the key pass_through will not be filtered. Note that entries must match keys exactly to prevent filtering - that is, whitelisting secrets still causes secrets_store to be filtered.

Default Values

See defaults. Note that all of these values can be overridden via the options.

The default keys that are filtered are:

  • auth
  • bearer
  • credit
  • CVD
  • CVV
  • encrypt
  • PAN
  • pass
  • secret
  • token

License & Contributing

sensitive-param-filter uses the MIT license. See the license.

We welcome contributions. See contributing.

版本与发布记录

@amaabca/sensitive-param-filter 共发布 23 个版本,首次发布于 2019/10/05;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.2.10latest2024/09/062 年前
1.2.92024/05/222 年前
1.2.82023/10/273 年前
1.2.72023/04/143 年前
1.2.62023/02/103 年前
1.2.52023/01/203 年前

关于 @amaabca/sensitive-param-filter 的常见问题

@amaabca/sensitive-param-filter 是什么?

A package for filtering sensitive data (parameters, keys) from a variety of JS objects

如何安装 @amaabca/sensitive-param-filter?

在项目目录运行 npm install @amaabca/sensitive-param-filter,或使用 pnpm add / yarn add / bun add。

@amaabca/sensitive-param-filter 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/amaabca__sensitive-param-filter 是否存在。

@amaabca/sensitive-param-filter 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@amaabca/sensitive-param-filter 可以商用吗?

@amaabca/sensitive-param-filter 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@amaabca/sensitive-param-filter 的下载量有多少?

根据 npm 官方下载统计,@amaabca/sensitive-param-filter 在 2026/10/06 – 2026/11/04 这 30 天内被下载 2,322 次,日均约 77 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@amaabca/sensitive-param-filter 还在维护吗?

最新版本 1.2.10 发布于 2024/09/06(2 年前);至今共发布 23 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/10/05。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。