All Projects → nickdeis → eslint-plugin-no-secrets

nickdeis / eslint-plugin-no-secrets

Licence: MIT license
An eslint plugin to find strings that might be secrets/credentials

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to eslint-plugin-no-secrets

eslint-config-get-off-my-lawn
A highly opinionated, sharable config of ESLint rules to produce beautiful, readable JavaScript.
Stars: ✭ 44 (-52.69%)
Mutual labels:  eslint-plugin, eslint-rules
eslint-plugin-no-only-tests
ESLint rule for catching focused/only test blocks
Stars: ✭ 67 (-27.96%)
Mutual labels:  eslint-plugin, eslint-rules
Xo
❤️ JavaScript/TypeScript linter (ESLint wrapper) with great defaults
Stars: ✭ 6,277 (+6649.46%)
Mutual labels:  eslint-plugin, eslint-rules
eslint-plugin-strict-vue
Vue eslint plugin with rules to make you code stricter: enforce jsdoc, restrict rootGetters, rootState and more.
Stars: ✭ 28 (-69.89%)
Mutual labels:  eslint-plugin, eslint-rules
Eslint Plugin Unicorn
Various awesome ESLint rules
Stars: ✭ 2,157 (+2219.35%)
Mutual labels:  eslint-plugin, eslint-rules
eslint-plugin-gridsome
ESLint plugin for Gridsome
Stars: ✭ 45 (-51.61%)
Mutual labels:  eslint-plugin
eslint-plugin-diff
Run ESLint on your changes only
Stars: ✭ 80 (-13.98%)
Mutual labels:  eslint-plugin
eslint-plugin-license-header
Rules to validate the presence of license headers in source files.
Stars: ✭ 21 (-77.42%)
Mutual labels:  eslint-plugin
ultimate-hot-boilerplate
🚀 node-react universal app boilerplate with everything on hot reload, SSR, GraphQL, Flow included
Stars: ✭ 35 (-62.37%)
Mutual labels:  eslint-plugin
eslint-plugin-mongodb
🔎 MongoDB best practices rules for ESLint
Stars: ✭ 17 (-81.72%)
Mutual labels:  eslint-plugin
eslint-plugin-chai-friendly
Makes eslint friendly towards Chai.js 'expect' and 'should' statements.
Stars: ✭ 49 (-47.31%)
Mutual labels:  eslint-plugin
eslint-config-xo-flow
ESLint shareable config for Flow to be used with eslint-config-xo
Stars: ✭ 24 (-74.19%)
Mutual labels:  eslint-rules
eslint-plugin-aura
Salesforce Lightning (Aura) specific linting rules for ESLint
Stars: ✭ 24 (-74.19%)
Mutual labels:  eslint-plugin
eslint-plugin-yml
This ESLint plugin provides linting rules for YAML.
Stars: ✭ 40 (-56.99%)
Mutual labels:  eslint-plugin
eslint-plugin-vue-scoped-css
ESLint plugin for Scoped CSS in Vue.js
Stars: ✭ 58 (-37.63%)
Mutual labels:  eslint-plugin
eslint-config-leapfrog
Set of ESLint rules for JavaScript projects at Leapfrog.
Stars: ✭ 15 (-83.87%)
Mutual labels:  eslint-rules
eslint-plugin-header
ESLint plugin to ensure that files begin with given comment
Stars: ✭ 65 (-30.11%)
Mutual labels:  eslint-plugin
eslint-plugin-googleappsscript
ESLint plugin for Google Apps Script environment
Stars: ✭ 37 (-60.22%)
Mutual labels:  eslint-plugin
eslint-plugin-strict-dependencies
ESlint plugin to define custom module dependency rules.
Stars: ✭ 142 (+52.69%)
Mutual labels:  eslint-plugin
eslint-plugin-array-func
Rules for Array functions and methods.
Stars: ✭ 77 (-17.2%)
Mutual labels:  eslint-plugin

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

Option Description Default Type
tolerance Maximum "randomness"/entropy allowed 4 number
additionalRegexes Object of additional patterns to check. Key is check name and value is corresponding pattern {} {[regexCheckName:string]:string | RegExp}
ignoreContent Will 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)[]
ignoreModules Ignores strings that are an argument in import() and require() or is the path in an import statement. true boolean
ignoreIdentifiers Ignores the values of properties and variables that match a pattern or an array of patterns. [] string | RegExp | (string|RegExp)[]
ignoreCase Ignores character case when calculating entropy. This could lead to some false negatives false boolean
additionalDelimiters In 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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].