📌 Description
internal/handlers/admin.go BootstrapAdmin() promotes the authenticated user to admin if the X-Admin-Bootstrap-Token header matches cfg.AdminBootstrapToken. The comparison appears to be a plain ==, which is not constant-time and is therefore susceptible to timing analysis, and there is no enforcement that the token is non-empty/sufficiently strong before the endpoint is usable.
💡 Why it matters: A timing-leaky or weak admin-bootstrap secret is a direct privilege-escalation risk — it grants the admin role.
🧩 Requirements and context
- Use
crypto/subtle.ConstantTimeCompare for the token check.
- Reject the bootstrap request (and ideally disable the endpoint) when
AdminBootstrapToken is empty or shorter than a minimum length.
- Optionally restrict bootstrap to
APP_ENV=dev or require a one-time/rotating token.
- Log a single audit entry on successful and failed bootstrap (without the token value).
- Add tests for match, mismatch, empty-configured-token, and short-token cases.
Non-functional requirements
- Must be secure, tested, and documented.
- Should be efficient and easy to review.
🛠️ Suggested execution
1. Fork the repo and create a branch
git checkout -b security/bootstrap-token-hardening
2. Implement changes
- Write/modify the relevant source:
internal/handlers/admin.go, internal/config/config.go
- Write comprehensive tests:
internal/handlers/admin_test.go
- Add documentation: note in README/security docs about the bootstrap flow
- Include GoDoc comments on the comparison helper
- Validate security assumptions: never log the token; constant-time compare
3. Test and commit
go test ./internal/handlers/...
- Cover edge cases: empty token disables endpoint, short token rejected, mismatch returns 403
- Include test output and security notes in the PR description.
Example commit message
security(admin): constant-time bootstrap token compare and strength check
✅ Acceptance criteria
🔒 Security notes
This endpoint grants admin; defend against timing oracles and accidental empty-token misconfiguration that would let any authenticated user self-promote.
📋 Guidelines
- Minimum 95% test coverage
- Clear documentation
- Timeframe: 96 hours
📌 Description
internal/handlers/admin.goBootstrapAdmin()promotes the authenticated user toadminif theX-Admin-Bootstrap-Tokenheader matchescfg.AdminBootstrapToken. The comparison appears to be a plain==, which is not constant-time and is therefore susceptible to timing analysis, and there is no enforcement that the token is non-empty/sufficiently strong before the endpoint is usable.🧩 Requirements and context
crypto/subtle.ConstantTimeComparefor the token check.AdminBootstrapTokenis empty or shorter than a minimum length.APP_ENV=devor require a one-time/rotating token.Non-functional requirements
🛠️ Suggested execution
1. Fork the repo and create a branch
2. Implement changes
internal/handlers/admin.go,internal/config/config.gointernal/handlers/admin_test.go3. Test and commit
go test ./internal/handlers/...Example commit message
✅ Acceptance criteria
subtle.ConstantTimeCompare🔒 Security notes
This endpoint grants admin; defend against timing oracles and accidental empty-token misconfiguration that would let any authenticated user self-promote.
📋 Guidelines