fix(security): harden analytics Basic Auth (fail-closed + constant-time)#261
Open
ttonyxx wants to merge 1 commit into
Open
fix(security): harden analytics Basic Auth (fail-closed + constant-time)#261ttonyxx wants to merge 1 commit into
ttonyxx wants to merge 1 commit into
Conversation
## Why this change is needed `AnalyticsBasicAuth` protects admin endpoints that can look up any user by email and manually upgrade/downgrade accounts. Two issues weakened it: 1. **Fail-open when unconfigured.** The check compared the request credentials directly against the env vars. If `ANALYTICS_USERNAME`/`ANALYTICS_PASSWORD` were unset (empty), a request presenting empty Basic Auth credentials would match and be granted access — turning a misconfiguration into an open admin API. 2. **Non-constant-time comparison.** Using `==` on the credentials can leak their length/contents through timing differences. ## What this does - Refuses the request with `503` if either credential env var is unset, so the endpoints fail closed instead of open. - Compares username and password with `crypto/subtle.ConstantTimeCompare`. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
5a50270 to
0bc149f
Compare
2eaff2b to
5ec785f
Compare
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.
Severity: 🟡 Medium — potential open admin API + timing side-channel
AnalyticsBasicAuthguards admin endpoints that can look up any user by email (/analytics/user/:email) and manually upgrade/downgrade accounts.The problems
ANALYTICS_USERNAME/ANALYTICS_PASSWORDare empty/unset, a request with empty Basic Auth credentials matches → the admin API is wide open on a misconfigured deploy.!=) on credentials leaks information via timing.The fix
503if either credential env var is unset.crypto/subtle.ConstantTimeCompare.🤖 Generated with Claude Code