ac4af582301a4e8a29245dbba767eba31334ddf9
8
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 |
||
|
|
6874b892bb |
providers: a StepFun sign-in is read once a request, not once a row
/api/providers asks StepFunSignedIn for each StepFun provider on every poll, and each ask opened stepfun-auth.json under stepfunMu, most often a file that isn't there. In a profile of 200 lists against a copy of the owner's real config (2 StepFun providers) it was 0.28s of 4.07s. StepFunSignedIn now reads the file through filememo, which parses it once until it changes and remembers it missing while a request holds it. A file with a site's session from before #2384 ("ai", "com") still goes through loadStepFun under the lock, which moves it. saveStepFun calls filememo.Forget, so a sign-in saved during a request is seen by the next ask in it. Run (on mote unless named): - go test -count=1 -timeout 45m ./internal/provider ok (115s); -run TestStepFun -count=3 ok; GOOS=linux and windows go vet ./internal/provider ok; gofmt clean (here). - New TestStepFunSignedInReadOnce: 40 asks in one held request parse once, and a save inside it is seen. Broken by hand: each ask reading the file -> "parsed 0 times, want 1"; no Forget in saveStepFun -> "a sign-in saved in the request wasn't seen". - Here, 200 GET /api/providers on the sandbox with the real config copy (offline, proxy :9): StepFunSignedIn 0.28s -> gone from the profile, syscalls 1.54s -> 1.08s; total CPU 4.49s -> 4.53s, within this machine's noise. Not run: the full ./... suite; GUI tests (no page change); a real StepFun sign-in (the save path is unchanged apart from Forget). |
||
|
|
cd10dfbe6f |
provider: an Ark, Tencent or StepFun plan key is weighed by its plan's windows
chen on Discord: the Usage page showed a Volcengine Ark Coding Plan's
5-hour and weekly windows, while the Routing page's row for the same key
said only "one key", with no bar. Routing reads a key's windows through
KeyAllowance, and readsKeyWindows knew only plans a key tells itself
(planQuotaSourceOf: Kimi Code, GLM Coding Plan, MiniMax, Command Code,
Ollama, OpenCode Go) and sub2api keys. The plans whose windows the
account tells, not the key, were left out of routing:
- Volcengine Ark Coding / Agent Plan (account AccessKey, volcengine_usage.go)
- Tencent Cloud Token Plan Enterprise (SecretId/Key, tencent_usage.go)
- StepFun Step Plan (magpie's platform sign-in, stepfun_plan.go)
accountPlanOf names them; readsKeyWindows takes them, and keyWindows
reads them as their Usage card does. The cards' own reads note the
windows for routing at once (noteKeyAllowance), and Ark's card kept on
disk seeds routing after a restart (keyCardTag). Their tags are not
"plan"/"balance", so withKeyReadings adds no second card for them. A
Tencent account with several team plans gives a key no windows: which
plan a key is of isn't told. A plan without its access key, and
pay-as-you-go, are never asked. The Routing row then says "{n} left ·
renews in {d}" with its bar, as an account's does; no GUI change.
Test: TestAccountPlanKeyAllowance (Ark read, from its card, from disk;
pay-as-you-go and no-secret not read; Tencent plan and StepFun read) and
TestStepPlanKeyAllowance. Both red on origin/main
|
||
|
|
cc09c5bd97 |
stepfun: a Step Plan sign-in is the provider's own, not its site's: two accounts on one site show their own windows (#2384)
stepfun-auth.json kept one platform session per site ("ai", "com"), so
every StepFun provider on a site shared it: bringing a sign-in to one
signed in all of them, two accounts showed the same windows, and signing
one out signed out all (fangzhengjin, #2384). Sessions are now kept by
provider id; the site, which platform is asked, is still the provider's
(StepFunSite). StepFunSignedIn, SaveStepFunSession, SaveStepFunPaste,
SignOutStepFun, stepfunNow and stepfunAsk take the id, and
stepPlanQuotas gives one card per signed-in provider, not one per site.
Nobody signs in again for the upgrade: a file still keyed by site is
given, on read, to the StepFun providers on that site (stepfunBySite) and
written back through the temp-and-rename write. One provider: it's
theirs. Several: each gets it, so nobody loses their windows, and the
user brings the other account's sign-in to the ones that are someone
else's. Those copies are one sign-in, so stepfunNow renews every entry
holding the same refresh token together; renewed apart, the platform
could end the token the first renewal replaced and sign the others out.
With no StepFun provider on the site yet (or providers.json unreadable)
the old entry waits as it is. A file that doesn't parse, or that holds an
entry of another shape, is read as no session and nothing but a new
sign-in writes over it, after lastgood.KeepUnparsed has kept it aside.
Every other place keyed by the provider follows: Delete drops its
session (a provider added later under the same id doesn't inherit it),
Rename moves it, and the GUI posts /api/stepfun/{id}/session and
/api/stepfun/{id}/signout, 404 for an id that isn't a StepFun
provider's (a site's name among them). Backup and sync never carried
stepfun-auth.json, so nothing changes there.
Built on fangzhengjin's stepfun-per-provider branch (996cf969e), which
rekeyed the session by id. Not taken from it: it made every existing user
sign in again, left Delete and Rename on the old keys (a renamed provider
lost its sign-in, a removed one's was inherited by a new provider of the
same id), let signout take any id, and its two-provider test checked
only the stored Account, never each provider's windows.
Run at this head (on origin/main
|
||
|
|
58651568b3 |
agent, sessions, provider: a state file that doesn't parse is kept aside, not written over as empty (#2263, ggbdpq)
applied.json, wsl.json and sessions-wsl.json were read as empty when they didn't parse, and the next save wrote that emptiness over them. What magpie had applied to each agent, the WSL distros and the WSL session listing were lost with no copy. stash.json already kept a bad file aside as .bad-<time>. Each of these now does the same through one helper, lastgood.KeepUnparsed, instead of a copy per file: - It does nothing when the file is missing or empty. - When the file doesn't unmarshal into the reader's own type (lastgood.Into[T]), it copies the file aside (KeepBad). - It stops the write when the copy can't be kept. This also fixes the issue's claim about stash.json. Stash judged a file with json.Valid, so `[]`, which a map reader takes as empty, was written over unkept. Its failed copy was only logged, and the write went ahead anyway. Both are fixed (TestUnreadStashArrayKeptAside), and gateway-hidden.json uses the same helper. Siblings found by going through every single-file JSON reader that takes a bad file as empty and then writes it whole: - stepfun-auth - login-returns - quota-history - balance-history - credits-daily - Claude Desktop tiers - plugin updates - usage's computer id - davsync's sync state Each now keeps a bad copy. Caches that are rebuilt from the vendor are left alone; docs/subsystems/providers-accounts.md lists them. Run: - gofmt -l, go vet (darwin -tags nogui, GOOS=linux -tags nogui, GOOS=windows): clean. - go test -tags nogui -p 4 -timeout 40m ./... with the other three commits of this push: see the last one's body. Broken by hand: on the code before this, these fail: - the issue's applied_keep_test.go and wsl_keep_test.go - TestUnreadStashArrayKeptAside - TestUnreadStateKeptAside (10 subtests) - the gateway, usage, davsync and plugin _keep tests TestKeepUnparsed and TestKeepUnparsedFailsWhenItCantBeKept cover the helper. I dropped a test, "not written when it can't be kept", for stash. It passed on the old code too, because a read-only folder also stops the atomic write. Not tried: a real WSL distro. Co-authored-by: ggbdpq <ggbdpq@gmail.com> |
||
|
|
37f2a2851f | gui: a Usage card has a refresh of its own, left of its "Updated" time, that reads that card alone (Hu9956, #840: 在更新时间左侧加一个刷新按钮,鼠标悬停在套餐卡片上时显示,可以单独刷新某个套餐的用量,不用刷新全部) — only the page's Refresh read the allowances again, every card at once. Each card now has a ↻ that opens left of "Updated 3 min ago" (or of a failed reading's reason, or under a balance) as the card is hovered; at rest the line starts where the card's others do. A click POSTs /api/usage/quotas/refresh?provider=&user=: provider.RefreshUsage reads that subscription account, plan key or balance key again (a Claude account by running Claude Code's own /usage, as the page's Refresh does) and puts it in place in the caches, the other cards not asked and kept as they were read; the button turns while it reads. zh, ja, de strings. TestRefreshOneCard (two keys of one relay and another provider: a refresh asks that key alone, the others keep their figures) and the plugin case in TestPluginUsage (one account of three read) fail on the old code; usage-card-refresh.test.cjs (WebKit, en and zh: aligned at rest, left of the time when hovered, a click reads that card alone, turns meanwhile, doesn't scroll; a failed card's own button) fails on the old code. usage-quota-head, usage-checkin, click-scroll, quota-read-at, balance-parts, claude-usage-asked, gui-ja and gui-de pass on WebKit. go vet, builds (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass. | ||
|
|
25194cbc0d |
fix(provider): a Step Plan's credits show when they never reset (#460)
A monthly Step Plan (Pro, plan_family 2) has no 5-hour or weekly window, only credits that run out with the plan. QueryStepPlanRateLimit tells them as subscription_credit_left_rate 0.9019661 with subscription_credit_reset_time "0", and its credit_buckets entry says next_reset_at "0". readStepPlan dropped every window whose reset doesn't parse, so the card showed the plan's name and end date with no window at all, while StepFun's own usage page showed 90% of the credits left. Credits with no reset are now kept when the answer lists credit_buckets: a window with no ResetsAt, as other credit windows already are. The 5-hour and weekly windows are unchanged: 0 left and 0 for the reset is still no window. TestReadStepPlan gets the real answer from a Pro account (it fails on main with []) and a plan whose credits are 0/0 with no bucket (still no window). With a signed-in Pro account, magpie quota stepfun-cn on main shows "Pro · expires Oct 15 plan" with nothing after it; with the change it shows "Credits 10%". go vet and go test -tags nogui ./internal/provider pass. |
||
|
|
9e9c2ce96c | providers: StepFun and StepFun (China) show the Step Plan's 5-hour, weekly and credit windows on the Usage page (StepFun 国外版跟国内版这两个provider都应该支持显示额度) — the platform tells them only to a sign-in on platform.stepfun.ai or .com, never to a key ("api key not permitted for this method"), and its session cookie is HttpOnly with no way back to an app, so the user signs in in their own browser and brings the session over: the provider's editor has a bookmarklet that, on the signed-in platform page, asks the platform to renew the session as the page does and copies it, and a box to paste it into (the Oasis-Token cookie from developer tools is taken too). magpie keeps it in stepfun-auth.json (0600), one per site, renews it before it runs out and once more when it is refused, and asks QueryStepPlanRateLimit and GetStepPlanStatus for a card with the plan, its windows and when it ends; an anonymous session, another site's, or one renewed as someone else (past the refresh token's 30 days) is not kept or shown. Tested with a fake StepFun platform (renewal, early expiry, another account, pastes of each kind), the bookmarklet run against a stubbed page, and the field in a sandbox magpie web (signed out, a bad paste, signed in, sign out); not with a real StepFun sign-in |