test: integration coverage for hostile returnPathname sanitization (CWE-601)#29
test: integration coverage for hostile returnPathname sanitization (CWE-601)#29nicknisi wants to merge 1 commit into
Conversation
Adds an end-to-end `createAuthorization → handleCallback` round-trip against four CWE-601 payload classes (absolute URL, protocol-relative, backslash smuggle, javascript: scheme). Asserts the returned `returnPathname` starts with `/` and stays same-origin when resolved against a trusted base. The existing `utils.spec.ts` suite covers `sanitizeReturnPathname` in isolation; this test covers the wire connecting it to `handleCallback`. Without it, a future refactor that accidentally dropped the sanitizer call in AuthService.ts would still pass all 243 prior tests while reintroducing the vulnerability.
Greptile SummaryThis PR adds four Confidence Score: 5/5Test-only change with no production code modifications; safe to merge. The PR adds four well-structured integration tests that follow established patterns, use correct assertions, and would reliably catch a regression in the CWE-601 sanitization path. No production code is modified. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant T as Test (it.each)
participant AS as AuthService
participant S as makeStorage (in-memory)
participant SU as sanitizeReturnPathname
T->>AS: createAuthorization('res', { returnPathname: hostilePathname })
AS->>S: setCookie(cookieName, sealedState)
AS-->>T: { cookieName }
T->>S: cookies.get(cookieName) → sealedState
T->>AS: handleCallback('req', 'res', { code, state: sealedState })
AS->>S: getCookie(req, cookieName)
AS->>SU: sanitizeReturnPathname(returnPathname)
SU-->>AS: sanitized path (starts with /, same origin)
AS-->>T: { returnPathname }
T->>T: expect(returnPathname.startsWith('/')).toBe(true)
T->>T: expect(new URL(returnPathname, trusted).origin).toBe(trusted)
Reviews (1): Last reviewed commit: "test: integration coverage for hostile r..." | Re-trigger Greptile |
Summary
Closes the integration-level gap identified while reviewing v0.5.1 confidence. The existing coverage for the CWE-601 fix is split across two layers:
src/utils.spec.ts): 21 cases provesanitizeReturnPathnamecorrectly neutralizes hostile input in isolation. ✓src/service/AuthService.spec.ts): exerciseshandleCallbackbut only with legitimate paths (/dashboard,/foo). No test feeds a hostilereturnPathnamethrough the fullcreateAuthorization → handleCallbackround-trip.This means a future refactor that accidentally removed the
sanitizeReturnPathname(...)call atAuthService.ts:387would still pass all prior tests while reintroducing the open-redirect vulnerability. This PR adds a test that would catch that.Changes
it.eachcases underhandleCallback()— one per CWE-601 payload class: absolute URL, protocol-relative, backslash smuggle,javascript:scheme.returnPathnamestarts with/and resolves to the trusted origin (the same invariant the unit tests use).Test plan
pnpm test src/service/AuthService.spec.ts— 40 tests pass (was 36)pnpm test— 247 tests pass (was 243), no regressions