0.9.1 • Published 7 days ago

eslint-plugin-no-secrets v0.9.1

Weekly downloads
22,912
License
MIT
Repository
github
Last release
7 days ago

Build Status

eslint-plugin-no-secrets

An eslint rule that searches for potential secrets/keys in code and JSON files.

1. Usage

npm i -D eslint-plugin-no-secrets

.eslintrc

{
   "plugins":["no-secrets"],
   "rules":{
       "no-secrets/no-secrets":"error"
   }
}
//Found a string with entropy 4.3 : "ZWVTjPQSdhwRgl204Hc51YCsritMIzn8B=/p9UyeX7xu6KkAGqfm3FJ+oObLDNEva"
const A_SECRET = "ZWVTjPQSdhwRgl204Hc51YCsritMIzn8B=/p9UyeX7xu6KkAGqfm3FJ+oObLDNEva";
//Found a string that matches "AWS API Key" : "AKIAIUWUUQQN3GNUA88V"
const AWS_TOKEN = "AKIAIUWUUQQN3GNUA88V";

1.1. Include JSON files

To include JSON files, install eslint-plugin-jsonc

npm install --save-dev eslint-plugin-jsonc

Then in your .eslint configuration file, extend the jsonc base config

{
    "extends": [
        "plugin:jsonc/base"
    ]
}

2. Config

Decrease the tolerance for entropy

{
   "plugins":["no-secrets"],
   "rules":{
       "no-secrets/no-secrets":["error",{"tolerance":3.2}]
   }
}

Add additional patterns to check for certain token formats.
Standard patterns can be found here

{
 "plugins": ["no-secrets"],
 "rules": {
   "no-secrets/no-secrets": [
     "error",
     { "additionalRegexes": { "Basic Auth": "Authorization: Basic [A-Za-z0-9+/=]*" } }
   ]
 }
}

3. When it's really not a secret

3.1. Either disable it with a comment

// Set of potential base64 characters
// eslint-disable-next-line no-secrets/no-secrets
const BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

This will tell future maintainers of the codebase that this suspicious string isn't an oversight

3.2. use the ignoreContent to ignore certain content

{
   "plugins":["no-secrets"],
   "rules":{
       "no-secrets/no-secrets":["error",{"ignoreContent":"^ABCD"}]
   }
}

3.3. Use ignoreIdentifiers to ignore certain variable/property names

{
   "plugins":["no-secrets"],
   "rules":{
       "no-secrets/no-secrets":["error",{"ignoreIdentifiers":["BASE64_CHARS"]}]
   }
}

3.4. Use additionalDelimiters to further split up tokens

Tokens will always be split up by whitespace within a string. However, sometimes words that are delimited by something else (e.g. dashes, periods, camelcase words). You can use additionalDelimiters to handle these cases.

For example, if you want to split words up by the character . and by camelcase, you could use this configuration:

{
   "plugins":["no-secrets"],
   "rules":{
       "no-secrets/no-secrets":["error",{"additionalDelimiters":[".","(?=[A-Z][a-z])"]}]
   }
}

4. Options

OptionDescriptionDefaultType
toleranceMinimum "randomness"/entropy allowed. Only strings above this threshold will be shown.4number
additionalRegexesObject of additional patterns to check. Key is check name and value is corresponding pattern{}{[regexCheckName:string]:string | RegExp}
ignoreContentWill ignore the entire string if matched. Expects either a pattern or an array of patterns. This option takes precedent over additionalRegexes and the default regular expressions[]string | RegExp | (string|RegExp)[]
ignoreModulesIgnores strings that are an argument in import() and require() or is the path in an import statement.trueboolean
ignoreIdentifiersIgnores the values of properties and variables that match a pattern or an array of patterns.[]string | RegExp | (string|RegExp)[]
ignoreCaseIgnores character case when calculating entropy. This could lead to some false negativesfalseboolean
additionalDelimitersIn addition to splitting the string by whitespace, tokens will be further split by these delimiters[](string|RegExp)[]

5. Acknowledgements

Huge thanks to truffleHog for the inspiration, the regexes, and the measure of entropy.

eslint-config-slick@typhoon41/eslint-vue-config@infinitebrahmanuniverse/nolb-eslint-plugin-n@everything-registry/sub-chunk-1613@finale-lua/eslint-config@developer-kit/eslint-config@codeday/eslint-config@compositive/eslint-config@dbos-inc/eslint-pluginweb-ui-deps@voiceflow/eslint-config@voltiso/config.eslint@voltiso/eslint-config@voltiso/eslint-config-fast@xtrctio/eslint-config@xylabs/eslint-config@xylabs/eslint-config-base@xylabs/eslint-config-flat@xylabs/eslint-config-react@xylabs/eslint-config-react-base@vue-storefront/eslint-config@atomspace/eslint@authentiqagency/eslint-config@bothrs/eslint-config@bodrick/eslint-config@bootcamp-project/eslint-config@bootcamp-project/eslinttier@bosscard/eslint-config@anolilab/eslint-config@vdl-dev/eslint-config@actualsize/eslint-config@al/eslint-config-alertlogic@alexlit/config-eslint@techsky/eslint-config@typhoon41/eslint-config@handy-eco/eslint-config@hendacorp/eslint-plugin@gravis-os/eslint-config@wasc/tools@warrify/eslint-config@washingtondc/eslinteslint-config-strict-modeeslint-config-suiyobieslint-config-tailseslint-config-tuxsncteslint-plugin-maintainableeslint-plugin-mist3rbru@lottiefiles/eslint-plugin@hug/eslint-config@mist3rbru/eslint-config@morev/eslint-config@mattcampbell/eslint-config@mblabs/eslint-config@megabytelabs/eslint-config@nick-mazuk/eslint-config@nimec/eslint-config@launchbadge/eslint-configeslint-config-brandingbrandeslint-config-dsx-baseeslint-config-rocketeslint-config-safe-security@revved/eslint-config-node@revved/eslint-config-react@roleup/eslint-config@j0hnm4r5/eslint-configeslint-config-heimdalleslint-config-intenseeslint-config-noteeslint-config-nirtamir2eslint-config-noamkadosheslint-config-platypuseslint-config-re-taroeslint-config-lifioneslint-config-lifion-webeslint-config-meienbergereslint-config-mimiceslint-config-reform-collectiveeslint-config-airlight-baseeslint-config-archisquadeslint-config-architowereslint-config-backendeslint-config-bis-baseeslint-config-bis-react@pumpn/eslint-config@slick_kilmister/node-dev-config@searchspring/eslint-config@eslegant/js@enigmatry/eslint-config@enormora/eslint-config-base@emhamzahazeen/eslint-config-base@ehacke/eslint-config@snowball-tech/eslint-config@stillmine/eslint-config@suncin/eslint-config-typescript
0.9.0

7 days ago

1.0.1-eslint9

7 days ago

0.9.1

7 days ago

1.0.0-eslint9

7 days ago

0.8.9

3 years ago

0.7.9

3 years ago

0.6.8

4 years ago

0.6.5

4 years ago

0.6.4

4 years ago

0.5.4

4 years ago

0.3.4

5 years ago

0.3.3

5 years ago

0.2.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago