Skip to content

fix: treat ww.Status()==0 as 404 for metric cardinality protection#14

Merged
sethgrid merged 1 commit into
mainfrom
fix/metric-cardinality-status-zero
Apr 9, 2026
Merged

fix: treat ww.Status()==0 as 404 for metric cardinality protection#14
sethgrid merged 1 commit into
mainfrom
fix/metric-cardinality-status-zero

Conversation

@sethgrid
Copy link
Copy Markdown
Owner

@sethgrid sethgrid commented Apr 9, 2026

Summary

  • chi's WrapResponseWriter.Status() returns 0 when WriteHeader is never explicitly called (unmatched routes, scanner traffic hitting arbitrary paths)
  • The existing check only caught explicit http.StatusNotFound, so status-0 responses bypassed redaction and polluted Prometheus label cardinality
  • Fix: treat status == 0 the same as 404 — redact the path and log it separately under path_high_cardinality

Test plan

  • New table-driven test in logger/logger_test.go covers three cases: known path (no redaction), explicit 404 (redacted), status 0 / unmatched route (redacted)
  • go test ./logger/... passes locally

🤖 Generated with Claude Code

chi's WrapResponseWriter returns 0 when WriteHeader is never explicitly
called (unmatched routes). Without this fix, scanner traffic hitting
arbitrary paths bypasses the redaction check and pollutes Prometheus
label cardinality.

Adds table-driven tests covering the known-path, explicit-404, and
status-0 cases.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@sethgrid sethgrid merged commit fc2f384 into main Apr 9, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant