ac4af582301a4e8a29245dbba767eba31334ddf9
6
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 |
||
|
|
4062cda781 |
provider: a custom provider at a Token Plan's or Ark's address is asked for no access key (ysm119)
ysm119 on Discord saved a custom provider (no preset) at https://tokenhub.tencentmaas.com/plan/v3 with a plain sk- key on the OpenAI-compatible tab, and its editor asked for a SecretId and SecretKey. AccessKeyVendor decides by host alone, so any provider at a Token Plan's /plan address (or an Ark plan's) got the access-key fields, and a Singapore Token Plan or Ark one also got a Usage card asking for them. Now AsksAccessKey(p) gates the two places a user is asked: the editor's listing (gui/providers.go) and the keyless Usage cards (tencentPlanQuotas, volcPlanQuotas). A preset's provider is asked as before; a custom one only once it has an access key saved (so a key the user did give is still shown and still used for its usage). The host rules themselves are unchanged, since presetAccessKey and the presets read them on providers with no preset of their own. The key itself was already sent as typed: no Tencent signing exists on chat, Responses, the model list or a probe; the access key only reads plan usage. TestCustomTokenHubIsSentAsTyped holds that (Authorization: Bearer <key>, on Chat and Responses). Run on mote (go1.26.8): - go test ./internal/provider ./internal/gui: provider ok; gui red only in TestMainWindowCorners (AppKit, #3949, macOS 27 on mote). - TestPlanCardWithoutAccessKey, TestCustomTokenHubIsSentAsTyped, TestProviderListTellsTencentAccessKey ok. - GUI (node --test, Chromium and WebKit, 5 languages): tencent-access-key, tencent-cloud, volc-access-key, usage-access-key-card, i18n-keys and the provider editor's key files ok, except tencent-cloud's "a region clicked right after the strip scrolled" (#4321, open, same on main). - gofmt -l clean; go vet, GOOS=linux go vet -tags nogui, GOOS=windows go vet on provider, gateway, gui ok. Broken by hand: AsksAccessKey returning AccessKeyVendor(p) always turns TestPlanCardWithoutAccessKey (my-ark gets a card), TestCustomTokenHubIsSentAsTyped and TestProviderListTellsTencentAccessKey (my-tokenhub, my-intl, my-ark asked) red. Not tried: the reporter's real tokenhub key; the real app's editor. |
||
|
|
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
|
||
|
|
6e6aba51c8 |
providers: a key may be for another plan of its vendor, sent to that plan's endpoints
yckonnnn on X uses Volcengine's pay as you go and its Agent Plan, and wants a key of each in one provider. Each plan takes its own keys at its own endpoints (/api/v3, /api/plan/v3, /api/coding/v3), and every key of a provider went to the provider's one plan, so only one kind worked. A key now may say which of its preset's Regions it is for (KeyAccount.Plan; Provider.KeyPlan for the first key, as KeyProtocol). None, or the provider's own plan, is the provider's plan, stored as none: old configs read and write as before. Presets whose plans take keys of their own (PresetDef.KeyPlans): zhipu, zai, stepfun, stepfun-cn, xiaomi, baidu-qianfan, tencent-cloud, huaweicloud, volcengine, siliconflow. Not: yylx (one key everywhere), bailian-decision (decide only), bedrock and bedrock-mantle (regions of one account). Every reader of the region or a base URL, and what it does now: - WithKey (keys.go): moves the key's copy to its plan (atKeyPlan: Chat, Responses, Anthropic, Decide, KeysURL, Website, Catalog via atRegionOf; a provider at a host of its own keeps that host) and marks it keyView. Every gateway key path goes through it: chat, Responses, Messages, count_tokens, failover, embeddings (serveRetrieval via onKeys), drawing (drawOnAccounts via perKeyBarred), key tests (test.go), key_models.go, gui/groups.go, markedKey. - perKeyBarred (gateway/fallback.go): a key whose plan's list lacks the model (PlanServing) is not asked; only when no key's plan has it. - fetch / fetchPerKey / planOnly (models.go): a mixed provider lists each key's plan, a NoList plan from its preset list with no request, pay as you go from /api/v3/models with its own key. - planMedia (PlanEmbeddings, PlanDrawers, PlanVideos): every plan's. - PlanQuotas (planquota.go): each key read at its own plan's source. - volcPlanQuotas, tencentPlanQuotas: one view per plan (planViews). - KeyBalances (balance.go): each key at its plan's host (SiliconFlow). - startVideo / videoMaker (gateway/video.go): a mixed provider starts on a key whose plan makes the model (onKeys) and names it in the id (keyMark), so the poll goes to that key's plan. - GUI: POST /api/keys/plan (SetKeyPlan, then the lists are read again); the editor keeps KeyPlan with an unchanged first key, typed() clears it with a new one; KeepSecrets, AddCopy, backup's withoutKeys carry it. - app.js: planPicker, a plan chip in each key row (the app's own menu, openProtoMenu, through pickPill, which protoPicker now shares), shown for a KeyPlans preset while the provider has several keys or the key has a plan; i18n zh, zh-TW, ja, de. A key's plan is not guessed from the key: Volcengine's keys carry nothing that says their plan. Xiaomi's tp-, Tencent's sk-tp-, MiniMax's sk-cp- and Bailian's sk-sp- are noted in code but not used. Not done: a gateway key held to some keys (videoAsker) on a mixed provider's video may pick another key; a mixed provider whose own plan has no balance source while a key's plan has one is not read; keys left out for their plan don't show in the Routing trace; StepFun's plan windows are a sign-in per site, unchanged. Credit: yckonnnn on X (tweet 2114657701305487483). Run at this commit on origin/main |
||
|
|
8792ee063d |
provider: a Volcengine or Tencent access key is kept through sync, restore, a stale editor and a copy, and a plan card without one says what to give (#1821, Edward4226)
The reporter's Volcengine Agent Plan card vanished: providers.json had
lost accessKeyID/secretAccessKey, and volcPlanQuotas skipped a provider
without them before building any card, so nothing said why.
Writers that dropped the access key, fixed at the cause:
- Sync and restore (Mirror, Restore, davsync take) kept this machine's
access key and balance token only when the incoming provider had no
key at all. A magpie before v0.1.1142 (
|
||
|
|
aa82288fb6 |
usage: Volcengine Ark's Coding Plan and Agent Plan windows, read with the account's access key (#1427, yayoinoyume)
Ark tells a Coding Plan's or Agent Plan's 5-hour, weekly and monthly
windows only to the account's control plane (GetCodingPlanUsage,
GetAFPUsage on open.volcengineapi.com), signed with the account's
AccessKey ID and Secret, never to the plan's inference key. An Ark
provider's editor now takes that access key, and the Usage page shows the
plan's windows as a card.
From yayoinoyume's feat/volcengine-usage, reviewed and reworked:
- Signing is volc-sdk-golang's (base/sign.go GetSignRequest, 06f9ef66):
signed headers sorted (content-type;host;x-content-sha256;x-date), only
Action and Version in the query. The branch signed them unsorted and put
Region in the query. TestVolcSignMatchesSDK pins two signatures the SDK
made.
- The card is in PlanQuotas beside the Step Plan's (its cache, last
reading, refresh and `magpie quota wait`), not in the subscription
cards. One per access key and plan.
- The plan is the endpoint's: /api/coding asks GetCodingPlanUsage,
/api/plan GetAFPUsage, pay-as-you-go none, in the host's region. The
branch asked both and showed whichever answered.
- Dropped guessed reply fields; the Coding Plan reply is the one
pi-ark-usage, dsh-ark-quota and ArkCodingPlanUsage read. AFP buckets are
read in the forms dsh-ark-quota and arkcli read (Used of Quota or Total,
or Percent), plus Tier; none was seen from a real account.
- An Ark provider is known by its host, not the preset id, so a copy or a
custom provider takes the key too.
- The Secret is never sent to the page (accessKey {id, secretSet}); a
blank Secret keeps it, a save without the ID keeps both, Remove
(clearAccessKey) drops both, an ID with no Secret is refused.
- The pair goes where keys go: AddCopy, Restore, Mirror, backups and
davsync carry it only with keys (withoutKeys), and a keyless restore or
sync keeps this machine's. CLI: access.key, access.secret.
- A changed access key drops the cached cards (ForgetPlanQuotas).
- UI strings in zh, zh-TW, ja and de.
Nothing was tried against the real Volcengine API: there was no access
key. A local fake checked the real request PlanQuotas makes against
volc-sdk-golang's own GetSignRequest (both actions, two regions); it
lives outside the repo, so go.mod is unchanged.
Run: gofmt -l; go vet (darwin), GOOS=linux and GOOS=windows go vet
-tags nogui on provider, gui, backup, davsync and the root; go test
-tags nogui ./internal/provider ./internal/gui ./internal/backup
./internal/davsync . under a temp HOME; node --test
volc-access-key, zhipu-team, gui-ja, gui-de, i18n-keys in Chromium and
WebKit. Fail without the change: TestVolcSignMatchesSDK (unsorted
headers), TestAddCopy, TestBackupBalanceToken, TestNoKeys,
TestTakeBalanceToken, TestSyncBalanceToken (pair not carried),
TestProviderSaveKeepsVolcengineSecret (blank Secret dropped),
volc-access-key (Remove not posted).
Co-authored-by: YAYOI27 <111715843+yayoinoyume@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
|