Skip to content

Secrets check flags keys in JavaScript and TypeScript const, let, var and class fields (GST-3500) - #4697

Closed
garrytan wants to merge 5 commits into
mainfrom
secrets-check-reads-js-declarations
Closed

garrytan wants to merge 5 commits into
mainfrom
secrets-check-reads-js-declarations

Conversation

@garrytan

@garrytan garrytan commented Nov 22, 2026 •

Copy link
Copy Markdown
Owner

The secrets check now catches a key written as const token = "<key>"; (or let, var, export const, a typed declaration, or a class field like private apiKey = "<key>";) in JavaScript and TypeScript files.
Why: before this, a real key in that form passed the check, and JavaScript and TypeScript are the most common languages in projects that use gstack.
Nothing to do, but a test that builds a fake key from pieces (const token = 'ghp_' + '…') now fails the check when that line is edited; build it with [...].join('') instead.

What changed
  • New rule env.kv.js (MEDIUM, blocks like env.kv). It reads a declaration with one to four of declare, public, private, protected, static, readonly, override, accessor, const, let or var (optionally after export), then a secret-named name, an optional ?/! and type, and a quoted or template literal. It also reads after // and /*.
  • It reports only in .js, .jsx, .ts, .tsx, .mjs, .cjs, .mts and .cts files. A scan with no file path is unchanged, because the Rust rule already reads let and const there.
  • It is a separate pattern, so every existing env.kv match is unchanged and no line reports twice. A name with no keyword, including a bare #secret = "<key>" line, is still env.kv's.
  • The value gets env.kv's checks: a credential-shaped name, no placeholder, 3.0 bits of entropy and the test-file fixture-label exemption. A key split across a + chain of quoted pieces reports.
  • These stay clean: key-naming text ('agent_model', 'terminalFontSize'), lowercase paths or ids ('test/skill-e2e-bws.test.ts'), environment-variable names (const API_KEY = "MY_SERVICE_API_KEY"), and a template whose text beside its ${…} slots holds no secret. A type stops at ;, so let session: string; const mode = "BILLING_DASHBOARD"; gives nothing. UUIDs, hex, digit segments and mixed-case random text still report.
  • docs/pregate.md lists what this rule does not read: a fallback after an environment read, a declaration that does not start its line, a value on the next line, .vue and .svelte files, letters-only passphrases, a space inside a ${ } slot, and a + chain whose first piece is a template.
Why

A real key bound by a JavaScript or TypeScript declaration passed the check that runs before every push. The tests were written first and failed on main; the negative controls (types, destructuring, imports, calls, environment reads, placeholders, other file types) passed there and still pass.

Blast radius

Only added lines in JavaScript and TypeScript files are read by the new rule, so nothing that passed before fails unless it is edited. A replay over every tracked file, comparing main 75410da with this branch at a0763dc, lost 0 findings and added 41, all secret-shaped literals in test files (fake sk- keys, UUID tokens, random strings).

Documentation

Status: current. The documentation already matches this change; no edits were needed.

Scope: 6 committed files from 75410da to a0763dc (the secrets check reads JS/TS declarations as env.kv.js): changelog.d/secrets-check-reads-js-declarations.md, docs/pregate.md, lib/redact-patterns.ts and three tests. There were no staged, unstaged or new files. Cross-doc reads covered the redaction sections of CLAUDE.md, docs/CONTRIBUTOR_REFERENCE.md and spec/sections/gate-and-file.md.tmpl.

Documentation health:
  docs/pregate.md                                     Current (new GST-3500 bullet matches the rule, extensions, exemptions and known limits)
  changelog.d/secrets-check-reads-js-declarations.md  Current (accurate fragment; not editable here)
  docs/CONTRIBUTOR_REFERENCE.md                       Current (MEDIUM credential-shape tier agrees with env.kv.js)
  CLAUDE.md                                           Current (redaction guard pointer unchanged)
  spec/sections/gate-and-file.md.tmpl                 Current for this change (says ~30 patterns, now 52: existing debt)
  CHANGELOG.md                                        Skipped (not edited by this audit)
  TODOS.md                                            Skipped (not edited by this audit)

Coverage: env.kv.js has reference coverage (docs/pregate.md secrets section), how-to coverage (allowlisting by finding id in the same doc) and explanation coverage (why each shape is or is not read, with known limits). No critical or common gaps.

Diagram drift: none; no diagrams name the redaction patterns.

Debt: spec/sections/gate-and-file.md.tmpl's "~30 patterns" count predates this branch (51 at base, 52 now). The env.kv.js source comment in lib/redact-patterns.ts lists a bare #secret = "<key>" as matched, while the rule and the docs leave that line to env.kv.

Approvals

Approved: yes (record r-676a35a605b3). The full approval record stays private.
Plan: exempt: bug fix with failing-first tests (R4)
Plan check: exempt bug fix

Agent notes

Thread GSTA-800 for GST-3500, a follow-up to #4675. lib/pregate/index.ts is not touched. End-to-end case: test/pregate-secrets-source-context.test.ts.

Review. Full panel on 454db3e (specialists 0 findings; red-team 1 informational, fixed). Second-model review on 454db3e marked 3 blocking: one fixed in 885bca1 (template static text), two ruled as notes by the owner. A fresh second-model review on 885bca1 marked 5 blocking: #4 (a type crossing ;) and #5 (env-var names) were new false positives, fixed in a0763dc under the owner's second granted fix-check; #1-#3 ruled as notes. The fix-check reader on 885bca1..a0763dc found no blocker and 2 informational notes: an uppercase underscore-joined random value now passes as an env-var name, and let token: string; token = "<key>"; on one line no longer reports (885bca1 caught it only through the cross-statement match the fix removed; main never did).

Ruled note: lib/redact-patterns.ts:1894:outside-voice at 454db3e ruled by GSTA-36 (relayed from GSTA-800:01M81F1M4AKC4PXEQQAX861Z8S) at 2026-11-22T11:26:28.241Z: pre-existing pregate path parsing drops git-quoted paths; filed as GST-3528 (approval a-5023c3c6f937)
Ruled note: lib/redact-patterns.ts:1892:outside-voice at 454db3e ruled by GSTA-36 (relayed from GSTA-800:01M81F1M4AKC4PXEQQAX861Z8S) at 2026-11-22T11:26:28.409Z: value on the next line is the documented added-lines limit; main misses it too (approval a-fa368e659e5f)
Ruled note: lib/redact-patterns.ts:1897:outside-voice at 885bca1 ruled by GSTA-36 (relayed from GSTA-800:01M81FMHS19V5KYRV17TK00SEW) at 2026-11-22T11:26:28.569Z: git-quoted paths skip path-scoped rules on main too; filed as GST-3528 (approval a-538105c826d0)
Ruled note: lib/redact-patterns.ts:1895:outside-voice at 885bca1 ruled by GSTA-36 (relayed from GSTA-800:01M81FMHS19V5KYRV17TK00SEW) at 2026-11-22T11:26:28.706Z: value capture stops at whitespace or escapes, as env.kv does on main (approval a-1e8e4bdf7c14)
Ruled note: lib/redact-patterns.ts:1899:outside-voice at 885bca1 ruled by GSTA-36 (relayed from GSTA-800:01M81FMHS19V5KYRV17TK00SEW) at 2026-11-22T11:26:28.841Z: + chain finding spans the first operand, as env.kv does on main (approval a-fa33c5c6d9c5)

Ship notes. The p2v and p3v native adversarial rows were logged after the bound outside-voice rows, so gstack-ship-receipt stop returned STOP_UNBOUND and neither fix-check grant could bind a stop record; the grants are relayed from GSTA-800 messages 01M81F1M4AKC4PXEQQAX861Z8S and 01M81FMHS19V5KYRV17TK00SEW. The env.kv.js source comment still lists a bare #secret as matched; the docs and tests are correct.

{
  "schema_version": 1,
  "pr": 4697,
  "head": "a0763dc3752f3e01919eb6916681751ac212ac89",
  "version": "1.102.2.0",
  "base": "main",
  "gate": {
    "test": {
      "pass": 1750,
      "fail": 0,
      "skip": 0
    }
  },
  "ci_carried": [
    {
      "lane": "test",
      "run": 45017503395,
      "attempt": 1,
      "tree": "4ef68a536bbe2e3ea63219df17677506b389a774"
    }
  ],
  "session_kind": "unattended",
  "run": "ship-4697",
  "head_tree": "4ef68a536bbe2e3ea63219df17677506b389a774",
  "product_patch_id": "23059e5d38213b00341f7bbfdb3051d198d6eac7",
  "gstack_version": "1.102.2.0",
  "review_depth": {
    "depth": "full",
    "class": "gate",
    "runtime_lines": 75,
    "rules": "618ea1985b54beb1",
    "base": "f59520e7595cdac501e71b12b800d44c1669834c",
    "registry": "f59520e7595cdac501e71b12b800d44c1669834c",
    "gate_scan": {
      "tagged": 0,
      "head": "a0763dc3752f3e01919eb6916681751ac212ac89"
    },
    "reasons": [
      "gate-class",
      "risk:secret",
      "risk:security",
      "runtime=75"
    ],
    "risk": [
      "secret",
      "security"
    ],
    "mode": "panel"
  },
  "pregate": "requires-remote cleared @4ef68a536bbe (8 checks, current for a0763dc3752f)",
  "requires_remote": [
    "free-tests.yml/cso-macos-launcher: https://github.com/garrytan/gstack/actions/runs/45017080209/attempts/1",
    "free-tests.yml/macos-named-regressions: https://github.com/garrytan/gstack/actions/runs/45017080209/attempts/1",
    "free-tests.yml/cso-windows-launcher: https://github.com/garrytan/gstack/actions/runs/45017080209/attempts/1",
    "windows-smoke.yml/windows-smoke: https://github.com/garrytan/gstack/actions/runs/45017080199/attempts/1",
    "pregate.json/remote_gate: remote-gate tree=4ef68a536bbe tests=38876 skipped=92 runs=45017503395/1 profiles=ci-reuse/free-tests heads=a0763dc3752f verified=2026-11-22T11:34:06.320Z"
  ],
  "issues": {
    "fixes": [],
    "refs": [],
    "flakes": []
  },
  "docs": {
    "status": "current",
    "scope": "docs/, README.md, CONTRIBUTING.md against 75410da..a0763dc"
  },
  "review_loop": {
    "passes": 1,
    "blocking_found": 8,
    "deferred": 0,
    "noted": 12,
    "fixed": 4,
    "scope": "frozen",
    "fix_checks": 3,
    "rounds": 1,
    "ledgers_read": 4,
    "unbound": 4,
    "dispatches": {
      "specialist": 1,
      "red-team": 1
    }
  },
  "ruled_notes": [
    {
      "finding": "lib/redact-patterns.ts:1894:outside-voice",
      "head": "454db3ed21d88d98b501f8aea7e1c5c300e4789d",
      "by": "GSTA-36",
      "reason": "pre-existing pregate path parsing drops git-quoted paths; filed as GST-3528",
      "at": "2026-11-22T11:26:28.241Z",
      "approval": "a-5023c3c6f937",
      "relayed": "GSTA-800:01M81F1M4AKC4PXEQQAX861Z8S"
    },
    {
      "finding": "lib/redact-patterns.ts:1892:outside-voice",
      "head": "454db3ed21d88d98b501f8aea7e1c5c300e4789d",
      "by": "GSTA-36",
      "reason": "value on the next line is the documented added-lines limit; main misses it too",
      "at": "2026-11-22T11:26:28.409Z",
      "approval": "a-fa368e659e5f",
      "relayed": "GSTA-800:01M81F1M4AKC4PXEQQAX861Z8S"
    },
    {
      "finding": "lib/redact-patterns.ts:1897:outside-voice",
      "head": "885bca1bd5e8380eb65925936963f79cea6f207a",
      "by": "GSTA-36",
      "reason": "git-quoted paths skip path-scoped rules on main too; filed as GST-3528",
      "at": "2026-11-22T11:26:28.569Z",
      "approval": "a-538105c826d0",
      "relayed": "GSTA-800:01M81FMHS19V5KYRV17TK00SEW"
    },
    {
      "finding": "lib/redact-patterns.ts:1895:outside-voice",
      "head": "885bca1bd5e8380eb65925936963f79cea6f207a",
      "by": "GSTA-36",
      "reason": "value capture stops at whitespace or escapes, as env.kv does on main",
      "at": "2026-11-22T11:26:28.706Z",
      "approval": "a-1e8e4bdf7c14",
      "relayed": "GSTA-800:01M81FMHS19V5KYRV17TK00SEW"
    },
    {
      "finding": "lib/redact-patterns.ts:1899:outside-voice",
      "head": "885bca1bd5e8380eb65925936963f79cea6f207a",
      "by": "GSTA-36",
      "reason": "+ chain finding spans the first operand, as env.kv does on main",
      "at": "2026-11-22T11:26:28.841Z",
      "approval": "a-fa33c5c6d9c5",
      "relayed": "GSTA-800:01M81FMHS19V5KYRV17TK00SEW"
    }
  ],
  "gate_dispositions": [],
  "review_targeted": {
    "classes": [
      "secret"
    ],
    "rules": "7c9346274d9d1e1c",
    "brief_sha": "7f92a0d0a8319c3c0e076fb3b1a4689c45120b2be2c14dfc7d4cb03aafa9d6a5",
    "product_patch_id": "23059e5d38213b00341f7bbfdb3051d198d6eac7",
    "status": "done",
    "findings": 0,
    "raised_by": "targeted"
  }
}

Fix-check bookkeeping. fix_checks=3 counts one reader run twice plus one log row: I first ran the granted fix-check reader by hand (2 informational notes), then gstack's plan ran it again with the targeted reader on a0763dc (3 informational notes, targeted 0), and a third review-log row on the same unchanged tree records p3v/outside-voice#4 and #5 as fixed by this range and p2v/outside-voice#3 as fixed in 885bca1 (verified by its tests and the p3v second-model pass). No reader found a blocker.

REVIEW_LOOP: passes=1 blocking_found=8 deferred=0 noted=12 fixed=4 scope=frozen open=5 unbound=4 ledgers_read=4 fix_checks=3 dispatches=2

{
  "schema_version": 1,
  "pr": 4697,
  "head": "a0763dc3752f3e01919eb6916681751ac212ac89",
  "version": "1.102.2.0",
  "base": "main",
  "gate": {
    "test": {
      "pass": 1750,
      "fail": 0,
      "skip": 0
    }
  },
  "ci_carried": [
    {
      "lane": "test",
      "run": 45017503395,
      "attempt": 1,
      "tree": "4ef68a536bbe2e3ea63219df17677506b389a774"
    }
  ],
  "session_kind": "unattended",
  "run": "ship-4697",
  "head_tree": "4ef68a536bbe2e3ea63219df17677506b389a774",
  "product_patch_id": "23059e5d38213b00341f7bbfdb3051d198d6eac7",
  "gstack_version": "1.102.2.0",
  "review_depth": {
    "depth": "full",
    "class": "gate",
    "runtime_lines": 75,
    "rules": "618ea1985b54beb1",
    "base": "f59520e7595cdac501e71b12b800d44c1669834c",
    "registry": "f59520e7595cdac501e71b12b800d44c1669834c",
    "gate_scan": {
      "tagged": 0,
      "head": "a0763dc3752f3e01919eb6916681751ac212ac89"
    },
    "reasons": [
      "gate-class",
      "risk:secret",
      "risk:security",
      "runtime=75"
    ],
    "risk": [
      "secret",
      "security"
    ],
    "mode": "panel"
  },
  "pregate": "requires-remote cleared @4ef68a536bbe (8 checks, current for a0763dc3752f)",
  "requires_remote": [
    "free-tests.yml/cso-macos-launcher: https://github.com/garrytan/gstack/actions/runs/45017080209/attempts/1",
    "free-tests.yml/macos-named-regressions: https://github.com/garrytan/gstack/actions/runs/45017080209/attempts/1",
    "free-tests.yml/cso-windows-launcher: https://github.com/garrytan/gstack/actions/runs/45017080209/attempts/1",
    "windows-smoke.yml/windows-smoke: https://github.com/garrytan/gstack/actions/runs/45017080199/attempts/1",
    "pregate.json/remote_gate: remote-gate tree=4ef68a536bbe tests=38876 skipped=92 runs=45017503395/1 profiles=ci-reuse/free-tests heads=a0763dc3752f verified=2026-11-22T11:34:06.320Z"
  ],
  "issues": {
    "fixes": [],
    "refs": [],
    "flakes": []
  },
  "docs": {
    "status": "current",
    "scope": "docs/, README.md, CONTRIBUTING.md against 75410da..a0763dc"
  },
  "review_loop": {
    "passes": 1,
    "blocking_found": 8,
    "deferred": 0,
    "noted": 12,
    "fixed": 4,
    "scope": "frozen",
    "fix_checks": 3,
    "rounds": 1,
    "ledgers_read": 4,
    "unbound": 4,
    "dispatches": {
      "specialist": 1,
      "red-team": 1
    }
  },
  "ruled_notes": [
    {
      "finding": "lib/redact-patterns.ts:1894:outside-voice",
      "head": "454db3ed21d88d98b501f8aea7e1c5c300e4789d",
      "by": "GSTA-36",
      "reason": "pre-existing pregate path parsing drops git-quoted paths; filed as GST-3528",
      "at": "2026-11-22T11:26:28.241Z",
      "approval": "a-5023c3c6f937",
      "relayed": "GSTA-800:01M81F1M4AKC4PXEQQAX861Z8S"
    },
    {
      "finding": "lib/redact-patterns.ts:1892:outside-voice",
      "head": "454db3ed21d88d98b501f8aea7e1c5c300e4789d",
      "by": "GSTA-36",
      "reason": "value on the next line is the documented added-lines limit; main misses it too",
      "at": "2026-11-22T11:26:28.409Z",
      "approval": "a-fa368e659e5f",
      "relayed": "GSTA-800:01M81F1M4AKC4PXEQQAX861Z8S"
    },
    {
      "finding": "lib/redact-patterns.ts:1897:outside-voice",
      "head": "885bca1bd5e8380eb65925936963f79cea6f207a",
      "by": "GSTA-36",
      "reason": "git-quoted paths skip path-scoped rules on main too; filed as GST-3528",
      "at": "2026-11-22T11:26:28.569Z",
      "approval": "a-538105c826d0",
      "relayed": "GSTA-800:01M81FMHS19V5KYRV17TK00SEW"
    },
    {
      "finding": "lib/redact-patterns.ts:1895:outside-voice",
      "head": "885bca1bd5e8380eb65925936963f79cea6f207a",
      "by": "GSTA-36",
      "reason": "value capture stops at whitespace or escapes, as env.kv does on main",
      "at": "2026-11-22T11:26:28.706Z",
      "approval": "a-1e8e4bdf7c14",
      "relayed": "GSTA-800:01M81FMHS19V5KYRV17TK00SEW"
    },
    {
      "finding": "lib/redact-patterns.ts:1899:outside-voice",
      "head": "885bca1bd5e8380eb65925936963f79cea6f207a",
      "by": "GSTA-36",
      "reason": "+ chain finding spans the first operand, as env.kv does on main",
      "at": "2026-11-22T11:26:28.841Z",
      "approval": "a-fa33c5c6d9c5",
      "relayed": "GSTA-800:01M81FMHS19V5KYRV17TK00SEW"
    }
  ],
  "gate_dispositions": [],
  "review_targeted": {
    "classes": [
      "secret"
    ],
    "rules": "7c9346274d9d1e1c",
    "brief_sha": "7f92a0d0a8319c3c0e076fb3b1a4689c45120b2be2c14dfc7d4cb03aafa9d6a5",
    "product_patch_id": "23059e5d38213b00341f7bbfdb3051d198d6eac7",
    "status": "done",
    "findings": 0,
    "raised_by": "targeted"
  }
}

