Repository navigation
Saturate HmacAuth token expiry and test the authenticator - #764
Open
hiroki-abe-58 wants to merge 1 commit into
Open
hiroki-abe-58 wants to merge 1 commit into
hiroki-abe-58 wants to merge 1 commit into
Conversation
`HmacAuth::issue` computed the expiry as `now() + ttl_secs`. A TTL above `u64::MAX - now()` overflowed: a panic with overflow checks, otherwise an expiry in the past, so the token was refused. The expiry now saturates at `u64::MAX`. Add the first tests for `HmacAuth`: issued tokens verify and authenticate; another secret, a tampered payload, a past expiry and a truncated token are refused with their messages; another scheme is refused unless configured; and the anonymous fallback applies to a missing header only, never to a bad one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
HmacAuth::issuecomputes the expiry asnow() + ttl_secs. A TTL greater thanu64::MAX - now(), such asu64::MAX, overflows:cargo test),issuepanics with "attempt to add with overflow".verifyrefuses the token it just issued as "token expired".This PR makes the expiry saturate at
u64::MAX. Refusing instead would mean either a panic or an API change, becauseissuereturns aString. And any TTL that overflows already exceeds about 5.8×10¹¹ years, so saturating gives the same token as the exact sum would. The TTL is chosen by the server, not read from a request.h5i-app-httphad no tests forHmacAuth, so this PR also adds a few. They use a minimal test kernel whose principal is(tenant, user)and whose other types are all().Authorization: Bearer ….issue(…, u64::MAX)givesexp == u64::MAXand verifies. On main this test fails in both build modes: the overflow panic with overflow checks, and theexpassertion without them.bad signature;token expired;malformed token.with_scheme;or_anonymousapplies only when the header is missing, never when it is present but invalid.Nothing else changes: the token format, the parsing in
h5i-app-token(whose proofs cover everyu64expiry), andverify.Testing
cargo test --locked -p h5i-app-http: 4 passed.now() + ttl_secsrestored,ttl_saturatesfails.cargo clippy --locked -p h5i-app-http --all-targets -- -D warnings: clean.h5i-app-httpchanged. The workspace-wide build, test and clippy were not run locally.Written with AI assistance (Claude Code, Claude Opus 5.5) and checked in a separate AI-assisted review session. No human reviewed it before submission.
🤖 Generated with Claude Code