Skip to content

Stop the secrets check flagging code that reads an environment variable (GST-1894) - #4157

Merged
capy-ai[bot] merged 6 commits into
mainfrom
capy/stop-secrets-check-flagging-env-var-reads
Nov 8, 2026
Merged

capy-ai[bot] merged 6 commits into
mainfrom
capy/stop-secrets-check-flagging-env-var-reads

Conversation

@garrytan

@garrytan garrytan commented Nov 8, 2026 •

Copy link
Copy Markdown
Owner

The preflight secrets check stops failing a branch for code that reads an environment variable, or for a self-describing fixture label in a test file. That keeps the safety check honest, so people trust it when it does fail.

What changed

Env reads that end the expression now pass; a literal fallback still fails (QA captures 001 and 002)

Env reads that end the expression now pass; a literal fallback still fails (QA captures 001 and 002).

Before/after as text: Env reads that end the expression now pass; a literal fallback still fails (QA captures 001 and 002)
--- Before · before.txt · captured output
+++ After · after.txt · captured output
+env.kv findings per line shape (branch c44d6348)
+env member read, ends with ;          0  passes
+getenv call, ends with )              0  passes
+member read with ?? literal fallback  1  still fails
+getenv call with literal default      1  still fails
+fallback wrapped to the next line     1  still fails
-env.kv findings per line shape (main d479c5bf)
-env member read, ends with ;          1  fails pregate
-getenv call, ends with )              1  fails pregate
-member read with ?? literal fallback  1  
-getenv call with literal default      1  
-fallback wrapped to the next line     1  
 

Why

"The preflight secrets check fails on token = opts?.env?.AGENT_API_TOKEN;": yc-software/qm hit this on a test file that only reads an environment variable and names a fixture "personal-secret" (GST-1894). Those lines now pass. A line with a fallback or a second argument gets no new exemption, so a hardcoded secret written as a default still fails.

Blast radius

Only the env.kv rule in lib/redact-patterns.ts changes, and every gstack-redact caller shares it: pregate, PR-body scans and decision-log scans. It's safe because the wider env-read exemption applies only when the line has no ??, ||, or or :, has no second argument, and ends the expression with ;, , or ). Every other line keeps exactly the #2912 exemption main has. We checked this by running the scanner on main and on this branch (QA captures 001 to 004), and CI run 42455675573 passed at this tree.

Summary

Pregate blamed ordinary code for holding a credential. process.env.X already passed, but opts?.env?.X;, ctx.env.X;, import.meta.env.X;, process.env["X"]; and System.getenv("X"); all failed it. Now an env member read by an ALL-CAPS name, or an indexed or call read whose argument is a quoted ALL-CAPS name, passes when the line holds no fallback and ends the expression. In test-named files, a value made only of lowercase words with a credential word among them passes as a fixture label. The branch first added a next-line reader and a shared backtick change, then removed both, so a fallback on the next line or in backticks is simply not exempted. The changelog fragment now says a quoted name that isn't ALL-CAPS in os.environ[...] fails where it used to pass.

Test Coverage

All new code paths have test coverage. The Step 7 audit mapped 10 of 10 changed paths at three stars across test/redact-context-exemptions.test.ts and test/pregate-secrets-source-context.test.ts.
Tests: 1760 → 1760 (+0 new)
Coverage: 100% value-weighted (100% including 0 weakly covered paths)
Test value: 0 tests written, 2 rejected by the authoring gate, 0 existing tests extended, 0 paths weakly covered (weak = ★, gate-failing or unrated).
Tests ran: tests 1641

Pre-Landing Review

