Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
@zapier/secret-scrubber
Advanced tools
Confidently remove secrets and sensitive values from unstructured objects.
secret-scrubber
is a JS package for removing sensitive data (such as passwords or API secrets) from arbitrary objects. It was written by Zapier to programmatically censor user logs without knowing what we were looking for.
yarn add @zapier/secret-scrubber
There are two main functions:
scrub
takes an object/array/string and an array of sensitive strings. It returns the input with anything from the sensitive array censored.findSensitiveValues
uses our battle-tested heuristics to guess which values should be censored in an object.Used together, these functions make it easy to pull sensitive data out of a user-supplied object without knowing the exact secrets you're looking for. To get value from this library, it's very important to use the scrub
function. Without its transform logic, there's a much greater chance of leaking secrets. See the scrub docs for more info about the transforms.
Here's an example:
import { scrub, findSensitiveValues } from '@zapier/secret-scrubber'
scrub('Hey there! The password is "very-secret-password"', [
'very-secret-password',
])
// 'Hey there! The password is ":censored:20:7991f05acc:"'
const request = {
url: 'https://site.com?api_key=this%20is%20my%20key',
body: {
text: 'The password is "this is my key"',
},
headers: {
authorization: 'Basic ZGF2aWQ6aHVudGVyMg==',
accept: 'application/json',
},
}
findSensitiveValues(request)
// [
// 'this is my key',
// 'Basic ZGF2aWQ6aHVudGVyMg=='
// ]
scrub(request, findSensitiveValues(request))
// {
// url: 'https://site.com?api_key=:censored:14:5538025964:',
// body: { text: 'The password is ":censored:14:5538025964:"' },
// headers: {
// authorization: ':censored:26:861bf51897:',
// accept: 'application/json'
// }
// }
The following are the functions exported by this package:
scrub
scrub: (input: object | any[] | string, secretValues: Array<string | number>) =>
any
Recursively removes any version of each secretValue
found in input
. It looks for secrets both as plaintext and after a number of transformations. For instance, it you pass 'secret code'
as a secret, it properly censors https://example.com?key=secret%20code
. It currently performs the following transforms:
+
JSON.stringify
, so secrets with control charactersYou can supply your own list of secret values (if you know them) or use one of the below functions to help extract a list of secrets.
findSensitiveValues
findSensitiveValues: (obj: object) => string[]
A convenience function to find potentially sensitive data in objects. It grabs:
authorization
or password
)recurseExtract
recurseExtract: (obj: object | any[], matcher: (key: string, value: any) => boolean): string[]
The underlying recursive function that powers findSensitiveValues
. It takes an object to recurse and a matcher function. It returns stringified versions of any values that were found in the below steps. It's algorithm is as follows:
In the root object, each key/value pair are passed to the matcher
function. Then:
matcher('', value)
)This project uses SemVer as its versioning scheme.
To release a new version publicly on the npm
registry, do the following:
version
in package.json
and updates the CHANGELOG.md
with the new version number.package.json
on the main
branch.Created using generator-xavdid during the Summer '21 Zapier hackathon.
FAQs
Confidently remove secrets and sensitive values from unstructured objects.
We found that @zapier/secret-scrubber demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 285 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.