-
Notifications
You must be signed in to change notification settings - Fork 0
[WRONG BRANCH] fix: validate manual Codex import identity #228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,7 +43,13 @@ import { | |
| parseAccountPoolStrategy, | ||
| parseAccountPriority, | ||
| } from "./pool-rotation"; | ||
| import { checkAccountIdCollision, getMainChatgptAccountId, readCodexTokens, readCodexTokensResult } from "./auth-collision"; | ||
| import { | ||
| checkAccountIdCollision, | ||
| checkManualImportCollision, | ||
| getMainChatgptAccountId, | ||
| readCodexTokens, | ||
| readCodexTokensResult, | ||
| } from "./auth-collision"; | ||
| export { checkAccountIdCollision, getMainChatgptAccountId } from "./auth-collision"; | ||
| export { clearAccountNeedsReauth, isAccountNeedsReauth, markAccountNeedsReauth } from "./account-runtime-state"; | ||
| import { clearAccountNeedsReauth, isAccountNeedsReauth, markAccountNeedsReauth } from "./account-runtime-state"; | ||
|
|
@@ -67,7 +73,7 @@ export { | |
| setAccountQuotaFromParsed, | ||
| updateAccountQuota, | ||
| } from "./quota"; | ||
| import { extractAccountId, decodeJwtPayload } from "../oauth/chatgpt"; | ||
| import { extractAccountId, decodeJwtPayload, extractEmail } from "../oauth/chatgpt"; | ||
| import { getMainAccountPlan, MAIN_CODEX_ACCOUNT_ID, setMainAccountPlan } from "./main-account"; | ||
| import { captureConfigGeneration, registerStateSweepAfterTick } from "../lib/state-store-sweeper"; | ||
| import { reconcileLiveStateStores } from "../lib/state-store-registrations"; | ||
|
|
@@ -1226,9 +1232,13 @@ export async function handleCodexAuthAPI( | |
| const runtimeConfig = getRuntimeConfig(config); | ||
| const preflightConflict = codexAccountPersistenceConflict(runtimeConfig, body.id, "create"); | ||
| if (preflightConflict) return jsonResponse({ error: preflightConflict }, 400); | ||
| // 1.1: Duplicate check is scoped by personal vs workspace plan bucket. | ||
| // Manual-import identity must come from the token, not request-controlled metadata. | ||
| const derivedAccountId = extractAccountId(undefined, body.accessToken) ?? body.chatgptAccountId; | ||
| const collision = checkAccountIdCollision(derivedAccountId, body.email, body.plan); | ||
| const derivedEmail = extractEmail(undefined, body.accessToken); | ||
| if (!derivedEmail) { | ||
| return jsonResponse({ error: "Access token does not contain an email claim" }, 400); | ||
| } | ||
| const collision = checkManualImportCollision(derivedAccountId); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a warmup-valid access token has an email but no account-id claim recognized by AGENTS.md reference: src/AGENTS.md:L20-L20 Useful? React with 👍 / 👎. |
||
| if (collision.collision) { | ||
| return jsonResponse({ error: collision.reason }, 400); | ||
| } | ||
|
|
@@ -1249,7 +1259,7 @@ export async function handleCodexAuthAPI( | |
| markCodexAccountValidated(body.id, warmup.validatedAt); | ||
| clearAccountNeedsReauth(body.id); | ||
| const accounts = latestConfig.codexAccounts ?? []; | ||
| accounts.push(withCodexAccountLogLabel({ id: body.id, email: body.email, plan: body.plan, isMain: false }, accounts)); | ||
| accounts.push(withCodexAccountLogLabel({ id: body.id, email: derivedEmail, plan: body.plan, isMain: false }, accounts)); | ||
| latestConfig.codexAccounts = accounts; | ||
| saveRuntimeConfig(config, latestConfig); | ||
| reconcileLiveStateStores(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Require a ChatGPT account-ID claim from the access token.
Line 1236 falls back to request-controlled
body.chatgptAccountId. A token with an email claim but no supported account-ID claim can therefore select a different collision identity and bypasscheckManualImportCollision.Reject the import when
extractAccountId(undefined, body.accessToken)returnsundefined. Add a regression test that submits such a token with a suppliedchatgptAccountIdand expects no credential or account row.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents