Skip to content

Commit

Permalink
Typescript conversion (#1)
Browse files Browse the repository at this point in the history
Rewrote the entire library in typescript:
- All code & tests in TS
- Separated large fixture objects into fixture file
- Added `tsconfig.json` and appropriate `eslint` rules

along with a whole bunch of other small changes:
 - Update node version to 20
 - Add `prettier`
 - Fix security vulnerabilities + general package updates
 - Add `dpdm` for circular reference checks
 - Update git workflow to run all checks, not just tests
 - Add `.code-workspace` file with recommended extensions, etc.
  • Loading branch information
zjullion authored Jan 15, 2024
1 parent 982cf21 commit c9c2ddc
Show file tree
Hide file tree
Showing 21 changed files with 3,663 additions and 5,226 deletions.
563 changes: 259 additions & 304 deletions .eslintrc.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
os: [windows-latest, macos-latest, ubuntu-latest]
node-version: ['16', '18']
node-version: ['18', '20']
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -18,7 +18,7 @@ jobs:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: npm install
- name: Run tests
run: npm run test
- name: Run validations
run: npm run validate
env:
CI: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules
coverage
dist

.vscode
.npmrc
7 changes: 6 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
node_modules
coverage
test
dist/test

.github
.publish-config

.vscode
.eslintrc.json
.travis.yml
CONTRIBUTING.md
package-lock.json
.gitattributes
.nvmrc
.prettierrc
sensitive-param-filter.code-workspace
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18.15.0
20.10.0
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"printWidth": 100,
"semi": false,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "all",
"useTabs": false
}
68 changes: 34 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ const paramFilter = new SensitiveParamFilter()
const rawObject = {
Authorization: 'Bearer somedatatoken',
body: {
info: '{ "amount": 28.64, "credit_card": "4242424242424242", "cvv": "123" }'
info: '{ "amount": 28.64, "credit_card": "4242424242424242", "cvv": "123" }',
},
method: 'POST',
url: 'https://pay.example.com?user=bob.bobbington&password=asecurepassword1234'
url: 'https://pay.example.com?user=bob.bobbington&password=asecurepassword1234',
}
const filteredObject = paramFilter.filter(rawObject)
// filteredObject = {
Expand All @@ -47,13 +47,13 @@ Key matching is done in a case-insensitive, partial-macthing manner (that is, if

### 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
- 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

Expand All @@ -63,27 +63,27 @@ const filter = new SensitiveParamFilter({
filterUnknown: false,
params: SPFDefaultParams.concat(['data', 'email']),
replacement: '***',
whitelist: ['authentic', 'encryption_standard']
whitelist: ['authentic', 'encryption_standard'],
})
```

* **filterUnknown:**
Indicates whether "unexpected" objects (such as functions) should be filtered or returned as-is.
Defaults to `true`
- **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`).
- **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'`.
- **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.
- **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

Expand All @@ -92,16 +92,16 @@ 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
- auth
- bearer
- credit
- CVD
- CVV
- encrypt
- PAN
- pass
- secret
- token

## License & Contributing

Expand Down
Loading

0 comments on commit c9c2ddc

Please sign in to comment.