Repository navigation
fix(logs): mask Anthropic keys that contain an underscore - #1783
Open
rudycelekli wants to merge 1 commit into
Open
rudycelekli wants to merge 1 commit into
rudycelekli wants to merge 1 commit into
Conversation
Anthropic key bodies are base64url, so most real keys contain '_'. The anthropic_key pattern only allowed [A-Za-z0-9-], and since '_' is a word character the trailing \b could not end the match there either. A key with an early '_' was not matched at all and was logged in full.
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This branch has not been deployed
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.
Bug
The log sanitizer's
anthropic_keypattern is\b(sk-ant-[A-Za-z0-9\-]{30,})\b. Anthropic key bodies (sk-ant-api03-…,sk-ant-admin01-…) are base64url, so they contain_as well as-. A 90+ character body almost always has at least one_._is a word character, so the match cannot end just before it at the trailing\b. The match can only end at a-. The key is then either:-sits 30+ characters in before the first_; or-, with the rest of the key logged in clear.No other pattern catches it in free text. The legacy
openai_keybranch stops at the-insk-ant, andhigh_entropyneeds a=/:/quote prefix and also excludes_.The security pattern set already allows
_(patterns/tokens.go:sk-ant-(?:api03|admin01)-[a-zA-Z0-9_-]{20,}). The log sanitizer was never updated to match.Trigger
On main this line is written unchanged.
Fix
Add
_to the character class.Test
TestSanitizer_AnthropicKeyWithUnderscorechecks three keys with_at different positions (twoapi03, oneadmin01). Each must be masked assk-ant-api***…/sk-ant-adm***…, and the key body must not appear in the output.Commands run
CGO_ENABLED=0 go test -count=1 ./internal/logs: oksanitizer.goreverted, the new test fails for all three keys (6 assertion failures).gofmt -l internal/logs: no output