Pre-Landing Review: 1 issue — 0 auto-fixed, 1 asked (0 fixed, 1 skipped), 0 deferred, 0 noted. The fix round then corrected the changelog half of that finding (c44d634), and the one scoped fix-check found nothing blocking.
REVIEW_LOOP: passes=1 blocking_found=2 deferred=0 noted=1 fixed=1 scope=frozen unrecorded=2 ledgers_read=4 fix_checks=1 dispatches=4
Ruled note: lib/redact-patterns.ts:722:outside-voice at 830d294 ruled by Captain GStack Minder (GSTA-36) at 2026-11-08T06:38:38.670Z: Note (a): an env.ALLCAPS-shaped quoted value in YAML or .env passes env.kv; no real secret has that shape (approval a-b240fe09f2a4)
Ruled note: lib/redact-patterns.ts:777:adversarial-native at 830d294 ruled by Captain GStack Minder (GSTA-36) at 2026-11-08T06:38:38.874Z: Note (d): a lowercase word label with a credential word in a test-named file is a fixture label, item 2 policy (approval a-17df74499cd2)
Ruled note: lib/redact-patterns.ts:724:red-team at 830d294 ruled by Captain GStack Minder (GSTA-36) at 2026-11-08T06:39:12.011Z: Fail-closed: a quoted env name that is not ALL-CAPS in os.environ[...] or os.getenv(...) now fires env.kv where main passed (approval a-3d16d2eda6a2)
Gate edits: none detected (2 listed, 0 read; patterns: RH-1,RH-3,RH-4,RH-12,RH-13,RH-14,RH-15,RH-16; unlisted idioms: none)
Outside review: completed (openai/gpt-6.1-sol, medium, certified configuration). It reported one finding, the note (a) shape, which the Captain ruled a note.

Notes that ship with this PR, one line each:

  • Note (a), ruled: an x.env.ALLCAPS or x.env[ shaped quoted value in a .env or YAML file passes env.kv.
  • Note (d), ruled: in a test-named file, a lowercase passphrase that contains a credential word is exempt as a fixture label.
  • Fail-closed, lib/redact-patterns.ts:724: a quoted lowercase name in os.environ[...] (os.environ["db_password"]) now fires where main passed it.
  • Fail-closed, lib/redact-patterns.ts:729: wider reads in semicolon-free code (opts?.env?.X with no ;) still fire, as on main.
  • Note (b): bin/gstack-redact-prepush passes no sourcePath for .py and .dart files, so fixture labels there still warn.
  • Note (c): RSpec *_spec.rb and minitest test_*.rb files don't get the fixture-label exemption.
  • lib/redact-patterns.ts:708: an ALL-CAPS-and-digit name is the ruled env-name exemption, so a.env.ZX9QW8ER7TY6UI5OP4; in code passes where main flagged it.
  • process.env.X || <backtick literal> passes, as on main.
  • Changelog wording, changelog.d/stop-secrets-check-flagging-env-var-reads.md:1 (fix-check): only longer, higher-entropy quoted names in os.environ[...] or ENV[...] newly fail. Snake_case call reads that the lookup-key exemption covers, such as os.getenv("db_password"), still pass.

Review notes

Below the blocking floor (advisory, informational, test-gap or wording items); recorded here and not fixed in this PR.

  • INFORMATIONAL lib/redact-patterns.ts:724 Same defect as p1/red-team#1: non-ALL-CAPS quoted names in os.environ[...] now fire env.kv (fail-closed); changelog wording inaccurate.
  • INFORMATIONAL lib/redact-patterns.ts:708 ENV_NAME_ARGUMENT accepts ALL-CAPS-and-digit names, so os.environ["JBSWY3DPEHPK3PXP"] passes (as on main) and a.env.ZX9QW8ER7TY6UI5OP4; in code now passes (main flagged): the Captain-ruled ALL-CAPS-name exemption.
  • INFORMATIONAL lib/redact-patterns.ts:729 Wider reads without a trailing ; , or ) (semicolon-free code) still fire, as on main (fail-closed, documented).
  • INFORMATIONAL changelog.d/stop-secrets-check-flagging-env-var-reads.md:1 The reworded sentence overclaims: only os.environ[...] / ENV[...] reads whose quoted name is 8+ characters with entropy >= 3.0 newly fail; call reads the lookup-key exemption covers still pass.

Exploratory QA

Functional smoke on the scan() API, comparing main d479c5b with this branch, using synthetic rows only. Capture 001 passed: a wider env read that ends the expression passes. Capture 002 passed: a literal fallback still fails on every row, as on main. Capture 003 failed, and replay 004 confirmed it: a quoted lowercase name in os.environ[...] and os.getenv(...) now fires where main passed it. That's the fail-closed finding at lib/redact-patterns.ts:724, which ships as a ruled note (approval a-3d16d2eda6a2). No plan checks ran because no plan is bound.

Design Review

No frontend files changed — design review skipped.

Eval Results

No prompt-related files changed — evals skipped.

Review bot comments

No review bot comments.

Scope Drift

Scope Check: CLEAN

Plan Completion

Plan completion audit: not run (no plan is bound to this branch and no docs/designs/ file matches). Fix: add "Plan: " to the PR body, or run /autoplan.

TODOS

No TODO items completed in this PR.

