Skip to content

AAK-SECRET-006: .env file not in .gitignore

Severity
MEDIUM
Category
Secret Exposure (secret-exposure)
Scanner
agent_audit_kit/scanners/secret_exposure.py
Auto-fixable
Yes. agent-audit-kit fix can apply it.
SARIF name
EnvFileNotInGitignore

What it detects

A .env file exists in the project root and the root .gitignore does not ignore it. Env templates meant to be committed (.env.example, .env.sample, .env.template, .env.dist) are not reported.

How to fix

Add .env* to .gitignore.

agent-audit-kit fix can apply this change for you; add --dry-run to preview it.

To confirm the finding is gone, report only this rule:

agent-audit-kit scan . --rules AAK-SECRET-006

Limitations

Looks for .env and .env.* files in the project root only, and reads only the root .gitignore. An env file in a subdirectory, such as services/api/.env.test in a monorepo, is not examined, even when the project has no .gitignore at all. The .gitignore is read up to the last line that ends within its first 1,000,000 bytes, so an env file ignored only by a line past that point is reported. Every pattern is compared with every root env file, with no bound on how many env files there are: a .gitignore of 1,000,000 bytes of one-character * lines holds 500,000 patterns, and each env file then costs about 0.15 s of CPU, so 500 env files took 70 to 80 s (measured on Python 3.12 at a load average of 7). Patterns match case-sensitively, as git does by default on Linux: where core.ignorecase is set, the default on macOS and Windows, a .ENV line also ignores .env, which this rule still reports.

References


All rules. This page is generated from the rule registry when the documentation is built; to change it, change the rule in agent_audit_kit/rules/builtin.py. To give the rule a hand-written write-up, add docs/rules/AAK-SECRET-006.md: the page then shows that text, with the registry reference appended under it.