Repository navigation
fix(oauth): validate raw paste code#state suffix against expected state - #5090
Conversation
|
⏳ DRAFT
What to do
Review readiness checklist
✅ 4/4 boxes ticked. Automatic draft conversion failed (token cannot change draft status). Please convert this pull request to a draft manually. The required |
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configurationConfiguration used: Repository: lidge-jun/opencodex/.coderabbit.yaml Review profile: ASSERTIVE Plan: Advanced Run ID: 📒 Files selected for processing (4)
✨ 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 |
|
This touches the restricted \src/oauth/\ surface, so the unsponsored_surface gate is expected. The change is intentionally small: a raw \code#state\ paste is now treated as state-bearing and validated against the expected state in both \submitManualLoginCode\ and the callback wait loop, while a raw paste without a state suffix keeps the existing same-session exemption. Requesting maintainer-sponsored review when convenient. |
리뷰 · 우선순위 66 / 80로그인할 때 브라우저가 콜백 주소에 닿지 못하면, 사용자는 인증 코드나 리다이렉트 주소를 직접 붙여넣습니다. 주소 형태는 state를 검사합니다. state는 “이 코드가 이번 로그인에서 나온 것인지” 확인하는 값입니다. 코드만 붙여넣는 경우는 같은 세션이라서 그 검사를 건너뜁니다. 구멍은
메인테이너의 판단이 필요한 지점
너의 추천 이 댓글은 grok-bot이 작성했습니다 |
리뷰 · 우선순위 66 / 80이 PR은 로그인 코드를 손으로 붙여 넣을 때, 로그인을 시작하면 주소에 이번 시도만의 표시( 구멍은 베이스는 src/oauth/index.ts - 새 조건은 tests/oauth/oauth-manual-code.test.ts - 틀린 메인테이너의 판단이 필요한 지점
너의 추천 코드는 이 방향으로 두면 됩니다. 드래프트를 풀기 전에 이 댓글은 grok-bot이 작성했습니다 |
A raw manual paste carrying a code#state suffix bypassed state validation because both the synchronous submit gate and the callback wait loop exempted every raw input, weakening the CSRF/login-fixation protection the check exists for. Treat a raw input with an explicit state suffix as state-bearing: it must now match the expected state, while a suffix-less raw code keeps relying on the in-session PKCE verifier.
…paste mismatch message
c6f1bac to
43de224
Compare
|
Author note: the hygiene/enforce-target gates fail with unsponsored_surface because this PR touches the OAuth callback surface. It stays in draft until a maintainer adds the maintainer-sponsored label; the review findings above are addressed at head c6f1bac. |
* refactor(oauth): move in-flight login state into its own module src/oauth/index.ts reached 2009 lines after #5090 and is not in the file-size baseline, so it tripped NEW_OVERSIZED at the 2000-line threshold and failed the gate for every branch whose merge ref includes current dev. Raising the cap is not available: updateBaseline only lowers, and tests/ci-workflows/file-size-ratchet.test.ts asserts it. Trimming the comments that #5090 added to explain why a raw paste carrying an explicit state suffix is state-bearing would have fit the budget and is the wrong trade. src/oauth/login-flow-state.ts takes the bookkeeping for a login that has started and not yet settled: the per-provider state, abort and manual paste maps, the slot helpers, the flow-state reconciliation, and submitManualLoginCode. The cut follows a seam rather than a line count. Nothing moved reads or writes a stored credential, and nothing left behind touches an in-flight slot. index.ts re-exports reconcileOAuthFlowState and submitManualLoginCode, so the management routes and the Codex login flow that import them are unchanged. The raw code#state validation from #5090 moves with submitManualLoginCode unchanged, comments included. index.ts ends at 1894 lines. No local suite, focused test, typecheck or build was run. Exact-head hosted CI is the execution evidence. * fix(adapters): keep the bounded image decode inside the file's size cap src/adapters/openai-chat.ts reached 823 lines against a committed cap of 822 after #5208, so the ratchet reports GREW and the gate fails for every branch whose merge ref includes current dev. The overage is one line out of a six-line addition, which does not justify extracting a module. Naming the options object instead of spreading it across three lines expresses the same call with the same arguments and leaves the file at 821, one line under the cap. No comment was removed and no behaviour changed: normalizeOpenAIChatImages receives the same tierBias and abortSignal, and the rejection handler still rethrows on a real abort and otherwise finishes. No local suite, focused test, typecheck or build was run. Exact-head hosted CI is the execution evidence. * test(layout): register the client runtime test in both inventories tests/clients/client-runtime.test.ts arrived with #5144 and was recorded in neither scripts/test-layout/layout.json explicit nor tests/fixtures/test-layout-expected.json, so the layout guards fail for every branch whose merge ref includes current dev. The file already sits in the domain directory its name implies, so the registration is the whole fix: clients in both inventories, matching the other tests/clients entries. No guard was relaxed and no seed regex was widened to make the file resolve implicitly. Reported by the contract-campaign task, which verified the omission by static blob lookup on dev before raising it. No local suite, focused test, typecheck or build was run. Exact-head hosted CI is the execution evidence. --------- Co-authored-by: lidge-jun <[email protected]>
Motivation
The manual login-code fallback treats a syntactically raw paste as state-exempt so the CLI/GUI paste path keeps working for the same PKCE session. But a raw paste can still carry an explicit
code#statesuffix — and today that suffix is silently ignored, so a pasted code bound to a different login attempt''s state is accepted without any state check. A state-bearing paste should be validated against the expected state instead of bypassing it.Description
submitManualLoginCode: a raw paste with an explicit#statesuffix is now treated as state-bearing — a missing slot state still passes, but a mismatched suffix is rejected with the same "state mismatch" error a redirect URL would get.OAuthCallbackFlowwait loop: the same rule is applied to parsed callback input, so a rawcode#WRONGSTATEpaste no longer completes a login it was not issued for.Tests
bun test tests/oauth/oauth-manual-code.test.ts— 18 pass; new regression asserts a rawcode#WRONGpaste is rejected with "state mismatch" while a matchingcode#statepaste completes the login.bun run typecheck— clean.Review readiness checklist
This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:
All CI tests are green on my local testing.
I pushed my PR to the latest dev commit.
I resolved all correct Codex and CodeRabbit findings.
My PR is ready for review.