Skip to content

fix(oauth): validate raw paste code#state suffix against expected state - #5090

Merged
lidge-jun merged 2 commits into
lidge-jun:devfrom
luvs01:fix/oauth-raw-state-suffix
Sep 19, 2026
Merged

lidge-jun merged 2 commits into
lidge-jun:devfrom
luvs01:fix/oauth-raw-state-suffix

Conversation

@luvs01

@luvs01 luvs01 commented Sep 18, 2026 •

Copy link
Copy Markdown
Collaborator

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#state suffix — 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 #state suffix 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.
  • OAuthCallbackFlow wait loop: the same rule is applied to parsed callback input, so a raw code#WRONGSTATE paste no longer completes a login it was not issued for.
  • Raw pastes WITHOUT a state suffix remain exempt, preserving the existing CLI/GUI paste fallback.

Tests

  • bun test tests/oauth/oauth-manual-code.test.ts — 18 pass; new regression asserts a raw code#WRONG paste is rejected with "state mismatch" while a matching code#state paste 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.

@github-actions github-actions Bot added the intake: hygiene-blocked Deterministic PR hygiene checks failed label Sep 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Deterministic hygiene checks failed.

  • unsponsored_surface — This changes an authentication, workflow, release-automation, or dependency surface. MAINTAINERS.md requires security review for these; ask a maintainer to apply maintainer-sponsored once they have reviewed it. Paths: src/oauth/callback-server.ts, src/oauth/index.ts.

@github-actions github-actions Bot added the bug Something isn't working label Sep 18, 2026
@github-actions

github-actions Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

⏳ DRAFT

  • hygiene: unsponsored_surface.

What to do

  • Fix unsponsored_surface — This changes an authentication, workflow, release-automation, or dependency surface. MAINTAINERS.md requires security review for these; ask a maintainer to apply maintainer-sponsored once they have reviewed it. Paths: src/oauth/callback-server.ts, src/oauth/index.ts.

Review readiness checklist

  • ✅ 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.

✅ 4/4 boxes ticked.

Automatic draft conversion failed (token cannot change draft status). Please convert this pull request to a draft manually. The required enforce-target check will keep failing until every issue above is resolved.

@coderabbitai

coderabbitai Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration

Configuration used: Repository: lidge-jun/opencodex/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 1c4e1058-e460-4e00-be1e-d328c26428a5

📥 Commits

Reviewing files that changed from the base of the PR and between d1745ee and 43de224.

📒 Files selected for processing (4)
  • src/oauth/callback-server.ts
  • src/oauth/index.ts
  • tests/oauth/oauth-callback-server.test.ts
  • tests/oauth/oauth-manual-code.test.ts
 ___________________________________________________________________________________________________________________________________________________________________________
< You talkin' to me? You talkin' to me? Then who the hell else are you talking...you talking to me? Well, I'm the only one here. Who do the bugs think they're hiding from? >
 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@luvs01

luvs01 commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator Author

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.

@lidge-jun

Copy link
Copy Markdown
Owner

리뷰 · 우선순위 66 / 80

로그인할 때 브라우저가 콜백 주소에 닿지 못하면, 사용자는 인증 코드나 리다이렉트 주소를 직접 붙여넣습니다. 주소 형태는 state를 검사합니다. state는 “이 코드가 이번 로그인에서 나온 것인지” 확인하는 값입니다. 코드만 붙여넣는 경우는 같은 세션이라서 그 검사를 건너뜁니다.

구멍은 코드#state입니다. 파서는 이걸 “그냥 코드”로 분류합니다. 그래서 다른 로그인 시도의 state가 뒤에 붙어 있어도 검사를 건너뛰었습니다. 이 PR은 뒤에 state가 있으면 그것도 검사합니다. 안 맞으면 “state mismatch”로 거절합니다. #가 없는 코드만은 예전처럼 통과합니다. 고친 곳은 두 군데입니다. submitManualLoginCode와, 콜백을 기다리는 루프입니다. 베이스는 dev입니다. types.ts/config.ts 분리와는 관계없습니다. 아직 draft이고, oauth 파일이라 maintainer-sponsored가 필요합니다.

tests/oauth/oauth-manual-code.test.ts - 틀린 evil-code#WRONG 거절은 추가됐다. 그런데 로그인이 끝나는 성공 검사는, 원래 있던 “전체 리다이렉트 주소”를 pasted-auth-code#state로 바꿔치기했다. 주소로 성공하는 길은 이제 안 본다
src/oauth/callback-server.ts 대기 루프 - 틀린 code#state를 여기서 거절하는 테스트가 없다. 제출 함수가 먼저 거절하면 루프까지 값이 안 간다. 두 조건이 어긋나도 테스트가 못 잡는다
src/oauth/index.ts 에러 문구 - 코드만 붙여넣었는데도 “redirect URL을 붙여넣으라”고 한다. 거절 자체는 맞다

메인테이너의 판단이 필요한 지점

  • maintainer-sponsored를 달고 draft를 풀지
  • 성공 테스트를 주소 형태와 code#state 둘 다 남길지
  • 에러 문구를 코드 붙여넣기에도 맞게 바꿀지

너의 추천
방향은 맞다. # 없는 코드는 그대로 두고, state가 붙은 붙여넣기만 검사하면 된다. 성공 테스트를 바꾸지 말고 하나 더 넣은 뒤, 스폰서 라벨과 CI를 보고 merge. types/config 스플릿 때문에 닫을 PR이 아니다.

