Skip to content

Port upstream 0.66.0: Qoder regional cookie routing - #644

Closed
Finesssee wants to merge 2 commits into
port/upstream-0.66.0from
port/micro-0.66.0-qoder-regional-cookies
Closed

Finesssee wants to merge 2 commits into
port/upstream-0.66.0from
port/micro-0.66.0-qoder-regional-cookies

Conversation

@Finesssee

Copy link
Copy Markdown
Collaborator

Summary

Qoder runs two independent sites (qoder.com, qoder.com.cn) and a session cookie is only valid on the site that issued it. The old path merged cookies from all four hostnames into one header and sent that same header to both sites. It now works per candidate:

  • Browser sessions are read per site (qoder.com, then qoder.com.cn), one candidate per browser, and each candidate is sent only to its own origin.
  • Requests carry the upstream headers: Accept-Language, Origin, Referer: <origin>/account/usage, X-Requested-With: XMLHttpRequest, Bx-V: 2.5.35.
  • 401/403 moves on to the next candidate. A non-auth failure is remembered and outranks a rejection when nothing succeeds. All rejected gives AuthRequired; no candidate gives NoCookies.
  • Login method is labelled <browser> / <domain> (manual: manual / <domain>).
  • Manual header defaults to international. It routes by a Domain= attribute (not sent as a cookie), or by the URL/Host of a pasted curl command or raw HTTP request. Invalid or conflicting hosts, shell synthesis, config files, and header injection are rejected before any request. A manual candidate is terminal on any result.

Upstream reference

  • v0.66.0 release item: Qoder regional cookie routing (commit b94c5fdc).
  • Resources/Plugins/qoder.js, Sources/CodexBarCore/Providers/Qoder/QoderCookieRouting.swift (site(forManualCookieHeader:)).
  • Tests ported from QoderProviderBehaviorTests.swift (QoderManualCookieRoutingTests, all 3 routing tests, verbatim cases) and the terminal-error semantics from CookieProviderCutoverTests.swift.

Ported / Deferred

Ported: everything above. Routing lives in rust/src/providers/qoder/routing.rs (tests in routing/tests.rs); mod.rs keeps fetch and parse.

Deferred:

  • Optional REQUEST_TIMEOUT setting: Win-CodexBar has no per-provider free-form settings surface, so the 15 s default is kept as a constant. Needs a settings/UI decision.
  • Missing-credential wording: ProviderError::NoCookies is kept (shared provider-state code keys on it) instead of upstream's Chrome-specific message.
  • Cached-session preference ("regional cache before browser import") relies on upstream's macOS cookie broker cache; no equivalent here.
  • No HTTP-level test of the candidate loop (origins are fixed constants); covered by request-builder and outcome-tally unit tests.

Validation

Run from the worktree with Rust 1.98.0 on E-cores, target slot-1:

  • cargo +1.98.0 fmt --all: clean
  • cargo +1.98.0 clippy -p codexbar --all-targets -- -D warnings: pass
  • cargo +1.98.0 test -p codexbar qoder: 18 passed, 0 failed
  • Workspace clippy could not run: the Tauri crate build script in slot-1 reads a stale plugin-permissions path from another slot's cache. No Tauri files are touched.

Affected areas

  • Rust backend / provider (Qoder)
  • Tauri shell, frontend, tray, settings, float bar

UI proof

Not applicable.

@Finesssee

Copy link
Copy Markdown
Collaborator Author

Reviewed by Codex gpt-6-luna (xhigh); verified and validated by Claude

Thermo-nuclear review findings:

  • P1 routing.rs: Windows curl.exe commands were not recognized as cURL and could fall through to plain-cookie routing, sending a China-site cookie to qoder.com. Fixed: curl.exe and \ path separators are recognized; cURL-looking input that cannot be parsed fails closed.
  • P2 routing.rs: cURL/HTTP input was parsed a second time to extract the cookie after routing. Fixed: the route carries the normalized cookie from the same parse.
  • P2 mod.rs: the spec's optional Qoder timeout setting is absent (fixed 15 s). Not fixed: needs a Qoder-specific settings, bridge and localized UI contract; already recorded as deferred in the PR.
  • P3 mod.rs: missing credentials return the shared NoCookies error instead of the spec text. Not fixed: the spec copy assumes Chrome while this app supports explicit browser selection; a correct message needs a localized error contract.

@coderabbitai

coderabbitai Bot commented Sep 30, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 7953281f-664f-4e59-9f7d-813c5a66842b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

@Finesssee

Copy link
Copy Markdown
Collaborator Author

Fixes pushed for the P1 and P2 findings (both in rust/src/providers/qoder/routing.rs, plus a test).

  • Left as documented above: optional timeout setting and the Chrome-specific missing-credentials copy (both need a localized settings/error contract, out of scope for this micro PR).
  • Verification correction: a Windows backslash path (C:\Windows\System32\curl.exe ...) is mangled by POSIX shell tokenization, so the test asserts it fails closed (no site) instead of routing; plain curl.exe routes by its URL.
  • Commands: cargo +1.98.0 fmt --all; clippy --manifest-path rust/Cargo.toml --all-targets -- -D warnings clean; cargo test qoder 19 passed. Rust crate only, no frontend or Tauri change.

@Finesssee

Copy link
Copy Markdown
Collaborator Author

Port review: Qoder regional cookie routing (#644, GAP-39)

Reviewed the branch diff 1827b876 vs port/upstream-0.66.0 against the 0.66.0 manifest spec for row 28d (upstream qoder.js + QoderCookieRouting.swift, 622 lines, commit b94c5fd), plus the PR body and the thermo-review/follow-up comments already on this PR.

What I checked:

  • Origin binding: every candidate (browser or manual) is bound to exactly one QoderSite (qoder.com / qoder.com.cn) and its cookie is only ever sent to that site's usage URL GET {origin}/api/v2/me/usages/big_model_credits. No cross-origin fallback.
  • Request headers (build_request): Cookie (marked sensitive), Accept: application/json, text/plain, */*, Accept-Language: en-US,en;q=0.9, Origin, Referer {origin}/account/usage, X-Requested-With: XMLHttpRequest, Bx-V: 2.5.35, User-Agent — all match the spec, with a request test asserting the exact header set per site.
  • Manual routing: plain headers default international; Domain= attributes route; pasted cURL/HTTP captures route by URL or Host; ambiguous/conflicting input fails closed before any request (invalid/unroutable capture → NoCookies, never a request). Manual is terminal — a rejection or failure is the answer, never a reason to try another site.
  • Browser candidates: iterate QoderSite::ALL (international then China); per-browser headers from browser_cookie_headers_for_domain(site.domain()), each normalized and labeled <browser> / <domain>. NoCookies for a site just skips it; import errors are remembered, not fatal.
  • Failure tally: 401/403 marks the candidate rejected and moves on; other failures are remembered but do not stop the search; final precedence is failure > rejection > import error > NoCookies. This matches the spec's continue-past-rejections semantics with a sane final error.
  • Existing review coverage at this head: the thermo review (Codex gpt-6-luna xhigh + Claude validation) found and fixed P1 (Windows curl.exe commands not recognized → could send a China cookie to qoder.com; now curl.exe and \ paths are recognized, unparsable cURL-looking input fails closed) and P2 (cookie double-parse; route now carries the normalized cookie from one parse), both in routing.rs with tests, pushed to the current head. The normalize_cookie_header control-character rejection test guards header injection.

Result: no new findings. The port matches upstream semantics; the two previously found defects are fixed at the current head and the two remaining deferrals (optional timeout setting, Chrome-specific missing-credentials copy) are correctly documented as needing a localized settings/error contract. Files: mod.rs 720, routing.rs 714, routing/tests.rs 469 — all under the cap. No dependency, locale, bridge or frontend change.

@Finesssee

Copy link
Copy Markdown
Collaborator Author

Shipped in v0.70.0: this PR's head is included in main via #735 (merge commit 9d0a37a). Closing as integrated.

@Finesssee Finesssee closed this Oct 3, 2026
junglesub-bot Bot pushed a commit to junglesub/Win-CodexBar that referenced this pull request Oct 4, 2026
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