Skip to content

fix(redact): env.kv skips JSX keys joined with ?? / || / && - #3605

Closed
adam-balazs wants to merge 1 commit into
garrytan:mainfrom
adam-balazs:fix/redact-jsx-key-nullish
Closed

adam-balazs wants to merge 1 commit into
garrytan:mainfrom
adam-balazs:fix/redact-jsx-key-nullish

Conversation

@adam-balazs

Copy link
Copy Markdown
Contributor

Summary

env.kv flags a React key such as key={workout.id ?? index} in a .jsx/.tsx file as a secret-named assignment. The pregate secrets check can't be downgraded, so a plain JSX key blocks /ship.

isSourceExpression (#3048) already exempts a JSX brace of names in TS/JSX source, but it split the brace's terms on + only. {turn.requestId + turn.role + index} passed, while {workout.id ?? index} was scored by entropy and failed.

This change splits on ??, || and && as well as +. Nothing else changes:

  • a quoted literal anywhere in the brace still returns false before the split;
  • every term must still match CODE_NAME_CHAIN, so a non-identifier token (an entropic value starting with a digit) is still a finding;
  • the exemption still applies only when the scan's sourcePath is TS/JSX.

Tests

test/redact-engine.test.ts, in the existing #3048 test:

  • Now exempt: key={workout.id ?? index} (.jsx), key={item.uuid || item.slug}, key={row.ready && row.id} (.tsx).
  • Still findings:
    • key={settings.apiKey ?? "<entropic>"} (quoted literal)
    • key={<entropic> || index} (not an identifier)
    • key={workout.id ?? index} in a .env file (no TS/JSX context)

Before the fix, the new exempt cases fail. After it, bun test test/redact*.test.ts gives 475 pass and 0 fail, bun test test/gstack-redact-cli.test.ts gives 17 pass, and bun run typecheck is clean.

Checked on the real line: the released 1.91.313.0 gstack-redact --from-file ClientSummary.jsx --json reports env.kv; this branch reports no findings.

The CHANGELOG entry and version stamp are left to a maintainer, per CONTRIBUTING's outside-PR notes.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DPbzLA2Ad25KxmYZDoUPpF

isSourceExpression (garrytan#3048) exempts a JSX brace of names in a TS/JSX file,
but split its terms on `+` only. A React key such as
`key={workout.id ?? index}` was scored as a secret-named assignment and
failed the pregate secrets check, which cannot be downgraded.

Split on `??`, `||` and `&&` as well. A quoted literal anywhere in the
brace still returns false first, and every term must still be an
identifier chain, so `key={settings.apiKey ?? "<entropic>"}`,
`key={<entropic> || index}` and the same key in a .env file stay
findings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DPbzLA2Ad25KxmYZDoUPpF
@trunk-io

trunk-io Bot commented Oct 29, 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

@capy-ai

capy-ai Bot commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

Thank you for this fix. A crew lane is picking it up, together with the related redact PRs, to land on current main with Co-authored-by credit to you.

@capy-ai

capy-ai Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Thanks @adam-balazs. This landed in #3742 (merged as 64fb6ec, v1.92.8.0). That PR rewrote the fix on current main and combined it with the Dart and Python work from #3418 and #3419. Your JSX ??/||/&& split is in it, credited with Co-authored-by and in the changelog, along with a negative control that still reports a literal fallback. Closing in favor of #3742.

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