@secretlint/secretlint-rule-pattern
v11.6.0
Published
A secretlint rule that checks for regex patterns stored in configuration.
Readme
@secretlint/secretlint-rule-pattern
A secretlint rule that checks for RegEx patterns
Install
Install with npm:
npm install @secretlint/secretlint-rule-patternUsage
Via .secretlintrc.json(Recommended)
{
"rules": [
{
"id": "@secretlint/secretlint-rule-pattern",
"options": {
"patterns": [
{
"name": "credentials",
"patterns": [
"/password\\s*=\\s*(?<password>[\\w\\d!@#$%^&(){}\\[\\]:\";'<>,.?\/~`_+-=|]{1,256})\\b.*/",
"/apikey\\s*=\\s*(?<apikey>[\\w\\d]{8,})\\b.*/",
"/token\\s*=\\s*(?<token>[\\w\\d]{16,})\\b.*/"
]
}
]
}
}
]
}
Using filePathGlobs
You can use filePathGlobs to match against file paths using glob patterns:
{
"rules": [
{
"id": "@secretlint/secretlint-rule-pattern",
"options": {
"patterns": [
{
"name": "env files",
"filePathGlobs": ["**/.env", "**/.env.*"]
},
{
"name": "AWS credentials in env files",
"filePathGlobs": ["**/.env*"],
"patterns": [
"/aws_access_key_id\\s*=\\s*\\S+/i",
"/aws_secret_access_key\\s*=\\s*\\S+/i"
]
},
{
"name": "private keys",
"filePathGlobs": ["**/*.pem", "**/*.key"],
"patterns": [
"/BEGIN (RSA |EC )?PRIVATE KEY/"
]
}
]
}
}
]
}- When only
filePathGlobsis specified, the rule reports if the file path matches any of the glob patterns - When only
patternsis specified, the rule reports if the file content matches any of the regex patterns - When both are specified, the rule reports only if both the file path matches the glob AND the content matches any of the patterns
MessageIDs
Pattern
found matching {{pattern.name}}: {{CREDENTIAL}}
Disallow to use specified RegEx patterns from SecretLint config.
Options
allows: string[]- Allows a list of RegExp-like String
patterns: PatternType[]- Array of pattern configurations
- Each pattern can have:
name: string- Name of the pattern (required)patterns?: string[]- Array of RegExp-like strings to match against file contentpattern?: string- [DEPRECATED] Single RegExp-like string to match against file content (usepatternsinstead)filePathGlobs?: string[]- Array of glob patterns to match against file paths
Deprecated options
The pattern field (singular) is still supported but deprecated. Use patterns array instead:
{
"rules": [
{
"id": "@secretlint/secretlint-rule-pattern",
"options": {
"patterns": [
{
"name": "password",
"pattern": "/password\\s*=\\s*(?<password>[\\w\\d!@#$%^&(){}\\[\\]:\";'<>,.?\/~`_+-=|]{1,256})\\b.*/"
}
]
}
}
]
}Changelog
See Releases page.
Running tests
Install devDependencies and Run npm test:
npm testContributing
Pull requests and stars are always welcome.
For bugs and feature requests, please create an issue.
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature - Commit your changes:
git commit -am 'Add some feature' - Push to the branch:
git push origin my-new-feature - Submit a pull request :D
Author
License
MIT © azu
