Skip to content

fix(csrf): use constant-time comparison and hide internal errors#138

Merged
appleboy merged 2 commits intomainfrom
worktree-authgate-1
Mar 30, 2026
Merged

fix(csrf): use constant-time comparison and hide internal errors#138
appleboy merged 2 commits intomainfrom
worktree-authgate-1

Conversation

@appleboy
Copy link
Copy Markdown
Member

Summary

  • Use crypto/subtle.ConstantTimeCompare for CSRF token validation to match the constant-time comparison pattern used throughout the codebase (metrics_auth.go, registration.go, device.go)
  • Log session save errors server-side and show a generic message to users, preventing internal error detail leakage

Test plan

  • All 14 CSRF middleware tests pass
  • Full test suite passes (excluding pre-existing Redis-dependent tests)
  • Manual: verify CSRF-protected form submissions still work (login, device verify, consent)

🤖 Generated with Claude Code

- Use crypto/subtle.ConstantTimeCompare for CSRF token validation
- Log session save errors server-side instead of exposing to users
- Show generic error message to prevent internal detail leakage
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 30, 2026

Codecov Report

❌ Patch coverage is 71.42857% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/middleware/csrf.go 71.42% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@appleboy appleboy merged commit e2db1d3 into main Mar 30, 2026
17 checks passed
@appleboy appleboy deleted the worktree-authgate-1 branch March 30, 2026 03:47
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