Harden HMAC authentication against timing and validation bypasses#98
Merged
Harden HMAC authentication against timing and validation bypasses#98
Conversation
…ypass attacks Security fixes: - FixedTimeEquals: eliminate timing side-channel on length mismatch by avoiding early return; XOR lengths into accumulator (NETSTANDARD) or perform a dummy comparison to burn constant time (.NET 8+). - IpAddressWhitelist: reject negative and out-of-range CIDR prefix lengths that previously caused IsIpInNetwork to match all IPs. - GenerateContentHash: stop trusting Content-Length header; always read the body stream to prevent TOCTOU gap between auth and application layers. - Enforce that x-timestamp and x-content-sha256 are present in SignedHeaders, ensuring replay-protection and body-integrity are cryptographically bound. Includes comprehensive security-focused unit tests. https://claude.ai/code/session_0188rXmpYc7jnR1xnXV2BVBQ
…aders Update README.md and Implementation.md to reflect that the server now enforces the presence of x-timestamp and x-content-sha256 in SignedHeaders. This ensures replay protection and body integrity are always cryptographically bound to the HMAC signature. https://claude.ai/code/session_0188rXmpYc7jnR1xnXV2BVBQ
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.
Summary
This PR strengthens the HMAC authentication implementation with critical security hardening across three areas: timing side-channel resistance, CIDR validation bounds checking, and mandatory signed header enforcement.
Key Changes
1. Timing Side-Channel Protection in
FixedTimeEquals2. CIDR Prefix Length Validation in
IpAddressWhitelistfalsefor out-of-range values3. Mandatory Signed Header Enforcement in
HmacAuthenticationHandlerx-timestamp,x-content-sha256) from SignedHeaders, weakening securityValidateRequiredSignedHeaders()method enforces both headers are always includedMissingRequiredSignedHeadersfailure if validation fails4. Content-Length Bypass Prevention
Content-Length: 0header to skip body hashingStream.Null(no body stream at all)Content-Length: 0with actual body content, causing hash mismatchImplementation Details
SecurityTests.cs) covering:https://claude.ai/code/session_0188rXmpYc7jnR1xnXV2BVBQ