Documentation

Status: current. No documentation changes were needed.

Scope: base d479c5b..c44d634 on capy/stop-secrets-check-flagging-env-var-reads. The candidate selects 4 committed files: lib/redact-patterns.ts, two test files and changelog.d/stop-secrets-check-flagging-env-var-reads.md. Nothing is staged, unstaged or untracked.

Documentation health:

  • docs/pregate.md: current. The secrets check and the Allowlist section are still accurate, and the env.kv examples are unaffected.
  • docs/troubleshooting.md: current. The push guard (redaction) entries are unaffected.
  • CLAUDE.md, docs/TESTING_INTERNALS.md: current. Their only process.env mentions are unrelated.
  • changelog.d fragment: matches the code. Not edited, because changelog material is owned by the parent.

Coverage debt: The change adds no new public command, flag or config. The scanner's code exemptions (env reads under #2912 and GST-1894, and test-file fixture labels) are documented only in source comments and the changelog. That is reference-only coverage and a minor gap: docs/pregate.md does not list which code shapes the secrets check treats as non-secret.

Diagram drift: none.

Test plan

  • tests (bun run test, carried from CI run 42455675573/1 at tree 20ae77f132fd): 1641 files, exit 0
  • gstack-pregate --allow-repo-commands: CI carry cleared the remote gate, and the four remote checks were cleared from runs 42455675573/1 and 42455675639/1
  • Push guards: typecheck, module-size and conflict-markers passed; credential scan clear
Agent notes

Refs GST-1894

Approvals

Approved: yes (record r-ec1d4c96ce3e). The full approval record stays private: this repository is public or its visibility is unknown.
Plan: exempt: bug fix (R65)
Plan check: exempt bug fix

REVIEW_LOOP: passes=1 blocking_found=2 deferred=0 noted=1 fixed=1 scope=frozen unrecorded=2 ledgers_read=4 fix_checks=1 dispatches=4
Gate edits: none detected (2 listed, 0 read; patterns: RH-1,RH-3,RH-4,RH-12,RH-13,RH-14,RH-15,RH-16; unlisted idioms: none)
Ruled note: lib/redact-patterns.ts:722:outside-voice at 830d294 ruled by Captain GStack Minder (GSTA-36) at 2026-11-08T06:38:38.670Z: Note (a): an env.ALLCAPS-shaped quoted value in YAML or .env passes env.kv; no real secret has that shape (approval a-b240fe09f2a4)
Ruled note: lib/redact-patterns.ts:777:adversarial-native at 830d294 ruled by Captain GStack Minder (GSTA-36) at 2026-11-08T06:38:38.874Z: Note (d): a lowercase word label with a credential word in a test-named file is a fixture label, item 2 policy (approval a-17df74499cd2)
Ruled note: lib/redact-patterns.ts:724:red-team at 830d294 ruled by Captain GStack Minder (GSTA-36) at 2026-11-08T06:39:12.011Z: Fail-closed: a quoted env name that is not ALL-CAPS in os.environ[...] or os.getenv(...) now fires env.kv where main passed (approval a-3d16d2eda6a2)

/ship run ship-4157b (unattended, gstack 1.98.0.0). Evals: none affected. Review plan: class=gate depth=full, panel of 4. One fix round was used, for the changelog wording only, followed by one scoped fix-check.

