fix(cookie): order-independent parsing, reject fake auth, preserve locale - #5
Open
waknow wants to merge 1 commit into
Open
fix(cookie): order-independent parsing, reject fake auth, preserve locale#5waknow wants to merge 1 commit into
waknow wants to merge 1 commit into
Conversation
…cale The old normalizeCookie assumed auth= must be the first segment; a real browser cookie like 'oc_locale=zh; desktop_promo_dismissed=1; auth=...' was corrupted into 'auth=oc_locale=zh; ...', which opencode.ai rejects (302 to login). Fix: locate auth= anywhere, refuse to persist a cookie with no real auth token, and preserve the pasted oc_locale (default en) so both English and Chinese (already merged via PR v587d#2) pages parse. Records decision + rebase notes in COOKIE-FIX.md.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
normalizeCookieinsrc/config.tshad a parsing bug that corrupted validbrowser cookies and made the plugin report a misleading
http302.The old code decided "the first
;-segment is the auth value" whenever thestring did not start with
auth=. A real cookie pasted from a browser oftenlooks like this (especially under a non-English locale):
Because it does not start with
auth=, the old code treatedoc_locale=zhas the auth token and persisted a fake cookie:
auth=oc_locale=zh; ....opencode.ai rejects that, redirects to the login page, and the plugin reports
http302("usage page parsed empty"). This bug is independent of locale — anycookie whose
authsegment is not first is corrupted.Fix
Rework
normalizeCookieto be safe and order-independent:auth=anywhere in the string instead of assuming it is first(a bare opaque token with no
=still getsauth=prefixed).return
undefinedsowriteConfigFilenever writesauth=<locale>.oc_locale(zhstayszh), falling back toenwhen absent or malformed — the parser already understands Chinese pages
(merged via PR fix(api): parse zh-locale usage labels and reset phrases #2), so both English and Chinese consoles parse correctly.
;and,separators (Cookie-header / Set-Cookie style) anddrop unrelated UI segments (e.g.
desktop_promo_dismissed).Changes
src/config.ts— rewritenormalizeCookiesrc/config.test.ts— new regression tests + updated expectationslib/...— rebuilt artifacts so the fix takes effect viamain/typesCOOKIE-FIX.md— rationale, root cause and sync notes.gitignore— ignorelib/tsconfig.tsbuildinfo(build cache)Verification
pnpm test— 53/53 passed (config: 19, api: 23, service: 7, provider: 4)pnpm typecheck— cleanreturns usage data (no redirect).
Notes
Rebased onto the latest
main(including the already-merged zh-locale parsingin PR #2). Single, focused commit; no localization work is added here.