test(security): auth-order sweep β 28 route tests verify 401 before 400 (#4234)#4302
Merged
Conversation
Contributor
There was a problem hiding this comment.
β Approved β strong security regression test.
Reviewed: auth-order-sweep-4234.test.ts (28 test cases)
Checklist:
- β Solves root cause test gap from #4234 β verifies 401 before 400 on ALL protected routes
- β Edge cases: XSS injection, path traversal, invalid body, invalid query β all return 401, never 400
- β 4 public routes verified as NOT requiring auth (health, version, auth/verify)
- β
Uses
app.inject()β no HTTP server overhead - β Temp file cleanup, no leaking resources
- β Zero production code changes β test-only PR
- β Targets develop, conventional commit title
β οΈ Full CI not yet triggered (only GitGuardian) β Gate 3 pending
Approving code quality. Merge blocked until CI runs green.
e67ec76 to
ae61ac6
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.
Summary
Closes #4234
Comprehensive auth-order sweep test suite that verifies ALL
/v1/*routes return 401 (Unauthorized) β not 400/404/other β when no authentication credentials are provided, even when the request contains invalid parameters.What This Catches
The pattern from #4223 (validation before authentication = info leakage) where endpoints would return:
Invalid session ID β must be a UUIDβ leaks that the endpoint exists and validates UUIDsUnknown hook eventβ leaks valid event namesInstead, all routes should return 401 first. Auth middleware runs in
onRequestbefore any handler code executes.Test Coverage
Protected routes (21 tests)
All return 401 without auth:
GET /v1/sessions,GET /sessions,GET /v1/sessions/:idPOST /v1/sessions/:id/approve,POST /v1/sessions/:id/reject(both v1 and legacy)POST /v1/memory,GET /v1/memory/:key,GET /v1/memory,DELETE /v1/memory/:keyGET /v1/memories,POST/GET /v1/sessions/:id/memoriesGET /metrics,GET /v1/metricsGET /v1/hooks/:id/deliveriesGET /v1/events,GET /v1/sessions/:id/eventsGET /v1/openapi.jsonPublic routes (4 tests)
Verified to NOT return 401:
GET /health,GET /v1/health,GET /v1/version,GET /v1/auth/verifyAuth-order attack vectors (3 tests)
POST /v1/sessions/<script>/approveβ 401POST /v1/sessions/../../../etc/passwd/approveβ 401POST /v1/memory {invalid}β 401Findings During Sweep
requireRolecheck (any authenticated user can R/W memory) β may be intentional but flagged for review