Skip to content

Bundled semgrep rules for secret env fallbacks and secrets behind public prefixes - #2187

Merged
remigiusz-antczak merged 1 commit into
mainfrom
land/secgap
Nov 1, 2026
Merged

remigiusz-antczak merged 1 commit into
mainfrom
land/secgap

Conversation

@remigiusz-antczak

Copy link
Copy Markdown
Collaborator

Perun's bundled semgrep pack gains 3 rules that report a secret env variable silently falling back to a hardcoded value and a secret-looking variable behind a public bundler prefix, in JavaScript and Python.

What changes

  • js.yml: perun.js.secret-env-fallback (||, ??, ||=, ??=, destructuring defaults) and perun.js.public-env-secret (NEXT_PUBLIC_, VITE_ and seven other prefixes).
  • py.yml: perun.py.secret-env-fallback (os.environ.get and os.getenv defaults, setdefault, or).
  • A name counts as secret only by a trailing stem, so ACME_TOKEN_TTL stays clean; empty, sentinel and file-path fallbacks stay clean; test paths and test-runner configs are skipped.
  • New test_semgrep_secret_env.py; test_semgrep_hardcoded_cred.py checks the shared literal regex per rule.

Known limits

  • Optional chaining, a value copied to a variable first and value-based fallbacks are not followed; a destructured public read is not seen.
  • Token and API-key names behind public prefixes are not reported: many browser keys are public by design.
  • CI installs no semgrep, so there only the offline rule-text checks run.

Verification

Tests: run-ci-tests.sh --affected 10/10 on an identical tree, semgrep live; held-out fictional fixtures 29/29 reported with 0 false positives; changelog fragments 23/23

🤖 Generated with Claude Code

…lic prefixes

Adds three bundled semgrep rules to the deep-code-review templates. perun.js.secret-env-fallback and perun.py.secret-env-fallback report a secret-named environment variable that falls back to a hardcoded string (||, ??, ||=, ??=, a destructuring default, an os.environ.get or os.getenv default, setdefault, or `or`), because wherever the variable is unset the service silently runs with a known secret. Empty, sentinel and file-path literals stay clean, and test paths plus test-runner configs are skipped. perun.js.public-env-secret reports a secret-named variable behind a public bundler prefix such as NEXT_PUBLIC_ or VITE_, because a bundler inlines such variables into any client code that reads them. The name and literal regexes are shared with hardcoded-credential-compare, whose test now checks them per rule. Each file's header lists the limits: optional chaining, a value copied to a variable first and value-based fallbacks are not followed.

Tests: run-ci-tests.sh --affected 10/10 on an identical tree, semgrep live; held-out fictional fixtures 29/29 reported with 0 false positives; changelog fragments 23/23

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@remigiusz-antczak
remigiusz-antczak merged commit 17c0eec into main Nov 1, 2026
11 checks passed
@remigiusz-antczak
remigiusz-antczak deleted the land/secgap branch November 1, 2026 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant