Environment read deep in code
Environment read deep in code. Reads the environment here (process.env). Config read in many places is hard to test and easy to misspell.
This is how the comment reads inline, under the flagged line.
Why it matters
Scattered process.env reads make behavior depend on hidden globals, fail late on a typo, and can't be checked at startup.
What to do
Read and validate config once at startup, then pass the values in.
Examples
const key = process.env.API_KEY;
const key = config.apiKey;
What it catches
It reads a pattern on each line, aware of strings and comments. Languages: TypeScript and JavaScript, Python. Scope: Shipped code only. These cases are the rule's own tests: the first set must be flagged and the second must not.
Flagged
const k = process.env.KEY;
src/app.py
import os k = os.environ['KEY']
Left alone
src/config.ts
const k = process.env.KEY;
Research
Hard-coded localhost URLs, and environment reads deep in logic. The value cannot change per environment, and tests must patch globals.
- AI code audit taxonomy
- owner's code bar
Turn it off or change it
In a config file for the CLI, or in the API's rules field:
{
"rules": {
"disable": [
"env-read"
],
"severity": {
"env-read": "medium"
}
}
}