fix: log auth failures in requireApiKey middleware#162
fix: log auth failures in requireApiKey middleware#1620x-SquidSol wants to merge 1 commit intodcccrypto:mainfrom
Conversation
Both 401 return paths (missing key, invalid key) were completely silent — no logger imported, no logging of any kind. Operators could not detect brute-force attempts or correlate auth failures with other suspicious activity. Adds structured warn-level logging with client IP, request path, and method for both failure modes. Follows the same pattern used by the rate-limit middleware. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 17 minutes and 20 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
auth.ts(missing key and invalid key) had zero logging — nocreateLoggerwas even imported. Sentry only captures 5xx, so auth failures were completely invisible to operators. Could not detect brute-force attempts or correlate failures with suspicious activity.warn-level logging with client IP, request path, and HTTP method for both failure modes.Changes
src/middleware/auth.ts: ImportcreateLogger, addlogger.warn()to both 401 pathsLog output example
Test plan
tsc --noEmitpassesvitest runpasses (186/186 tests)🤖 Generated with Claude Code