ac4af582301a4e8a29245dbba767eba31334ddf9
10
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
c57a5f7f58 |
gateway: a vendor's redirect to another origin is sent no provider key
Go's http.Client follows up to 10 redirects to any host, https to http included, and on a hop to another domain drops only Authorization, Cookie and WWW-Authenticate. So a vendor (or anything answering at its URL) that redirected elsewhere got x-api-key, x-goog-api-key, api-key and a provider's own headers sent there; Authorization too when only the port differed, and all of them in the clear on an https to http hop on the same host. The class is fixed where the requests leave: - provider.KeepsCredentials is a CheckRedirect that follows a redirect only to the request's own origin (scheme, host, port; or http to https on the same host and default ports), at most 10, and gives any other 3xx back as the answer (http.ErrUseLastResponse). - provider.Keyed(c) is a copy of c with c's own CheckRedirect, then KeepsCredentials. Provider.do, the choke point of every p.Do, sends through it, and every http.DefaultClient.Do in internal/provider that carries a credential is Keyed(http.DefaultClient).Do. A copy per call, since netproxy.Install sets the default client's transport at run time. Left alone: Grok's public download, Antigravity's version URL and cline.go's unsigned read. - the gateway's client (s.client, every vendor call), the Codex relay's and the Codex websocket's take KeepsCredentials, and so does chatgpt_api's siwcClient. The native route needs nothing more: the vendor's 3xx comes back to the caller as it came, Location included, and the caller decides. Translated routes don't follow either, rather than following with credentials stripped: it is the rule search_api.go had already (#1580), no vendor magpie speaks to was found redirecting its API to another origin, a stripped request elsewhere would only fail with a confusing 401, and the vendor-URL downloads (video, images) are fetched unsigned through vendorClient, so they are not affected. Tests: TestRedirectKeepsTheKeyAtItsOrigin (307 and 302 elsewhere with Authorization, x-api-key, x-goog-api-key, api-key and a custom header; a same-origin redirect followed with every key; three clients), TestRedirectNeverDowngrades (an https vendor's redirect to http on its own host and port), TestSameOrigin, TestKeyedKeepsTheClientsRule, TestNativeRedirectKeepsTheKey (Anthropic and Gemini providers with an own header) and TestChatRedirectKeepsTheKey. Broken by hand: with Provider.do back on client.Do and s.client without CheckRedirect, the thief got every key header, /away answered 200, the https vendor's /plain was followed (400 from the TLS port spoken to in http), the native route's claudeish and gem answered the thief's {"stolen":true} with Authorization, X-Api-Key and X-Relay-Secret sent there, and the chat route sent Api-Key, Authorization and X-Relay-Secret to it. TestSameOrigin and TestKeyedKeepsTheClientsRule don't depend on the wiring and passed. Run on mote at the pushed head 883690a0b (this commit and the next, on origin/main |
||
|
|
b0174e7615 |
usage: a ChatGPT card says why its allowance can't be read, and a ChatGPT API account says where it shows
hmy on Discord: five ChatGPT accounts each said only "暂时无法获取额度"
(Allowance unavailable). danzi002 on Discord: accounts added through the
API never show usage, ones added as ChatGPT do.
What changed:
- Codex's usage read (codexWindows) now words its failure
(codex_usage_words.go): a Cloudflare challenge names the proxy/VPN
address as the usual cause; any other HTTP answer names its status and
what ChatGPT said; a network error says chatgpt.com couldn't be
reached; a reply magpie can't decode says so. The error still unwraps
to accountStatusError, so expiry and passing logic is unchanged.
- A ChatGPT API account (chatgpt-api) was read as a Codex account: a
saved one said "chatgpt-api accounts can't be used side by side", the
one in use read Codex's own sign-in ("Codex is signed out", or another
account's allowance under its name). OpenAI's API tells no plan usage,
so its row now says so, names chatgpt.com/settings/usage (SeeAt) and
says the same account added as ChatGPT shows it here.
- GUI quotaError translates each of these (en, zh, zh-TW, ja, de), and
"not read yet" (errNotAsked) gets its own words. The generic fallback
now reads "Allowance unavailable — hover for why"; the row's tooltip
has always been the raw error. Comments in app.js were shortened to
stay under TestCoreScriptBudget, which is not raised.
- docs/subsystems/providers-accounts.md describes the words.
Endpoint: the real wham/usage read of the owner's accounts in a sandbox
HOME copy (read-only, ~/.codex untouched) answered 200 and parsed, so
the endpoint itself is not broken; the "error decoding response body"
work is another session's and is not touched here.
Run (on mote; provider and gui again at the pushed head, rebased on
18c69aa46;
|
||
|
|
2251ca1ce9 |
providers: a ChatGPT account's row says when its paid plan ends (danzi002)
danzi002 on Discord (#general, 11-02): 「codex 账号什么是可以加一个 plus 账号到期时间」. The Usage page, the tray panel, the TUI and `magpie quota` have shown "Until …" for the signed-in Codex account since |
||
|
|
e90a635a9a |
provider: a Codex account held in another Codex folder offers Sign in again when its refresh is refused (charliepu)
charliepu on Discord (#general 1566029465107173518, Windows): a ChatGPT account whose sign-in had lapsed had no button to sign in again in the Providers editor. The account was one Codex keeps in another of its folders (CODEX_HOME=C:\Users\...\.codex-db-backup-...). OpenAI refused its refresh, but renewSaved only wrapped the refusal in "run CODEX_HOME=... codex login", and codexSignInRead skipped marking it: a saved account's refused refresh is marked by savedRefreshFailed, which never runs for a folder-held one. So the row never got a lapse, and the GUI's Sign in again (renderAccounts' signedOut, SIGN_IN_GONE) never showed. - logins_on.go: renewSaved wraps such a refusal as codexHeldRefusal and names no command to run. - login_usage.go: codexSignInRead marks a codexHeldRefusal signed out (markRevoked), as it does Codex's own, so the row reads "Sign-in required" with Sign in again, which runs magpie's Codex sign-in for that user (startSignIn), the flow every other revoked Codex account uses. - signin.go: addLogin writes the new tokens back to the Codex folder that holds the account (codexHeldFolder, saveCodexLogin) and clears its gone mark, or the next look would read the dead tokens back over them. ~/.codex/auth.json is not touched. - account.go: codexRefresh's failure says "sign in to this account again", not "run codex login". - chatgpt_api.go (sibling): a ChatGPT API account's kept lapse is listed on its row too, so it gets the same Sign in again. No GUI change: the row already shows Sign in again for a Codex lapse (revoked-signin-account.test.cjs covers it); the backend never set one. Run at origin/main |
||
|
|
85cde4a4de |
provider: Codex and ChatGPT API refreshes lock across magpies
Two magpies can now run at once: a restart to update hands the gateway
over and the old one finishes its requests for up to 15 minutes (next
commit), and a magpie run from a terminal can sit beside the app. Codex's
auth.json and the ChatGPT API sign-in rotate their refresh token on every
refresh. Their refresh locks (codexMu, siwcRefreshing) were a sync.Mutex,
held in one process only. So both magpies could refresh with the same
refresh token, and the second got refresh_token_reused, which signs the
account out.
Both are now a filelock.Mutex beside logins.json (.codex.lock,
.siwc.lock). The sign-in is read again once the lock is held, so a magpie
that waited uses the tokens the other one wrote instead of refreshing
again. Claude's saved tokens, MCP servers' and plugins' were already
locked across processes. Google's, Vertex AI's and Copilot's refresh
tokens don't rotate. Docs: providers-accounts.md, Constraints.
Tests: TestCodexRefreshWaitsForAnotherMagpie and
TestChatGPTAPIRefreshWaitsForAnotherMagpie. Each holds the file lock as
another magpie would, mid-refresh, writes that magpie's rotated tokens,
then lets go. The refresh must return those tokens and send nothing to
the token endpoint.
Broken by hand: with both locks put back to sync.Mutex, both tests are
red ("refreshed 1 times beside another magpie").
Run: see the next commit's body. The provider package ran at the pushed
head with -timeout 45m.
Not tried: a real Codex or ChatGPT API account refreshing in two magpies
at once. The tests use fake token endpoints.
|
||
|
|
40df6dbd38 |
provider: a subscription sign-in canceled while its token is fetched adds no account (#2054)
A sign-in checked canceled/finished only when its callback was claimed. The token exchange after that went on to addLogin / addGoogleLogin / addSideLogin and only then called finish, a no-op after CancelSignIn, so a sign-in the user canceled while its token was in flight still added the account, or replaced an existing account's tokens. Sibling of #1750 (mcpauth's flow.keep, |
||
|
|
2a8a9aecfa |
provider: signing out of ChatGPT and Devin's CLI checks go through the account's own proxy, as its sign-in does (#1663, demystify0137)
What changed: two siblings of
|
||
|
|
437bf023b8 |
codex, chatgpt-api: a conversation with tools reuses its cached prompt, its session sent in session-id/thread-id as Codex 0.162 sends it (#1473 inthink, #933 Scallions)
The ChatGPT backend looks up a conversation's prompt cache by the session headers, not by the body's prompt_cache_key. I probed a real Pro account (gpt-6.1-sol, 13 tools, about 7.6K-token prompt) directly: - key in body only, 6 requests: cached 0 every time - no key and no headers: 0 every time - session-id + thread-id: 0, then 7552 x5 - old session_id/conversation_id: 0, then 7552 - a bare request with no tools: 4096 every time. That is the instructions' shared cache, so #1473's "bare requests hit" pattern fits this. Codex CLI 0.162 (captured with codex exec against a fake server) now sends only session-id and thread-id. It no longer sends the underscored names, which a proxy may drop. Changes: - codexSign: sets session-id and thread-id from the prepared body's key (sessionHeaders). It drops the underscored names. A keyless body keeps the session the client named. - codexHeader: relays session-id/thread-id from Codex clients. - ChatGPT API (SIWC) provider: it sent only Authorization. Now it names the conversation (conversationKey for keyless clients) and sends the same session headers. Scallions' screenshots: chatgpt-api/ got 0% cache where codex/ got 10-99%. This was NOT tried against api.openai.com with a real ChatGPT API sign-in, since none is available here. Left for the reporter to confirm. Run: - Sandbox magpie on a real Codex account, client sending no key: old build cached 0/7296 erratically; new build 0, 0, then 7296 x4. - go test ./internal/provider ./internal/gateway: ok. - Break check: reverting codex_request.go and chatgpt_api.go turns TestCodexSignSessionHeaders, TestCodexSignAndBody and TestChatGPTAPISession red. - gofmt -l: clean. GOOS=linux and GOOS=windows go vet: clean. base_instructions and the identity line are unchanged. |
||
|
|
b0607ef5a6 |
provider: the ChatGPT API subscription lists, beside the models its account catalog lists, those Codex lists for the plan, which the token runs though the catalog leaves them out (#933, knothhe)
knothhe found the ChatGPT API account listing far fewer models than pi, while gpt-6-luna, added by hand, ran. OpenAI's catalog for a Sign in with ChatGPT token (GET api.openai.com/v1/models, its visibility "list" entries, as OpenAI's Models and inference page says to show) leaves out models the token runs: fastagent's run on a real account (fastagent-sh/fastagent#698) found 5 listed, and gpt-6-luna, gpt-6-sol and gpt-6.1-sol running though not in it at all, while pi lists its 44 built-in openai models, 36 of which answer "not supported when using Codex with a ChatGPT account". The token is served as Codex on the plan, so the list now adds to the catalog's models the ones Codex lists for a ChatGPT plan: the list magpie's Codex subscription last fetched, else Codex CLI's models_cache.json. A model the catalog hides stays out, and so do magpie's own in Codex's list. TestChatGPTAPIListsCodexModels is new and fails without the change (models [gpt-5.5 gpt-5.4-mini], no gpt-6-luna). Tested against fake OpenAI servers; not yet with a real ChatGPT API account. go vet, go build (GOOS=linux nogui, GOOS=windows) and go test -tags nogui ./... under a temp HOME pass. |
||
|
|
7a926dd3ce |
provider, gateway, gui: a ChatGPT plan can be signed in with OpenAI's Sign in with ChatGPT, as the ChatGPT API subscription, and asked on api.openai.com's Responses with the agent's own instructions (#933, knothhe)
OpenAI's Sign in with ChatGPT lets an open-source app on the user's machine use their ChatGPT plan through the public API: it registers itself on the way (client_id dynamic_agent_client, an ext_agent_host_id kept for this machine, agent_name_hint magpie), the callback brings the client id OpenAI issued, and the token (scope chatgpt.tokens.use.direct, resource https://api.openai.com/v1) is sent as a Bearer to api.openai.com/v1/responses. The new subscription, chatgpt-api ("ChatGPT API" in the add sheet, beside Codex's ChatGPT), signs in so in magpie (PKCE, a loopback callback on 1455 or any free port, the ID token's issuer, audience, nonce and expiry checked), keeps its accounts as the other in-magpie sign-ins do, refreshes under the issued client id (rotated refresh token, serialised; a refresh token OpenAI won't take again marks the account to sign in again), revokes it on sign-out, and lists the models /v1/models gives the token. Requests go with the agent's own instructions — no Codex prompt, no Codex headers; the Codex path is unchanged — stored nowhere and streamed, without the fields the API refuses for a ChatGPT token (max_output_tokens, temperature, prompt_cache_retention, …) and without hosted tools; a system message is a developer one. OpenAI's subscription_sharing_* refusals are said with what to do (the plan's usage at chatgpt.com/settings/usage, an ineligible account, a capability the token can't use). There is no usage meter: the token has no usage API. Tested against fake OpenAI auth and API servers (TestChatGPTAPISignIn, …Refused, …Refresh, …Body, …Explain; gateway TestChatGPTAPIRequests over chat completions, messages and responses) and the add sheet in Playwright on Chromium and WebKit (chatgpt-api-sub.test.cjs); the gateway and GUI tests fail without the change. Not yet signed in with a real ChatGPT account: the consent page needs the account's owner. go vet, go build (GOOS=linux nogui, GOOS=windows) and go test -tags nogui ./... under a temp HOME pass. |