Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@zapier/secret-scrubber

Package Overview
Dependencies
Maintainers
285
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zapier/secret-scrubber

Confidently remove secrets and sensitive values from unstructured objects.

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
285
Created
Source

secret-scrubber-js

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.

Installation + Quick Start

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'
//   }
// }

API

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:

  1. as-is (no transform)
  2. percent encoded (via encodeURIComponent)
  3. percent encoded, but strings are replaces with +
  4. via JSON.stringify, so secrets with control characters

You 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:

  • any value tied to a typically sensitive key (such as authorization or password)
  • the username, password, and all querystring items with sensitive keys from any URL

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:

  • if the value is an object, the function recurses
  • if the value is an array, we iterate each element:
    • if the element is an object or array, we recurse
    • otherwise, we call the matcher with only the value (matcher('', value))
  • otherwise, we pass the key and value to the matcher. If it's true, we collect the value

Versioning

This project uses SemVer as its versioning scheme.

  • Major versions will change change the public API (changing call signatures of exported functions or removing/renaming them entirely) or change platform support (aka, dropping support for older versions of Node.js)
  • Minor versions will add options, exported functions, or add transforms (see the the list of current transforms)
  • Patch versions will be internal bug fixes that don't affect either of the above cases

Deploying New Versions

To release a new version publicly on the npm registry, do the following:

  • Create a PR that updates the version in package.json and updates the CHANGELOG.md with the new version number.
  • Once that's approved merge it.
  • in CI, once tests pass, there's a "deploy" button. Clicking it will run the job that releases whatever version is in package.json on the main branch.

Created using generator-xavdid during the Summer '21 Zapier hackathon.

FAQs

Package last updated on 08 May 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc