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 |
||
|
|
73a12e8bf6 |
wsl: a distro's agent folder that is a link is opened where it leads (#4502)
On Windows, adding a skill or switching RTK on for an agent in WSL failed with `mkdir \\wsl.localhost\<distro>\root\.codex: Cannot create a file when that file already exists` (linusxiong). In the distro ~/.codex is a link to /mnt/c/Users/<user>/.codex. Through \\wsl.localhost Windows can't follow a link the distro has: a mkdir of it says it exists, and nothing below it can be made, written, read or listed. ggbdpq found and explained the link (thanks); their patch, which takes that EEXIST as "there", wasn't used: the writes below the link fail next (its test passed because a symlink here is followed). The fix, for every agent folder and every writer through \\wsl.localhost: - The WSL probe asks `readlink -f` in the distro where each agent folder, its skills folder and the folders beside them lead (wslLinkPaths -> distro.Links; a $HOME that is itself through a link is left alone), and which drive each Windows mount is (win:/mnt/c C: -> distro.Drives). - distro.open opens a path at or below a link where it leads: on a Windows drive, the drive's own path (C:\Users\<user>\.codex); elsewhere in the distro, through \\wsl.localhost again. native spells it back through the link, so the agent is told its own path. - A link readlink couldn't resolve is never guessed at: distro.open errors, and the agent is unreached (Agent.Unreached: its notice says why; every field Set and Sync returns it). - Writers: the agents' own files (place.join/place.open, every filepath.Join(at.home, ...) in internal/agent), the library's WSL targets (wslOpen/wslOpened; one "wsl" problem per agent and nothing written), RTK (rtkAt, rtkInstall checks agent.WSLOpen before its mkdir), the Sessions page's WSL reads (sessions.WSLHome.Open) and the Copilot CLI sign-in read (provider.CopilotWSLHomes -> CopilotWSLDirs). - Not changed: magpie's image MCP server opens arbitrary paths an agent in WSL gives it the same way; filed as #4578. Links deeper than the probed paths (other than <agent dir>/skills) aren't resolved. A distro probed by an older magpie has no Links until probed again (each run). Run: - Real Windows box (xiaomi-gpu, distro magpie-desktop, sandbox /tmp/x4502/home with .codex -> /mnt/c/Users/yeton/runs/x4502-target/.codex, .claude -> /tmp/x4502/data/claude, .pi -> a missing folder), a throwaway Windows test running the real probe with that HOME: probe said link:.codex /mnt/c/..., link:.claude /tmp/x4502/data/claude, link:.pi, win:/mnt/c C:, win:/mnt/d D:. The old way, MkdirAll(\\wsl.localhost\ magpie-desktop\tmp\x4502\home\.codex\skills\pdf) = "Cannot create a file when that file already exists" (the report's error). distro.open wrote SKILL.md to C:\Users\yeton\runs\x4502-target\.codex\skills\pdf and to \\wsl.localhost\magpie-desktop\tmp\x4502\data\claude\skills\pdf, both read back with cat in the distro through the links; .pi said "~/.pi in WSL magpie-desktop is a link magpie couldn't follow". Sandbox and target removed after. - New tests with a fake distro whose ~/.codex and ~/.claude are links to /mnt/c/... that don't exist here, so, as through \\wsl.localhost, nothing below them can be made: TestWSLFolderIsALinkToC, TestWSLFolderLinkUnresolved, TestRTKWSLFolderIsALink, TestRTKWSLFolderLinkUnresolved (library); TestWSLProbeLinks (runs the probe script), TestWSLOpenThroughLinks, TestWSLAgentFolderIsALink (config and a Claude session read on C:), TestWSLAgentFolderLinkUnresolved (agent). - Broken by hand: the library tests on the base (with a no-op FakeWSLDrives) fail with "mkdir .../home/me/.codex: file exists", the report's error; with ggbdpq's patch applied they still fail (the skill mkdir, and RTK's hook not written). - mote: go build ./...; go vet of agent, library, sessions, provider for darwin, GOOS=windows (and linux for agent, library); gofmt -l clean; go test -timeout 45m ./internal/agent ./internal/library ./internal/sessions ./internal/provider: all ok. - Windows (win-run): the same four packages. The new tests pass (the RTK ones skip: the fake distro runs sh). 32 tests are red, all already red at the base |
||
|
|
86b2f4d053 |
provider, gateway, gui: an account whose sign-in its vendor revoked or refused reads as signed out and is passed over, not asked on every request (#1793 ysicing, echo_ts on Discord)
What changed, one fix for the class:
- ChatGPT and the other built-in subscriptions (#1793): ChatGPT answered
401 token_revoked on every request, request after request (~18 rows in
the reporter's log), because a refused sign-in was just "other" and
rested a while, then asked again. Now a 401 whose words say the sign-in
is gone (provider.SignInRevoked: token_revoked, token_invalidated,
invalid_grant, refresh_token_reused/invalidated/expired; never
token_expired, a 403, a 5xx or a network error) marks the account for
the credential it was sent with (a 12-byte hash of the header, never the
credential), in logins.json as Refused "revoked:<mark>" plus Lapsed.
A saved ChatGPT account is refreshed first, as Codex does on a 401; a
refresh that goes through marks nothing. The routing loop fails it as
failAuth (next member at once, no rest); forwardOnce answers its later
requests with magpie's own 401 without asking the vendor; compaction
on a magpie account (compactOn) picks a marked one last. Signed in anew
(upsertLogin with another credential, addSideLogin), refreshed, or a
request served, the mark is gone. Claude, Copilot and plugins keep
their own marks; a key's provider answering the same words rests as
before.
- Copilot (echo_ts): a built-in Copilot account whose GitHub token GitHub
refused (401/403 on the token exchange, the CLI stand-in or the usage
read) is marked lapsed on its own account (copilot_lapsed.go), unless a
working CLI stand-in serves; cleared when a token is served or it signs
in again. 5xx and network errors never mark it.
- GUI: such an account's row says Sign-in required with Sign in again
(Copilot's on its GHE.com host) and Remove, the reason on its allowance
line in the user's language (zh, zh-TW, ja, de added); the card says
Signed out once every account in use is.
- docs/subsystems: providers-accounts "A revoked sign-in", gateway-routing.
What was run (sandbox HOME, caches pinned, worktree only):
- go test -race on the new tests: provider TestSignInRevokedWords,
TestRevokedSideLoginMarkedTillSignedInAgain, TestRevokedCodexRefreshedFirst,
TestRevokedSignInLeavesOthersMarks, TestUpsertLoginKeepsRevokedMarkForTheSameSignIn,
TestCopilot* (7); gateway TestRevokedSignInPassedOverTillSignedInAgain
(fake ChatGPT backend, zstd, real routing: turn 1 asks acct-1 then
acct-2, turns 2-4 and after a restart acct-2 only with no rests, after a
new auth.json acct-1 again and the mark gone),
TestRevokedSignInNotCompactedOnAgain, TestRevokedWordsFromAKeyRestAsBefore.
- Broken by hand, each turned a test red: the forwardOnce short-circuit,
the failureOf clause, noteSignIn in codexUpstreamOn, compactOn's skip,
ServedSignIn, its in-memory delete, the 401-only check, refresh-first,
upsertLogin's keep and its sameAuth, sideLogins' Lapsed and
addSideLogin's clear; and the six Copilot breaks. GUI: the signedOut
and quotaError lines each turn revoked-signin-account red.
- GUI (Chromium and WebKit, 420 and 1100, en/zh/zh-TW/ja/de):
revoked-signin-account (new), copilot-signed-out-account (new), and the
account-*, claude-*, codex-*, plugin-*, quota-*, signin-*, routing-*,
usage-accounts* suites: 1605 pass, 7 fail. Six are WebKit
routing-group-fold/routing-sessions/routing-steady cases that fail the
same on a clean
|
||
|
|
8c5b9f928d |
provider, agent, gui: subscription accounts can be turned off, and then no agent's sign-in is read (#1535, MaxHaiCom)
What changed: Settings → Privacy → Subscription accounts (On/Off), `magpie accounts discovery [on|off]` and MAGPIE_NO_ACCOUNTS=1 turn off account discovery. It stays on by default. While it is off, magpie reads none of the agents' sign-ins: ~/.claude/.credentials.json, .claude.json's account, ~/.codex/auth.json, Copilot's, Cursor's, Devin's, Kiro's, Gemini's, ZCode's, Command Code's and OpenCode's files. It runs no `security` / `secret-tool` for the Keychain or Secret Service, and asks no agent CLI who is signed in. It serves no subscription. API-key providers, middleware plugins and Pi extensions work as before. Why: the reporter runs magpie on machines where reading other tools' credentials isn't wanted. The owner delegated the call. How: settings.NoAccountDiscovery (kept per computer by KeepOwn) and settings.AccountDiscoveryOff(). The variable only ever turns discovery off. The gates sit at every reader (readAccountFile, discoveryOff) and at every route that reads or writes a sign-in, so a route that skips Accounts still reads nothing: - Accounts, All, Logins, usage, renewal, warm-up, session identities, check-ins; - switching, forgetting, SetLoginOn, StartSignIn, the imports; - moves onto plugins. The ones that write refuse with an error that names how to turn it back on. On the agent side, Agent.Source and OpenCode's auth.json are gated, and Codex wiring goes by magpie's stash instead of auth.json, so a toggle never rewires Codex. logins.json and plugin-auth.json are left untouched and serve again when discovery is turned back on. A change applies at once (ForgetAccounts). Docs: providers-accounts.md, README (en, zh-CN), and the site's CLI table (en, zh, ja). Run: - TestAccountDiscoveryOffReadsNoSignIn (provider) and TestAccountDiscoveryOffAgentsReadNoSignIn (agent). Every credential path is a FIFO that records each open, and security, secret-tool, claude, codex, cursor-agent, devin, kiro-cli, copilot and grok are fakes on PATH. Both fail with the gate removed: they show the opens and `security find-generic-password -s Claude Code-credentials`, among others. Both pass with the gate in place. - TestAccountDiscoverySetting and TestAccountsDiscoveryCmd. - account-discovery.test.cjs: chromium and webkit, 900 and 360 wide, en/zh/zh-TW/ja/de, 32/32. The neighbouring privacy, redact, settings-sections and i18n-keys GUI tests: 49/49. - The full `go test -tags nogui ./...`, gofmt -l, and go vet for darwin, linux and windows on the touched packages. Not tried: a real machine under fs_usage, and Linux and Windows at runtime. The FIFO tests are !windows. |
||
|
|
4464ef28d4 |
provider: magpie on Linux finds the Copilot CLI 1.0's token in the keyring (#723, jia2)
magpie looked the CLI's token up with `secret-tool lookup service copilot-cli account <host>:<login>`, the attributes keytar wrote before the CLI 1.0. The CLI 1.0's Rust runtime keeps it through keyring-core's zbus-secret-service-keyring-store, whose items carry service and username (cred.rs search_attributes), so a CLI 1.0 signed in with a keyring (magpie inside WSL or on a Linux desktop) wasn't found. copilotSecretTool asks for both attributes, account first, and bounds each lookup at 5s (copilotSecretWait): a keyring waiting on an unlock prompt nobody answers held the caller for good, including a sign-in's last step (addCopilotLogin -> copilotOwnUser -> copilotCLILogin). The service name is still taken to be copilot-cli: the string is in the 1.0.95 runtime, but which call uses it couldn't be read from the binary. Run: TestCopilotSecretToolUsername (a shell secret-tool answering only under username, and one that never answers): red with only "account" asked, green now. |
||
|
|
31468ad0ed |
provider, agent: magpie on Windows finds the Copilot CLI signed in inside a running WSL distro (#723, jia2)
jia2 runs Copilot CLI 1.0.95 inside WSL, signed in, and magpie (on Windows) never saw it: copilotCLILogin read only Windows' %USERPROFILE%\.copilot\config.json. In a distro with no Secret Service (WSL has none unless one is set up), the CLI asks to keep its token in plaintext and writes it under copilotTokens["https://github.com:<login>"] in ~/.copilot/config.json (read from the @github/copilot 1.0.95 package: its Rust runtime's storeTokenPlaintext / needs-plaintext-DBus path). - provider: copilotCLILogin falls back to each running distro's ~/.copilot/config.json (plaintext tokens only; a distro's keyring is out of reach), through a new CopilotWSLHomes hook, cached 20s since it is read over WSL's file share. The read itself moved into copilotCLILoginIn(dir, secret). - agent: the probe looks for $HOME/.copilot, and a distro that has only it is kept (wslKept) so its home is known; it makes no agent row. CopilotWSLHomes lists only running distros: reading a stopped one would start it. Run: TestCopilotCLIInWSL (provider) and TestWSLCopilotHome (agent), both red with the fallback / wslKept broken by hand, green with it; go test ./internal/agent ./internal/sessions green; both tests also pass on Windows 11. On the Windows box with a real running distro, a program built from this commit listed \\wsl.localhost\<distro>\home\<user> and found the copilot account once a CLI-shaped plaintext config.json was put in the distro's ~/.copilot (removed after), and none before. No real Copilot CLI sign-in was used. |
||
|
|
21702d01ff |
Add German translation; harden paths against unset env vars (#770)
* Add German translation and harden paths against unset env vars Add a German locale to the GUI, tray menu, usage alerts and website home page, and refuse to start when the home folder is unset or relative so nothing is written under the working folder; the pi plugin no longer adopts the user's PI_CODING_AGENT_DIR, and an inherited APPIMAGE no longer selects portable mode. Scripts refuse to run from the wrong folder or empty a shared out folder, and a new internal/testenv sandboxes every test package from the user's real files, which also fixes the Claude picker and Termux installer tests on Windows. * Makefile: know magpie's folder by its go.mod, so paths with spaces work The check compared $(CURDIR) with $(dir $(abspath …)), which make splits on spaces, so a checkout under 'My Projects' or 'John Doe' refused every target. It now reads go.mod relative to the working folder and wants magpie's module there: make -C and a symlinked Makefile work, make -f from another folder still stops before any recipe runs. * i18n: German for the strings main added since, with a parity test 75 strings main added (group order, patterns, slow-start wait, usage caps, RTK savings …) get their German, and two that main dropped go. gui-de.test.cjs checks, as gui-ja does, that de has every zh string with its placeholders and tags, and that the window reads in German when picked or on a German system. * appdir: ignore relative folder variables when reading, keep them for children CheckEnv no longer unsets anything. magpie reads the XDG folders, APPDATA/LOCALAPPDATA and every agent's folder variable through appdir.Getenv/LookupEnv, which pass over a relative value; the environment stays as it is, so the agents magpie starts get the variable as the user set it. That covers what proc.UserPath lends from the login shell too, which is set after main's check and reached the desktop app unchecked. On Windows a path rooted on the current drive (\Users\x, Git Bash's /c/x) counts as usable, and magpie version and help answer without a home, before run makes any folder. * Sandbox the tests main added since internal/wslrun gets testenv's TestMain, and four tests main added that set HOME alone set their home with testenv.SetHome, so on Windows they don't read the runner's profile through USERPROFILE. * agentenv: PI_CONFIG_DIR and OPENCODE_DB take relative names on purpose omp puts $PI_CONFIG_DIR under the home and OpenCode a relative $OPENCODE_DB in its data folder, so neither depends on the working folder: appdir no longer passes them over. * i18n: German for the Library's multi-select and System One's decision API The 19 strings main added since (#791's skill multi-select, the decision API snippets) get their German; the one main replaced (four APIs → five APIs) goes. * appdir: tidy the import into magpie's group; say what Go makes of /c/x The appdir import joins the group of magpie's own imports where a file has one. rooted's comment now says that Go takes a Git Bash path like /c/x as \c\x on the current drive, not C:\x. |
||
|
|
9f94b2156b |
copilot: an account on GitHub Enterprise Cloud with data residency (*.ghe.com) signs in, is read from copilot login --host and is served at its enterprise (#723, guitaoliu: magpie skipped a Copilot CLI sign-in whose host wasn't github.com and its own sign-in was fixed to github.com) — a Copilot account now remembers its host (copilotApp.Host, "host" in its logins.json auth; none for github.com) and every URL it uses follows it, as VS Code's Copilot Chat, copilot.lua and avante do (checked against the issue's references and GitHub's docs): the device flow at https://<name>.ghe.com/login/device/code and /login/oauth/access_token with the same Copilot OAuth app, the device page there, whose account at https://api.<name>.ghe.com/user, its plan and usage at api.<name>.ghe.com/copilot_internal/user, its session token at api.<name>.ghe.com/copilot_internal/v2/token, and its requests, model list, Auto and terms at the session's endpoints.api, or https://copilot-api.<name>.ghe.com when it names none (the provider's base too). A github.com account has no host and goes where it always did, the same vars and the same bytes. CopilotHost (copilot_ghe.go) takes only github.com or one <name>.ghe.com label (a scheme and a trailing slash are dropped; a port, path, user, deeper subdomain or any other host is refused), in the sign-in, the CLI and a host read back from logins.json, so a GitHub token is never sent to a host of the user's choosing. The Copilot CLI's sign-in: a github.com account first, as before; then one copilot login --host <name>.ghe.com signed in, its token under "https://<name>.ghe.com:<login>" in copilotTokens or the keychain; a GitHub Enterprise Server host is still left out. An editor's apps.json entry keyed "<name>.ghe.com:…" is read after the editors' github.com one and the CLI's. GUI: a Copilot device code's panel has "Account on GHE.com?" (zh 账号在 GHE.com 上?), which ends that sign-in and asks "Your enterprise on GHE.com" (你的企业在 GHE.com 上的地址) in a field (acme.ghe.com; Sign in stays off until it reads as <name>.ghe.com), then signs in there; that sign-in's panel offers "Sign in on github.com instead" (改为在 github.com 登录), as does a failed one. CLI: magpie accounts add copilot [--host <name>.ghe.com]. TestCopilotHost, TestCopilotGHESignIn (an httptest server standing in for acme.ghe.com, api.acme.ghe.com and copilot-api.acme.ghe.com through copilotGHEOrigin: sign-in, what is kept, models, a signed request, usage, nothing sent to github.com, a bad host refused) and TestCopilotCLIGHELogin are new and fail on the old code; copilot-ghe.test.cjs (webkit and chromium, en and zh: the link, the field refusing evil.com, a.b.ghe.com, ports and the like, the posted site, the way back, cancels, no native select, no left-border accent) fails on the old code. go vet, builds (darwin, GOOS=linux, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass; signin-link, signin-close, signin-again and routing-signin pass in webkit, signin-callback fails before and after the change alike. Not tried with a real GHE.com account: the URLs follow the references, and the CLI's token key for a ghe.com host is taken to be the github.com one's form. Accounts are still told apart by login alone; an EMU login carries its enterprise's suffix.
|
||
|
|
e8b3be572c | windows: the desktop app no longer opens a console window for every command it runs (#54) — it is linked as a GUI program and has no console, so each console CLI it started (devin auth status and models list, devin acp for every Devin turn, claude, codex, cursor-agent and grok probes and runs, grok login) was given a new console by Windows, and a Windows Terminal window with it, some every few seconds while the app sat idle. Every command magpie runs is now made through internal/proc, which starts it with CREATE_NO_WINDOW when magpie has no console of its own: the child gets a console without a window, and its output, which magpie always pipes back, arrives as before. A magpie run in a terminal (magpie serve, the TUI, the desktop app started from one with a command) has one, and its children share it as they did, so Ctrl+C there still reaches them. The relaunch after an update keeps its DETACHED_PROCESS, added to rather than replacing the flags it was made with, and a test fails on any command made with os/exec directly, so a new one can't bring the windows back | ||
|
|
e1d211cc4b | provider: a Copilot CLI sign-in is found — who from ~/.copilot/config.json (JSONC, COPILOT_HOME honoured), the token from the keychain's copilot-cli item or the file's plaintext copilotTokens; the CLI's token is not traded for a session token (that answers 403) but sent as is under the CLI's own integration, at the API its account is served from |