garrytan and others added 2 commits November 22, 2026 10:14
…, let, var and class fields (GST-3500)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…lds (GST-3500)

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

trunk-io Bot commented Nov 22, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

garrytan and others added 3 commits November 22, 2026 10:36
Review-Finding: p1/red-team#1 reader=red-team
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Review-Finding: p2v/outside-voice#3 reader=outside-voice
Review-Finding: p2v/adversarial-native#1 reader=adversarial-native
Review-Finding: p2v/adversarial-native#4 reader=adversarial-native
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…ames as names

A type annotation no longer crosses ";", so "let session: string; const
mode = ..." stops reporting the next declaration's literal, and an
uppercase underscore-joined value ("MY_SERVICE_API_KEY") reads as an
environment-variable name. The docs list three more known limits.

Review-Finding: p3v/outside-voice#4 reader=outside-voice
Review-Finding: p3v/outside-voice#5 reader=outside-voice
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@capy-ai
capy-ai Bot marked this pull request as draft November 22, 2026 11:51
@capy-ai

capy-ai Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Closing this PR. A narrower redesign will replace it: a JavaScript or TypeScript declaration will be flagged only when its value looks like a secret (a known key prefix or a high-entropy string), never just because its name looks like a key. Built this way, the rule flags ordinary environment-variable names used as lookup keys (const API_KEY = "AUTHENTICATION"; process.env[API_KEY];), which main does not. The branch is kept for reference. (GST-3500)

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