Repository navigation
Conversation
|
Merging to
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 |
…y TS `env.kv` already exempts a value that is code rather than a literal (`isSourceExpression`, garrytan#3048), and that function's own `CODE_NAME_CHAIN` accepts a Dart member access such as `request.password`. It never ran, because the exemption was gated to TypeScript/JSX by `TS_SOURCE = /\.(?:[cm]?tsx?|jsx)$/i`, so every other language kept the false positive. Found on a Dart backend where a refactor moved two existing lines into new files. Both forward the request's own password field by name, one as a `requireFields` map entry and one as a named argument, and neither holds a literal. Because the scan is over ADDED lines, a file move re-presents long-standing content as new, so the pre-gate's `secrets` check failed and refused publication on two lines that were byte-identical to the base branch. The pre-push hook reported them too. Demonstrated with one byte-identical line under three extensions: `.ts` clean, `.dart` fires, `.py` fires. `lib/pregate/checks/secrets.ts` writes each hunk to a temp file with `path.basename(part.file)`, so the real extension does reach the validator. Dart qualifies on the same ground TypeScript does, and the ground is a property of the language rather than a judgement about any repo: Dart has no unquoted string literal, so a bare name chain after `:` or `=` cannot be a value, only a variable read. Renamed the constant to `CODE_SOURCE` since it is no longer TS-only. Widening the gate alone WOULD have cost a real detection, so it does not go in alone. `withFlags` forces the `m` flag, so a `password:` line inside a triple-quoted string is matched on its own, and the `before` check reads only the character preceding the span — it cannot see a quote that opened three lines earlier. An embedded config block is exactly where the value after the colon IS a literal, and a `'''` fixture or inline manifest is ordinary Dart. Measured: that line reports on `main` and stopped reporting once `.dart` joined the gate. `insideTripleQuotedString` refuses the exemption there. It scans left to right for whichever delimiter opened rather than counting delimiters, because a `'''` inside a `"""` block is content and a combined parity count would call such text open when it is closed. Its two failure modes both land on the behaviour that already shipped: a diff hunk starting mid-string shows no opener and stays exempt, and a stray `'''` inside a single-line string costs an exemption rather than a report. TS/JSX template literals have the same hole and have had it since garrytan#3048; closing that changes behaviour no language added here is responsible for, so it is left alone. So detection holds. A credential in a Dart file still fires when quoted in either Dart quote style, when assigned with `=` (the separator check takes `:` alone, so an `=` value is never exempt), when the unquoted token begins with a digit, and inside a triple-quoted block. One thing this does NOT claim, because measuring it proved otherwise: an unquoted token is not reliably caught. `CODE_NAME_CHAIN` rejects a token only when it does not start with an identifier character, which a random base62 token does about 84% of the time, so `password: Fk2pQ9…` is exempt while `password: 8Fk2pQ…` fires. That is true of `.ts` on `main` today and is garrytan#3048's existing bargain — an unquoted token after `:` in a code file is a name, and code that pastes a raw secret there does not run. This change neither widens nor narrows it. Eight cases are added to the garrytan#3048 contract test: three that must now be exempt (the two Dart shapes, plus a closed `'''` block, which must not cost the exemption) and five that must still fire (both quote styles, an `=` assignment, a digit-first unquoted token, and a config line inside an open `'''` block). The last uses a letter-first token deliberately, so the chain matches and the guard is the only thing making it report; with `v`, which starts with a digit, it would have passed with or without the guard. Co-Authored-By: Claude Opus 5 <[email protected]>
2933165 to
7c8f4c7
Compare
|
Thank you for this fix. A crew lane is picking it up, together with your other redact PR, to land on current main with Co-authored-by credit to you. |
|
Thanks @hbarney. This landed in #3742 (merged as 64fb6ec, v1.92.8.0). That PR rewrote the fix on current main and combined it with #3419 and #3605. Your idea of extending the source-syntax exemption to Dart is in it, credited with Co-authored-by and in the changelog. The triple-quote guard was rewritten as a string-span pass that also handles comments, raw strings and line continuations. Closing in favor of #3742. |
Why (in your own words)
env.kvalready knows that a value which is code rather than a literal is not aleaked credential — that is
isSourceExpression, added for #3048 — and the regex ituses for the decision,
CODE_NAME_CHAIN, already accepts a Dart member access suchas
request.password. It just never got the chance to run.isSourceExpression'sfirst line gated the whole exemption to TypeScript/JSX:
So every non-TypeScript language kept the false positive the exemption exists to
remove. This widens the gate to
.dart(and renames the constant toCODE_SOURCE,since it is no longer TS-only).
Dart qualifies on the same ground TypeScript does, and the ground is a property of
the language rather than a judgement about any particular repo: Dart has no
unquoted string literal, so a bare name chain after
:or=cannot be a value —it can only be a variable read.
What it cost in real use: on a Dart backend, a refactor moved two pre-existing lines
into new files. Both forward the request's own password field by name — one as a
requireFieldsmap entry, one as a named argument — and neither holds a literal.Because the secrets scan is over ADDED lines, a file move re-presents long-standing
content as new, so
gstack-pregatefailed itssecretscheck and refusedpublication (
PREGATE_SECRETS→PREGATE_VERIFY: refused, andgstack-ship-receiptwrote nothing) over two lines byte-identical to the basebranch. There was no way around it either: secrets findings cannot be downgraded,
and
.gstack-redact-allowlistis read by the pre-push hook, not by the pre-gate.Live evidence
The experiment. One byte-identical line,
'password': request.password,, scannedunder three file extensions and nothing else changed. Run against this repo's
lib/redact-engine.tson unmodifiedmain(64d8210) and on this branch:The
.tsline and the.dartline are the same bytes, so the only thing thatdiffered before this change was the extension.
lib/pregate/checks/secrets.ts:61writes each diff hunk to a temp file with
path.basename(part.file), so the realextension does reach the validator — which is why the gate was reachable at all.
.pystill fires on purpose; see the follow-up note at the bottom.Downstream effect on the repo that hit this: the pre-gate
secretscheck goesfail→warn, and the pre-push hook drops from 3 MEDIUM findings to 1.This does not weaken detection, and a guard was needed to make that true. The
note below revises what this section first claimed — worth reading, since the first
version of this description overstated the case. A real credential in a Dart file
still fires when quoted in either Dart quote style, when assigned with
=(theseparator check in
isSourceExpressiontakes:alone, so an=value is neverexempt), when an unquoted token begins with a digit, and inside a triple-quoted
string. Eight cases are in the #3048 contract test, five that must fire and three
that must stay exempt:
The guard, and why this change does not go in without it.
withFlagsforces themflag, so apassword:line inside a'''block is matched on its own, and thebeforecheck reads only the character preceding the span — it cannot see a quotethat opened three lines earlier. An embedded config block is exactly where the value
after the colon is a literal, and a
'''fixture or inline manifest is ordinaryDart. Measured: that line reports on
main, and stopped reporting the moment.dartjoined the gate.
insideTripleQuotedStringrefuses the exemption there, scanningleft to right for whichever delimiter opened rather than counting delimiters, since a
'''inside a """ block is content and a parity count would call such text open whenit is closed.
Both of the guard's failure modes land on the behaviour that already shipped: a diff
hunk that starts mid-string shows no opener and the line stays exempt — the miss
survives there, which is the side that keeps #3048 working — and a stray
'''insidea single-line string costs an exemption rather than a report. TS/JSX template
literals have the same hole and have had it since #3048; closing that changes
behaviour no language added here is responsible for, so it is left alone. Say the
word if you would rather it came in too.
Scope
lib/redact-patterns.ts—TS_SOURCE→CODE_SOURCE, widened from/\.(?:[cm]?tsx?|jsx)$/ito/\.(?:[cm]?tsx?|jsx|dart)$/i; the newinsideTripleQuotedStringguard and the reasoning behind it; the comment explainingwhy Dart qualifies, and two comment touch-ups.
test/redact-engine.test.ts— 8 cases added to the existing fix(redact): ignore TypeScript parameter types and dynamic JSX values #3048 contract test(3 that must now be exempt, 5 that must still fire). +82/−4 across 2 files.
both run against this repo's own engine on
mainand on this branch; a vacuity checkthat removes only the guard call and watches the embedded-config case fail (102 pass,
1 fail); plus the four test/typecheck commands above, in a fresh clone. The downstream numbers (
fail→warn, pre-push 3 MEDIUM→ 1) are from @hbarney's own
gstack-pregateand pre-push runs on the Dart backendthat hit this; I am reporting them, not re-measuring them, since that repo is private.
below. No change to
isCallExpression,isSchemaFieldIdentifier, or any otherenv.kvvalidator, and no change to the pre-gate or the pre-push hook themselves.Liveness proof (required for external contributors)
gh api user --jq .login→hbarney.I am Claude Code, an agent, working on @hbarney's machine at their direction, so I am
reporting this rather than claiming it: the
GSTACK PRliveness screenshot is notsomething an agent can honestly produce — the point of the requirement is that a
human typed it into a live surface. @hbarney will attach it to this PR. If it is not
here, treat the requirement as unmet rather than satisfied.
Checklist
GSTACK PRtyped live into a real surface) — to be attached by @hbarney, see aboveisSourceExpression); reproduction is the three-extension probe abovePython is the same hole, and it is #3419, stacked on this
The same probe shows it —
.pyfires on the line.tsdoes not, before and afterthis change. It is not in this diff on purpose: the case for Dart above rests on a
property of Dart's grammar, so Python deserves that argument made for Python rather
than a gate widened on the assumption it carries over.
I have since done that work, as #3419. Worth knowing before you review it: making the
argument properly showed Python gains less than Dart does. Dart's two live shapes
both use
:; Python's keyword argument and plain assignment use=, which theseparator check rejects outright, so those keep firing. That PR says so and pins the
firing half in tests. Merge order is this PR first.
Still open after both, and not mine to decide: TS/JSX template literals keep the
embedded-config hole described above. The guard here covers triple quotes only.
🤖 Generated with Claude Code