Repository navigation
fix(redact): find a key right after a JSON escape - #87
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Built-in redaction rules missed a key that sits at the start of a line.
The scan runs on the request body as it is sent, which is JSON: a newline in the text is the two characters
\n, a tab is\t, and some clients write non-ASCII as\uXXXX(Python'sjson.dumpsdoes by default, so密钥:sk-…arrives as密钥:sk-…). Tokens were split on characters, so the letter of the escape stuck to what followed: a key after a newline becamensk-ant-…and no prefix matched. The same held for JWTs and, when they are on, internal addresses. A key alone on a line is the ordinary shape of a credentials file pasted into a prompt or read by a tool, so this was a real gap in observe and enforce alike.for_each_tokennow treats a whole escape sequence (\plus the next character, and four hex digits after\u) as a separator. Replacement ranges still start after the escape, so the body stays valid JSON.Found while demoing the security page: a request with a key after a full-width colon was not recorded. The sample tester in the control API runs the same scan, so it agrees with the gateway again.
Tests
\n,\tand\uXXXX, a JWT after\n, and a key after an escaped backslash are all found.cargo test -p tw-redact(60 passed),clippy -D warnings,fmt.🤖 Generated with Claude Code