{
  "schema_version": 1,
  "pr": 4157,
  "head": "c44d6348ef60cfde802e5a99f92daacc8416d476",
  "version": "1.98.0.0",
  "base": "main",
  "gate": {
    "tests": {
      "pass": 1641,
      "fail": 0,
      "skip": 0
    }
  },
  "ci_carried": [
    {
      "lane": "tests",
      "run": 42455675573,
      "attempt": 1,
      "tree": "20ae77f132fda88804ecf27256d8ae840eb3e2e1"
    }
  ],
  "session_kind": "unattended",
  "head_tree": "20ae77f132fda88804ecf27256d8ae840eb3e2e1",
  "product_patch_id": "73128bb9b97e768fb9d5e232a819cf3f3f72c985",
  "gstack_version": "1.98.0.0",
  "review_depth": {
    "depth": "full",
    "class": "gate",
    "runtime_lines": 53,
    "rules": "c6a079fdf812f479",
    "base": "d479c5bf1efed979297dc4498c60aef7b67aa639",
    "registry": "d479c5bf1efed979297dc4498c60aef7b67aa639",
    "gate_scan": {
      "tagged": 0,
      "head": "c44d6348ef60cfde802e5a99f92daacc8416d476"
    },
    "reasons": [
      "gate-class",
      "risk:security",
      "runtime=53"
    ],
    "risk": [
      "security"
    ],
    "mode": "panel"
  },
  "pregate": "requires-remote cleared @20ae77f132fd (8 checks, current for c44d6348ef60)",
  "requires_remote": [
    "free-tests.yml/cso-macos-launcher: https://github.com/garrytan/gstack/actions/runs/42455675573/attempts/1",
    "free-tests.yml/macos-named-regressions: https://github.com/garrytan/gstack/actions/runs/42455675573/attempts/1",
    "free-tests.yml/cso-windows-launcher: https://github.com/garrytan/gstack/actions/runs/42455675573/attempts/1",
    "windows-smoke.yml/windows-smoke: https://github.com/garrytan/gstack/actions/runs/42455675639/attempts/1",
    "pregate.json/remote_gate: remote-gate tree=20ae77f132fd tests=36463 skipped=92 runs=42455675573/1 profiles=ci-reuse/free-tests heads=c44d6348ef60 verified=2026-11-08T06:47:34.588Z"
  ],
  "issues": {
    "fixes": [],
    "refs": [],
    "flakes": []
  },
  "docs": {
    "status": "current",
    "scope": "docs/, README.md, CLAUDE.md, AGENTS.md (142 docs hashed; pregate.md, troubleshooting.md, TESTING_INTERNALS.md, CLAUDE.md read)"
  },
  "review_loop": {
    "passes": 1,
    "blocking_found": 2,
    "deferred": 0,
    "noted": 1,
    "fixed": 1,
    "scope": "frozen",
    "fix_checks": 1,
    "rounds": 2,
    "unrecorded": 2,
    "ledgers_read": 4,
    "dispatches": {
      "specialist": 3,
      "red-team": 1
    }
  },
  "ruled_notes": [
    {
      "finding": "lib/redact-patterns.ts:722:outside-voice",
      "head": "830d29456bc7e4e61d89c76180295d0c028d3850",
      "by": "Captain GStack Minder (GSTA-36)",
      "reason": "Note (a): an env.ALLCAPS-shaped quoted value in YAML or .env passes env.kv; no real secret has that shape",
      "at": "2026-11-08T06:38:38.670Z",
      "approval": "a-b240fe09f2a4"
    },
    {
      "finding": "lib/redact-patterns.ts:777:adversarial-native",
      "head": "830d29456bc7e4e61d89c76180295d0c028d3850",
      "by": "Captain GStack Minder (GSTA-36)",
      "reason": "Note (d): a lowercase word label with a credential word in a test-named file is a fixture label, item 2 policy",
      "at": "2026-11-08T06:38:38.874Z",
      "approval": "a-17df74499cd2"
    },
    {
      "finding": "lib/redact-patterns.ts:724:red-team",
      "head": "830d29456bc7e4e61d89c76180295d0c028d3850",
      "by": "Captain GStack Minder (GSTA-36)",
      "reason": "Fail-closed: a quoted env name that is not ALL-CAPS in os.environ[...] or os.getenv(...) now fires env.kv where main passed",
      "at": "2026-11-08T06:39:12.011Z",
      "approval": "a-3d16d2eda6a2"
    }
  ]
}

Open in Capy

garrytan and others added 2 commits November 8, 2026 05:35
…le (GST-1894)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@trunk-io

trunk-io Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

😎 This pull request was merged.

garrytan and others added 4 commits November 8, 2026 05:53
A production file such as ab-test.ts or load-test.ts matched the test-file pattern, so a weak real password in it stopped being flagged. The pattern now matches only the documented forms: *.test.*, *.spec.*, *_test.* and test_*.py.

Review-Finding: p1/red-team#1 reader=red-team
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
The env-read exemption only looked for a quoted fallback on the same line, so token = opts?.env?.API_TOKEN ?? followed by a backtick literal, or by a literal wrapped onto the next line, passed the secrets check. Backtick literals now count, and the next line is read when the expression continues there. The changelog now says plainly that an ALL-CAPS literal used as the variable name still passes.

Review-Finding: voices/outside-voice#1 reader=outside-voice
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…ng the next line

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…rets check

Review-Finding: p1/red-team#1 reader=red-team
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@capy-ai
capy-ai Bot merged commit 9100930 into main Nov 8, 2026
50 checks passed
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