Stop redacting optional-chained property accesses - #90
Merged
Conversation
isLikelySecretValue rejects code references so that expressions in source an agent is reading are not mistaken for credentials, but the two rules only matched plain dotted identifier chains. `?.` and `!` fall outside `[\w$]`, so `config.auth?.accessToken` and `process.env.SERVICE_API_KEY!` failed those rules, then passed the entropy heuristics and were replaced with surrogates. Tolerate optional chaining between segments and a trailing TypeScript non-null assertion. Measured across 4,098 tracked files in 10 repositories: 103 detections drop to 89, with none added. All 14 removed are optional-chained property accesses; no credential-shaped value is affected. Not addressed here: bare SCREAMING_SNAKE identifiers and kebab-case names at or above the 20-character threshold still pass. Those need a different rule than identifier-chain matching. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@coderabbitai ignore
isLikelySecretValuerejects code references so that ordinary expressions in source an agent is reading aren't mistaken for credentials. Both rules only matched plain dotted identifier chains, and?.and!fall outside[\w$]— soconfig.auth?.accessTokenandprocess.env.SERVICE_API_KEY!failed the rejection, passed the entropy heuristics, and got replaced with surrogates.Same failure mode as #85: a value the agent needed to see, silently removed from its view.
Fix
Tolerate optional chaining between segments and a trailing TypeScript non-null assertion.
Measurements
Across 4,098 tracked files in 10 repositories:
main, 0.2.3)I listed all 14 removed detections individually rather than trusting the aggregate — every one is an optional-chained property access (
foo?.bar,config.thing?.someValue). No credential-shaped value is affected. That mattered to check, because the same corpus does contain genuine credentials in test fixtures (bcrypt hashes, password literals) that a sloppier rule would have dropped.pnpm check: 51 files, 563 tests, all pass. Four new cases added to the existing code-reference test.Not addressed
Bare
SCREAMING_SNAKEidentifiers and kebab-case names at or above the 20-character threshold still pass the heuristics. Those need a different rule than identifier-chain matching, and I'd rather not widen this one speculatively — over-rejection here means a real secret slips through.This was the measured prerequisite for the bare-key detection work (the
token:/password:gap documented in #89); it removes roughly half the residual noise that made that change unattractive.🤖 Generated with Claude Code