[log] Add debug logging to nonce cache in server/hmac.go#8059
Merged
Conversation
Add three logHMAC.Printf calls to the previously-unlogged nonceCache methods: - newNonceCache(): log cache creation with maxAgeSecs and nonceTTL - evictExpired(): log eviction events with count of evicted/remaining entries - checkAndSet(): log nonce registration with current cache size These calls use the existing logHMAC logger (server:hmac) already present in the file. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Jun 25, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds targeted debug logging to the nonceCache lifecycle in internal/server/hmac.go to improve diagnosability of HMAC replay-protection behavior (initialization, eviction, and nonce registration), complementing the existing debug logging in hmacMiddleware.
Changes:
- Log nonce-cache creation with configured max age and TTL.
- Track and log eviction events when expired nonces are removed.
- Log cache size when registering a new nonce.
Show a summary per file
| File | Description |
|---|---|
| internal/server/hmac.go | Adds debug logs to nonce-cache init/eviction/registration to aid production debugging of HMAC replay protection. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 1
Comment on lines
76
to
80
| return false | ||
| } | ||
| c.entries[nonce] = now.Add(nonceTTL) | ||
| logHMAC.Printf("Nonce registered: cacheSize=%d", len(c.entries)) | ||
| return true |
Collaborator
|
@copilot address review feedback |
Contributor
Done in the latest commit. |
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
Adds three focused
logHMAC.Printfdebug logging calls to the previously-unloggednonceCachemethods ininternal/server/hmac.go.The existing
hmacMiddlewarefunction already has 9 log calls, but the nonce cache lifecycle methods (newNonceCache,evictExpired,checkAndSet) had no logging at all, making it hard to diagnose HMAC replay-protection issues in production.Changes
Only
internal/server/hmac.gois modified (+7 lines).newNonceCache()Logs cache initialization with the configured age and TTL values.
evictExpired()Logs eviction events with a count of expired entries removed and entries remaining. The
if evicted > 0guard avoids noise on calls where nothing is evicted (the common case).checkAndSet()Logs each new nonce registration with current cache size, making it easy to detect cache growth or unexpected replay attempts.
Validation
go build ./internal/server/...— ✅go test ./internal/server/...— ✅go vet ./internal/server/...— ✅make agent-finished— ✅ all Go tests pass (Rust crates.io network is blocked in sandbox — pre-existing infrastructure constraint)Quality Checklist
logHMAClogger (no new declaration needed)pkg:filenameconvention (server:hmac)Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
index.crates.ioSee Network Configuration for more information.