@zapier/secret-scrubber
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

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.

Readme

Keywords

none

Package Sidebar

Install

npm i @zapier/secret-scrubber

Weekly Downloads

15,299

Version

1.1.0

License

ISC

Unpacked Size

24.5 kB

Total Files

11

Last publish

Collaborators

  • lisa.zapier
  • david.jardine-zapier
  • david.graves-zapier
  • ana.krivokapic-zapier
  • jacob.blakely-zapier
  • ryan.detzel-zapier
  • brody-zapier
  • mason.jones-zapier
  • ben.rugg-zapier
  • nicole.hardson-hurley-zapier
  • bryce.seagervandyk-zapier
  • christophe.coutzoukis-zapier
  • jessica.winters-zapier
  • cameron.barnes-zapier
  • wojciech.matuszewski-zapier
  • ankit.gordhandas-zapier
  • chrys.swingler-zapier
  • ryan.vennell-zapier
  • benjamin.kempe-zapier
  • ali.tycast-zapier
  • jelani.jackson-zapier
  • jdotcee
  • jeanny.sy
  • james.hong-zapier
  • dennis.kailikia-zapier
  • tom.leung-zapier
  • service-account-renovate
  • erin.williams-zapier
  • desmond.morris-zapier
  • nolan.little-zapier
  • nik.danilov-zapier
  • michal.wysocki-zapier
  • tomasz.piechota-zapier
  • nate.moore-zapier
  • corbin.schwartz-zapier
  • andrew.kordampalos-zapier
  • jonathan.harrell-zapier
  • jc.coto-zapier
  • andrew.gosnell-zapier
  • amber.diehl-zapier
  • vivian.lau-zapier
  • osarhomiyeke.iyere-zapier
  • kristen.keller-zapier
  • blzapier
  • tal.peretz-zapier
  • shanan.holm-zapier
  • vj.clasgens-zapier
  • marina.hand
  • aubry.stewart-zapier
  • aleks.ozolins-zapier
  • abraham.duran-zapier
  • abdullah.umar-zapier
  • rohit.tripathi-zapier
  • nadia.welter-zapier
  • mike.lambert-zapier
  • ted.schmidt-zapier
  • laura.giles-zapier
  • nitish.upadhyay-zapier
  • catherine.murray-zapier
  • ken.ng-zapier
  • omar.delossantos-zapier
  • ryan.laxson-zapier
  • pedro.louro-zapier
  • zac.jones-zapier
  • brandon.parker-zapier
  • alec.hinh-zapier
  • maggie.cody-zapier
  • mary.rising-zapier
  • harrison.jackson-zapier
  • alex.hovancik-zapier
  • matthew.kiernander-zapier
  • philip.ng-zapier
  • daniel.shepard-zapier
  • sharvari.desai-zapier
  • jenna.macdonald-zapier
  • rval-zapier
  • ryan.dunnewold-zapier
  • ashley.isles-zapier
  • service-account-catalog
  • tazrafiq
  • jayson.kadlecek-zapier
  • ismail.latona-zapier
  • kasey.cowley-zapier
  • sarah.hernandez-zapier
  • aaron.kosel-zapier
  • iris.huang-zapier
  • zapier-interfaces
  • vitor.balocco-zapier
  • scott.woodend-zapier
  • emily.harris-zapier
  • sandy.brydon-zapier
  • brian.wendt-zapier
  • lauriemrauch
  • ron.swanson-zapiertest
  • dilan-zapier
  • katestamzap
  • jhk2020
  • percy_at_zapier
  • tupelo8
  • dewayne-zapier
  • sarahstory
  • raquel.zapier
  • danielheidornzap
  • alex.black
  • katesowles
  • jacquelynmccray
  • schlickmann
  • cody.landry
  • hgascoigne
  • ahsanhassan
  • kaushib
  • nkroeker_zap
  • recamilio
  • andyzapier
  • nataliemona
  • ariella-zapier
  • valeriia.shpiner
  • rchinerman
  • miklossimon
  • amickael-zap
  • sethetter
  • yohana-heringer
  • rebecca.davis.zapier
  • ben.clapp.zapier
  • mattplachter
  • mirrenzap
  • lizzyzap
  • colemaclean
  • sdelosrios95
  • magweaver
  • joseph-corona-zapier
  • nickaccuardizapier
  • raul.negron
  • normanroa
  • fernando.velascosalazar
  • manasseh_zapier
  • davidwin-zap
  • shpzap
  • gabebravo
  • annader-zapier
  • aparkin
  • abhi-kapoor
  • blakek
  • chasehamby
  • zoeykim-zapier
  • djeebus
  • xavierh-zapier
  • kalenwessel
  • lev.glick
  • greg-zapier
  • david.zapier
  • joel.taddei
  • robert.lewis
  • plorry
  • ilari.scheinin
  • msholty
  • poterekm
  • fgrafa
  • dayne-taitt
  • josuezap
  • pwhamman
  • omar.raza
  • adampie
  • erikamontani
  • standielpls
  • mdgreenwald
  • karljs
  • loveena.vattenky
  • jasehackman
  • tims256
  • zapetc
  • chaodonghu
  • emma-hays
  • michaelann
  • jdaudier
  • joaopimentel
  • ryanmrubin
  • ter0
  • rghazali
  • rsiemens
  • casshill13
  • eliang
  • noahmanger
  • kola-er
  • codebycaleb
  • calebpeterson
  • jordyvd
  • victoravasiloaei
  • lukecjohnson
  • zapier-engineering
  • stevemolitor
  • jdeal
  • bcooksey
  • bryanhelmig
  • robgolding
  • fokkezb
  • sam.plant
  • michaelgilley
  • mlukso
  • mikekuchera
  • joanne
  • juanv
  • ibrahem.zayed
  • muyiwa.olurin
  • jamesacarr
  • mikeknoop
  • josh.newman
  • parsenz
  • larryt
  • rhubbard
  • jacobsowles
  • jacebrowning
  • stacietaylorcima
  • linhvo
  • hitchcockwill
  • renaekathleen
  • chelsea.weber
  • reganstarrzapier
  • cyberwitch
  • veebers
  • thomir
  • shalgrim
  • season.huang
  • chris.vanderkolk.zapier
  • mattbowers-zapier
  • nickm0501
  • kaycee
  • owarij
  • brian.corbin
  • darko.ronic.zapier
  • kredlear
  • numichuu
  • justin.zapier
  • chelschubb
  • skylershaw
  • daniel-frazier
  • aaclarker-zap
  • tiffanie
  • errorific
  • ezerwx
  • lijenni
  • jasonkotenko
  • wernertc
  • cortega_zp
  • tkcranny
  • brandon.myers.zapier
  • matthewwalters
  • kat.nestor
  • andya-zapier
  • iansco
  • will.wiggins
  • rondiege
  • annaulyanova
  • bskaurud
  • leons
  • kaitrin.cox
  • jeansimon
  • kimgault
  • rocioar
  • milkram
  • mburni
  • peterbritnell
  • guivasconcelos-zapier
  • carolinezapier
  • emmaielle
  • jeanetteu
  • ismael.mendonca
  • bbohen
  • sugatmahanti
  • nicole.thomas
  • ramon.prieto
  • phoydar
  • agscala
  • jordanraleigh
  • josh.barber
  • kamalsingh.naruka
  • sno6
  • robertscl
  • wavebeem
  • laurenmbeatty
  • ankush_zapier
  • ihor.horak
  • keren-zapier
  • maxwellgbrown
  • hanz.cortes
  • alejandro-lagos