Repository navigation
test(api): pin the constant-time basic credential compare - #79
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.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.
Scope
One PR (1 of 1), module
apionly, test-only. Includes: structural tests that pin the constant-time basic credential compare. Leaves out: any change tosecurity.go. No further changes planned on top.Reason
Nothing failed if
validateCredentialswere reverted to==or to a short-circuiting compare: every case inTestValidateCredentialsMatchesUsernameAndPasswordalso passes with==(epic-security-fixes retrospective, finding 4 / action item 2). A timing test would be flaky, and a counting hook would change production code, so the tests read the source.Changes
security_constant_time_test.go(go/parser+go/ast, standard library only):TestValidateCredentialsComparesBothFieldsWithoutShortCircuit: the body is exactly thecredentialsConfiguredguard,constantTimeEqual(username, Username)andconstantTimeEqual(password, Password)as two unconditional assignments, and one return; no&&/||; the four credential identifiers appear only as compare arguments.TestConstantTimeEqualHashesAndUsesSubtle: the body is twosha256.Sum256calls andreturn subtle.ConstantTimeCompare(...); no==/!=;got/wantused only inside the hashes.Release notes
Review
Quick review lens. Applied: an early return between the two compares (
if usernameMatch != 1 { return false }) and aswitchon the sums before the subtle call both slipped through the first version; both function bodies are now pinned to their exact statement shape. Rejected: test file name differs from the plan (plan-only issue).Verification
Mutation-tested: each of these edits to
security.gomakes the new tests fail, and the original passes:==compare ·&&on the results · early return after the username compare ·if usernameMatch != 1 { return false }between compares ·bytes.Equalon the sums · no hashing ·switch gotSum { case wantSum: }before the subtle call.Local runs:
gofmt -l .— no outputgo vet ./...— okgo test -race ./...— ok for every packagegovulncheck ./...— No vulnerabilities foundTrade-off: the tests are structural, so a harmless refactor of these two functions also fails them; the failure message states the expected shape.
🤖 Generated with Claude Code