
Security News
GitHub Actions Checkout Now Blocks Risky pull_request_target Checkouts
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.
eslint-plugin-sensitive-env
Advanced tools
ESLint plugin to prevent sensitive values from being hardcoded in the codebase
An ESLint plugin designed to prevent hardcoded sensitive values in your code. This plugin ensures that sensitive values, such as API keys, tokens, passwords, and other environment-specific data, are stored in environment variables instead of being hardcoded into the source code.
.env files..env files to define environment variables.To install the plugin, run the following command:
npm install eslint-plugin-sensitive-env --save-dev
or using yarn:
yarn add eslint-plugin-sensitive-env --dev
Add the plugin to your ESLint configuration:
{
"plugins": ["sensitive-env"],
"rules": {
"sensitive-env/no-hardcoded-values": "error"
}
}
The no-hardcoded-values rule provides flexible configuration options:
envFile (optional): The path to the environment file where sensitive values are stored.
[
".env.production",
".env.development",
".env.local",
".env",
".env.local.example",
".env.example"
]
ignore (optional): An array of uppercase strings representing the environment variable names (keys) to ignore.
noSensitiveValues (optional): An array of strings representing specific values to ignore as non-sensitive.
[
"false",
"null",
"true",
"undefined",
"unknown",
"nan",
"infinity",
"-infinity",
"1234567890",
"9876543210"
]
2024-10-20 or 10/20/2024) are not considered sensitive. Numerical representations of dates (e.g., 1729464561272) are allowed.{
"rules": {
"sensitive-env/no-hardcoded-values": [
"error",
{
"envFile": ".env",
"ignore": ["PUBLIC_LOCALHOST"],
"noSensitiveValues": ["myPublicValue"]
}
]
}
}
In this configuration:
.env is used as the environment file.PUBLIC_LOCALHOST.myPublicValue will not be flagged as sensitive, regardless of where it appears.The no-hardcoded-values rule checks for sensitive values that should be stored in environment variables instead of being hardcoded. It works by reading an environment file (e.g., .env) and matching values defined by the specified options.
If the environment file does not exist or cannot be found, the rule will produce a warning with the message:
The environment file <envFile> does not exist.
If a hardcoded sensitive value is found, the following error message will be reported:
Do not hardcode sensitive values. Use environment variables instead.
You can customize the behavior of the plugin by defining which keys and values to ignore.
{
"rules": {
"sensitive-env/no-hardcoded-values": [
"error",
{
"ignore": ["PASSWORD", "SECRET"]
}
]
}
}
In this case, values for PASSWORD and SECRET will be ignored, but other keys will still be checked.
{
"rules": {
"sensitive-env/no-hardcoded-values": [
"error",
{
"noSensitiveValues": ["myPublicValue", "someOtherSafeValue"]
}
]
}
}
Here, myPublicValue and someOtherSafeValue will not be flagged, even if they appear as hardcoded values.
To run the tests for this plugin:
npm test
Contributions, issues, and feature requests are welcome! Feel free to check out the issues page if you have suggestions or encounter problems.
This project is licensed under the MIT License. See the LICENSE file for details.
FAQs
ESLint plugin to prevent sensitive values from being hardcoded in the codebase
The npm package eslint-plugin-sensitive-env receives a total of 0 weekly downloads. As such, eslint-plugin-sensitive-env popularity was classified as not popular.
We found that eslint-plugin-sensitive-env demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.