이 댓글은 grok-bot이 작성했습니다

@lidge-jun

Copy link
Copy Markdown
Owner

리뷰 · 우선순위 66 / 80

이 PR은 로그인 코드를 손으로 붙여 넣을 때, 코드#표시처럼 뒤에 표시가 붙은 붙여넣기를 그냥 통과시키지 않게 고칩니다.

로그인을 시작하면 주소에 이번 시도만의 표시(state)가 붙습니다. 다른 시도의 결과가 이 로그인에 섞이지 않게 하려고, 주소나 쿼리로 붙여 넣은 값은 그 표시가 맞아야 합니다. 표시가 없으면 거절합니다. 코드만 붙여 넣는 길은 예외입니다. 같은 로그인 창에 넣는 것이고, 토큰으로 바꿀 때 쓰는 확인 값(PKCE)이 이번 시도에 묶여 있기 때문입니다.

구멍은 #이 붙은 코드입니다. 파서는 예전부터 # 뒤를 표시로 읽고, 토큰 교환에는 # 앞만 넣습니다. 그런데 바로 거절하는 submitManualLoginCode와, 입력을 기다리다가 다시 읽는 콜백 루프는 "날것 코드면 표시를 안 본다"고만 되어 있었습니다. 그래서 코드#틀린표시도 통과했습니다. 이번 수정은 # 뒤에 값이 있으면 주소 붙여넣기와 같이 이번 표시와 비교합니다. #이 없는 코드는 예전처럼 통과합니다. 맞는 코드#표시는 로그인이 끝납니다.

베이스는 dev입니다. 지금 tip은 9824aa55bb0e이고 package는 2.60.0입니다. 이 브랜치는 그 tip보다 8커밋 뒤입니다. types.ts와 config.ts는 안 바꿉니다. 같은 구멍을 고치는 다른 열린 PR은 없습니다. 본문 체크는 네 칸이 모두 켜져 있지만 PR은 아직 드래프트입니다. 위생 검사가 src/oauth/callback-server.ts와 src/oauth/index.ts를 인증 쪽으로 보고, maintainer-sponsored 라벨이 없기 때문입니다. 본문에 적힌 테스트 숫자는 이 리뷰에서 다시 실행하지 않았습니다.

src/oauth/index.ts - 새 조건은 #이 있으면 표시를 봅니다. 바로 위 주석은 아직도 날것 코드 전부가 그 검사를 건너뛴다고 적혀 있습니다. 주석만 낡았습니다. 동작은 주석과 다릅니다.

tests/oauth/oauth-manual-code.test.ts - 틀린 코드#WRONG 거절과 맞는 코드#표시 성공은 있습니다. 주소 전체로 로그인이 끝나는 성공 확인은 이 테스트에서 빠지고, 그 자리에 날것 코드#표시가 들어갔습니다. CLI는 submitManualLoginCode를 타지 않고 콜백 루프만 탑니다. 틀린 접미사가 그 루프에서 거절되는지는 이 테스트가 보지 않습니다. 루프의 조건은 함수와 같은 식이라, 지금은 같이 거절합니다.

메인테이너의 판단이 필요한 지점

  • 위생 관문이 이 파일을 인증 표면으로 봅니다. 바뀐 것은 "# 뒤 값이 있으면 이번 로그인 표시와 맞는지 본다"입니다. maintainer-sponsored를 달고 드래프트를 풀지는 메인테이너 몫입니다.
  • 거절 문장은 아직도 "이번 로그인의 리다이렉트 주소를 붙여 넣으세요"입니다. 코드#틀린표시를 넣은 사람에게는 주소가 아니라, 표시 없는 코드나 맞는 표시가 붙은 코드를 말하는 편이 분명합니다. 문장을 바꿀지는 메인테이너 몫입니다.

너의 추천

코드는 이 방향으로 두면 됩니다. # 없는 붙여넣기는 그대로 두고, 표시가 적힌 붙여넣기만 검사해서 기존 CLI/GUI 붙여넣기를 깨지 않습니다. types.ts/config.ts 분할과 무관하니 이 PR을 닫지 마세요. 중복으로 닫을 PR도 없습니다.

드래프트를 풀기 전에 maintainer-sponsored가 필요합니다. 주석 한 줄과, 주소 성공 테스트·CLI 루프 거절 테스트는 있으면 더 안전하고, 없어도 머지를 막을 이유는 아닙니다. tip보다 8커밋 뒤이니 풀기 전에 dev를 한 번 더 받으면 됩니다.

이 댓글은 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.
@lidge-jun
lidge-jun force-pushed the fix/oauth-raw-state-suffix branch from c6f1bac to 43de224 Compare September 19, 2026 12:40
@luvs01

luvs01 commented Sep 19, 2026

Copy link
Copy Markdown
Collaborator Author

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.

@lidge-jun
lidge-jun marked this pull request as ready for review September 19, 2026 21:04
@lidge-jun
lidge-jun merged commit 6b742ec into lidge-jun:dev Sep 19, 2026
5 of 9 checks passed
lidge-jun added a commit that referenced this pull request Sep 19, 2026
* 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]>
@luvs01
luvs01 deleted the fix/oauth-raw-state-suffix branch September 19, 2026 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working intake: hygiene-blocked Deterministic PR hygiene checks failed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants