Skip to content

fix(auth): add scope on refresh and bypass accountId validation on RT exchange#675

Open
icebear0828 wants to merge 2 commits into
devfrom
fix/oauth-refresh-scope-and-account-import
Open

fix(auth): add scope on refresh and bypass accountId validation on RT exchange#675
icebear0828 wants to merge 2 commits into
devfrom
fix/oauth-refresh-scope-and-account-import

Conversation

@icebear0828

Copy link
Copy Markdown
Owner

This PR adds the openid scope to the token refresh payload to ensure Auth0/OpenAI returns the id_token, and bypasses metadata.accountId requirements for RT-exchanged tokens to improve robustness on account imports.

@icebear0828

Copy link
Copy Markdown
Owner Author

Review

总体评价

两个修复方向正确:refresh 加 scope 防止权限缩减,bypass chatgpt_account_id 检查兼容无该 claim 的 JWT。但有一个 High 问题和一个 Medium 问题需要修复后才能 merge。


🔴 High

canAcceptRtExchangeToken 未检查 exp 字段是否存在

isTokenExpired 在 payload 没有 exp 时返回 false(即"未过期")。若 Auth0 返回畸形 JWT(缺 exp),token 会被静默接受写入 pool,但 refresh-scheduler 因拿不到 exp 永远不会调度刷新,账号实际已死却停在 active 状态。

需要显式检查:

const payload = decodeJwtPayload(trimmed);
if (!payload || typeof payload.exp !== "number") {
  return { valid: false, error: "Token missing or invalid exp claim" };
}

🟡 Medium

核心 bug 场景(JWT 无 chatgpt_account_id)没有 regression test

所有 RT exchange 测试用例都用带 accountId 的 token,修复前这些测试同样通过。真正触发原始 bug 的场景从未被覆盖,日后容易被无声回退。

需补:

it("accepts RT-exchanged token with no chatgpt_account_id claim", async () => {
  const noAccountIdJwt = createValidJwt({ accountId: undefined });
  const result = await svc.importMany([{ refreshToken: "some_rt" }]);
  expect(result.added).toBe(1);
  expect(result.failed).toBe(0); // 老代码此处 failed=1
});

🟢 Low

  • canAcceptRtExchangeToken 是纯函数(无 this 状态),可提取为模块级工具函数,减少与 validateManualToken 的重复
  • CHANGELOG.md [Unreleased] 节缺本次修复条目
  • L182/185/189/212 的 as string cast 可通过入口 null guard 消除

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant