agent: Claude Desktop's key, sealed at rest by Desktop 4.4212, isn't said to be changed (Discord)
A Windows user on Discord: the Agents list keeps saying Claude Desktop's
inferenceGatewayApiKey (00000000-0000-4000-8000-6d6167706965.json) was
changed. Reconnect and a Desktop restart help only until the next start.
Cause: Claude Desktop 4.4212.0 (2026-10-29, Windows and macOS) seals
configLibrary secrets at rest. Its custom-3p:keys sweep runs at every start
and rewrites each clear-text secret field, inferenceGatewayApiKey among
them, in place as
"__sealed__:v1:" + base64(protect("anthropic.claude.crossProfileSecret.v1:"
+ {"configLibrary":{"key":k,"value":v}}))
Desktop opens the value again when it reads the profile, so it still sends
magpie's key and the gateway takes it. Only magpie's file check saw another
string. In 4.29.0 the writer was gated on !app.isPackaged; in 4.4212 the
gate is gone. Read from the 4.4212 nupkg and macOS zip's app.asar.
protect is the claude-native addon's userDpapiProtect on Windows (user
DPAPI, entropy "anthropic.claude.crossProfileSecret.v1") and Electron
safeStorage (Keychain) on macOS.
Fix: desktopOpen opens a sealed value before Check and Sync judge it. On
Windows it is opened with CryptUnprotectData and that entropy, the prefix
and the configLibrary key are checked, and the clear key is then compared
as before, so a sealed key that isn't magpie's is still "was changed". A
seal magpie can't open (macOS Keychain, another user, a bad blob) is
unknown, not changed: no notice, and Sync doesn't write over it. The
gateway's auth is unchanged; it still takes only the key magpie wrote,
which is what Desktop sends after opening the seal.
Run (mote, at this head on 99c2567cf): gofmt -l clean, go vet
./internal/agent, GOOS=windows and GOOS=linux go vet ./internal/agent,
go test -count=1 -timeout 45m ./internal/agent ok. Windows (xiaomi-gpu,
win-run): go test -count=1 -timeout 45m ./internal/agent: 14 reds, none
in Claude Desktop's key path. 13 fail the same at base 99c2567cf run
there; TestHermesProfilesFollowMagpieModel passed at the base and passes
6 of 6 alone at this head. All 14 are filed: #4115 (Hermes, Desktop
language, DesktopExec, WorkBuddy, Copilot/Qoder folders ...), #2808
(Codex keychain), #1827. The new Windows seal tests pass there.
Real blob: on xiaomi-gpu, Desktop's own claude-native-binding.node
(userDpapiProtect) sealed the clear text exactly as Desktop 4.4212 builds
it; desktopOpen opened it from Go to the original key (a throwaway test,
deleted after, since the blob opens only for that user).
Broken by hand: with the old claudedesktop.go, TestClaudeDesktopSealedKey
IsNotChanged fails with the reported message ("... inferenceGatewayApiKey
... was changed ...") and TestClaudeDesktopImportedSealedKeyStays fails on
its check and on Sync rewriting the sealed key. Without the entropy, the
real-blob open failed ("The data is invalid").
Not tried: a real Claude Desktop 4.4212 running against magpie on Windows
or macOS (not started; the live config on this Mac untouched). On macOS a
sealed key is left unknown rather than opened, so a key changed there by
hand after sealing is not reported until Desktop's file is clear again.
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -251,10 +251,20 @@ func desktopCheck(p desktopPaths) string {
|
||||
want := agentKey("claude-desktop")
|
||||
return wiringOff("Claude Desktop", prof, func(k string) (string, bool) {
|
||||
v, ok := edit.GetJSON(prof, k)
|
||||
if k == "inferenceGatewayApiKey" && prof != p.prof && desktopKeyTaken(v, want) {
|
||||
if k != "inferenceGatewayApiKey" {
|
||||
return v, ok
|
||||
}
|
||||
// Desktop seals the key at rest (desktopOpen): the one it opens
|
||||
// to is the one it sends; one magpie can't open is unknown, and
|
||||
// not said to be changed
|
||||
open, known := desktopOpen(k, v)
|
||||
if !known {
|
||||
return want, true
|
||||
}
|
||||
if prof != p.prof && desktopKeyTaken(open, want) {
|
||||
return want, true // a key of magpie's other than Desktop's own
|
||||
}
|
||||
return v, ok
|
||||
return open, ok
|
||||
}, "inferenceGatewayBaseUrl", gateway.URL(), "inferenceGatewayApiKey", want)
|
||||
}
|
||||
|
||||
@@ -298,7 +308,8 @@ func desktopAppliedGateway(p desktopPaths) string {
|
||||
// desktopKeyApplied gives the profile desktopAppliedGateway finds the
|
||||
// key magpie gives Desktop, only where the one it holds is a key this
|
||||
// gateway won't take (another magpie's, from the computer it was exported
|
||||
// on): one it takes stays. Its address and every other setting, its
|
||||
// on): one it takes stays, and so does one Desktop sealed that magpie
|
||||
// can't open (desktopOpen). Its address and every other setting, its
|
||||
// connectors among them, stay as they are.
|
||||
func desktopKeyApplied(p desktopPaths) error {
|
||||
f := desktopAppliedGateway(p)
|
||||
@@ -306,7 +317,9 @@ func desktopKeyApplied(p desktopPaths) error {
|
||||
return nil
|
||||
}
|
||||
want := agentKey("claude-desktop")
|
||||
if v, _ := edit.GetJSON(f, "inferenceGatewayApiKey"); desktopKeyTaken(v, want) {
|
||||
v, _ := edit.GetJSON(f, "inferenceGatewayApiKey")
|
||||
// a key Desktop sealed that magpie can't open is left as it is
|
||||
if open, known := desktopOpen("inferenceGatewayApiKey", v); !known || desktopKeyTaken(open, want) {
|
||||
return nil
|
||||
}
|
||||
kvs := []edit.KV{{Path: "inferenceGatewayApiKey", Value: want}}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Claude Desktop 4.4212 (10-29) keeps the secrets of its configLibrary
|
||||
// profiles encrypted at rest. At every start it sweeps configLibrary and
|
||||
// writes each secret it finds in the clear (inferenceGatewayApiKey among
|
||||
// them) back as
|
||||
//
|
||||
// "__sealed__:v1:" + base64(protect("anthropic.claude.crossProfileSecret.v1:" +
|
||||
// {"configLibrary":{"key":"inferenceGatewayApiKey","value":"<the key>"}}))
|
||||
//
|
||||
// (its custom-3p:keys sweep; protect is the user's DPAPI on Windows, its
|
||||
// native userDpapiProtect, and Electron's safeStorage, the Keychain, on
|
||||
// macOS), and opens it again when it reads the profile.
|
||||
// It sends the gateway the key as it was, so the value magpie wrote no
|
||||
// longer reads as magpie's key in the file while Desktop still runs on it:
|
||||
// magpie said the key "was changed", Reconnect wrote it in the clear and
|
||||
// Desktop sealed it again at its next start (a Windows user on Discord).
|
||||
const (
|
||||
desktopSealed = "__sealed__:v1:"
|
||||
desktopSealedWith = "anthropic.claude.crossProfileSecret.v1:"
|
||||
)
|
||||
|
||||
// errDesktopSealed: Desktop sealed a value with a keystore magpie can't
|
||||
// open here.
|
||||
var errDesktopSealed = errors.New("sealed by Claude Desktop")
|
||||
|
||||
// desktopOpen is the value v Desktop keeps at key k of a configLibrary
|
||||
// profile, as Desktop reads it: v itself, or what a sealed v opens to.
|
||||
// known is false for a sealed value magpie can't open (another system's
|
||||
// keystore, another user's, or not one of Desktop's): what it holds is
|
||||
// unknown, which is not the same as changed.
|
||||
func desktopOpen(k, v string) (open string, known bool) {
|
||||
t := strings.TrimLeft(v, " \t\r\n")
|
||||
if !strings.HasPrefix(t, desktopSealed) {
|
||||
return v, true
|
||||
}
|
||||
b, err := base64.StdEncoding.DecodeString(strings.TrimSpace(t[len(desktopSealed):]))
|
||||
if err != nil {
|
||||
return "", false
|
||||
}
|
||||
plain, err := desktopUnprotect(b)
|
||||
if err != nil {
|
||||
return "", false
|
||||
}
|
||||
s, ok := strings.CutPrefix(string(plain), desktopSealedWith)
|
||||
if !ok {
|
||||
return "", false
|
||||
}
|
||||
var m struct {
|
||||
ConfigLibrary struct {
|
||||
Key string `json:"key"`
|
||||
Value *string `json:"value"`
|
||||
} `json:"configLibrary"`
|
||||
}
|
||||
// Desktop opens a value only for the key it was sealed for
|
||||
if json.Unmarshal([]byte(s), &m) != nil || m.ConfigLibrary.Key != k || m.ConfigLibrary.Value == nil {
|
||||
return "", false
|
||||
}
|
||||
return *m.ConfigLibrary.Value, true
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
//go:build !windows
|
||||
|
||||
package agent
|
||||
|
||||
// desktopUnprotect: outside Windows magpie opens nothing Claude Desktop
|
||||
// sealed; what it holds stays unknown.
|
||||
func desktopUnprotect([]byte) ([]byte, error) { return nil, errDesktopSealed }
|
||||
@@ -0,0 +1,97 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
)
|
||||
|
||||
// a value Claude Desktop sealed with a keystore magpie can't open (another
|
||||
// user's DPAPI on Windows, the Keychain's "Claude Safe Storage" on macOS)
|
||||
var desktopForeignSeal = desktopSealed + base64.StdEncoding.EncodeToString([]byte("not this user's keystore"))
|
||||
|
||||
// Claude Desktop 4.4212 seals inferenceGatewayApiKey in magpie's profile at
|
||||
// its next start. Desktop still runs on magpie: the check doesn't say the
|
||||
// key was changed, and Sync and Reconnect leave nothing to undo.
|
||||
func TestClaudeDesktopSealedKeyIsNotChanged(t *testing.T) {
|
||||
home, p := desktopSandbox(t)
|
||||
os.MkdirAll(p.dir, 0o755)
|
||||
a := claudeDesktop(home)
|
||||
if err := a.Field("provider").Set("magpie"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := edit.SetJSON(p.prof, edit.KV{Path: "inferenceGatewayApiKey", Value: " " + desktopForeignSeal}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if c := a.Check(); c != "" {
|
||||
t.Errorf("check with the key sealed: %s", c)
|
||||
}
|
||||
before, _ := os.ReadFile(p.prof)
|
||||
if err := a.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if b, _ := os.ReadFile(p.prof); string(b) != string(before) {
|
||||
t.Errorf("sync rewrote the profile:\n%s", b)
|
||||
}
|
||||
|
||||
// a key in the clear that isn't magpie's is still a change
|
||||
edit.SetJSON(p.prof, edit.KV{Path: "inferenceGatewayApiKey", Value: "sk-someone-elses"})
|
||||
if c := a.Check(); !strings.Contains(c, "inferenceGatewayApiKey") || !strings.Contains(c, "was changed") {
|
||||
t.Errorf("check with another key: %q", c)
|
||||
}
|
||||
// and so is one gone
|
||||
edit.DelJSON(p.prof, "inferenceGatewayApiKey")
|
||||
if c := a.Check(); !strings.Contains(c, "is gone") {
|
||||
t.Errorf("check with no key: %q", c)
|
||||
}
|
||||
// and an address elsewhere, with the key sealed
|
||||
edit.SetJSON(p.prof, edit.KV{Path: "inferenceGatewayApiKey", Value: desktopForeignSeal},
|
||||
edit.KV{Path: "inferenceGatewayBaseUrl", Value: "http://elsewhere:1"})
|
||||
if c := a.Check(); !strings.Contains(c, "elsewhere") {
|
||||
t.Errorf("check with another address: %q", c)
|
||||
}
|
||||
}
|
||||
|
||||
// An imported profile for magpie's gateway Desktop applies, its key
|
||||
// sealed: on magpie, and Sync doesn't write a key over Desktop's.
|
||||
func TestClaudeDesktopImportedSealedKeyStays(t *testing.T) {
|
||||
const imported = "3f6c2a8e-9b1d-4e57-a0c4-7d2e5f81b9a6"
|
||||
home, p := desktopSandbox(t)
|
||||
os.MkdirAll(p.dir, 0o755)
|
||||
a := claudeDesktop(home)
|
||||
if err := a.Field("provider").Set("magpie"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
f := filepath.Join(p.library, imported+".json")
|
||||
prof := `{"inferenceProvider":"gateway","inferenceGatewayBaseUrl":"` + gateway.URL() +
|
||||
`","inferenceGatewayApiKey":"` + desktopForeignSeal + `","inferenceGatewayAuthScheme":"bearer"}`
|
||||
desktopWrite(t, f, prof)
|
||||
desktopWrite(t, p.meta, `{"appliedId":"`+imported+`","entries":[{"id":"`+desktopProfileID+`","name":"magpie"},{"id":"`+imported+`","name":"magpie"}]}`)
|
||||
if c := a.Check(); c != "" {
|
||||
t.Errorf("check: %s", c)
|
||||
}
|
||||
if err := a.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if b, _ := os.ReadFile(f); string(b) != prof {
|
||||
t.Errorf("sync wrote the imported profile:\n%s", b)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDesktopOpenNotSealed(t *testing.T) {
|
||||
for _, v := range []string{"", "magpie-claude-desktop", "__sealed__:v2:abc", "x__sealed__:v1:"} {
|
||||
if got, known := desktopOpen("inferenceGatewayApiKey", v); !known || got != v {
|
||||
t.Errorf("%q: %q %v", v, got, known)
|
||||
}
|
||||
}
|
||||
for _, v := range []string{desktopSealed, desktopSealed + "%%%", desktopForeignSeal} {
|
||||
if got, known := desktopOpen("inferenceGatewayApiKey", v); known || got != "" {
|
||||
t.Errorf("%q: %q %v, want unknown", v, got, known)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
// desktopEntropy is the entropy Claude Desktop's native userDpapiProtect
|
||||
// (claude-native's user_dpapi) gives CryptProtectData: its secret's
|
||||
// purpose, the one string beside CryptProtectData in the binary (4.4212).
|
||||
const desktopEntropy = "anthropic.claude.crossProfileSecret.v1"
|
||||
|
||||
// desktopUnprotect opens what Claude Desktop sealed with the user's DPAPI
|
||||
// (userDpapiProtect), never prompting.
|
||||
func desktopUnprotect(b []byte) ([]byte, error) {
|
||||
if len(b) == 0 {
|
||||
return nil, errDesktopSealed
|
||||
}
|
||||
in := windows.DataBlob{Size: uint32(len(b)), Data: &b[0]}
|
||||
e := []byte(desktopEntropy)
|
||||
entropy := windows.DataBlob{Size: uint32(len(e)), Data: &e[0]}
|
||||
var out windows.DataBlob
|
||||
if err := windows.CryptUnprotectData(&in, nil, &entropy, 0, nil, windows.CRYPTPROTECT_UI_FORBIDDEN, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer windows.LocalFree(windows.Handle(unsafe.Pointer(out.Data)))
|
||||
return append([]byte(nil), unsafe.Slice(out.Data, out.Size)...), nil
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
)
|
||||
|
||||
// desktopSealHere seals v at key k as Claude Desktop does on Windows: the
|
||||
// user's DPAPI, with its entropy, over its prefix and
|
||||
// {"configLibrary":{key,value}}.
|
||||
func desktopSealHere(t *testing.T, k, v string) string {
|
||||
t.Helper()
|
||||
j, _ := json.Marshal(map[string]any{"configLibrary": map[string]string{"key": k, "value": v}})
|
||||
b := []byte(desktopSealedWith + string(j))
|
||||
in := windows.DataBlob{Size: uint32(len(b)), Data: &b[0]}
|
||||
e := []byte(desktopEntropy)
|
||||
entropy := windows.DataBlob{Size: uint32(len(e)), Data: &e[0]}
|
||||
var out windows.DataBlob
|
||||
if err := windows.CryptProtectData(&in, nil, &entropy, 0, nil, windows.CRYPTPROTECT_UI_FORBIDDEN, &out); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer windows.LocalFree(windows.Handle(unsafe.Pointer(out.Data)))
|
||||
return desktopSealed + base64.StdEncoding.EncodeToString(unsafe.Slice(out.Data, out.Size))
|
||||
}
|
||||
|
||||
func TestDesktopOpensWhatDesktopSealed(t *testing.T) {
|
||||
k := "inferenceGatewayApiKey"
|
||||
if got, known := desktopOpen(k, desktopSealHere(t, k, "magpie-x-claude-desktop")); !known || got != "magpie-x-claude-desktop" {
|
||||
t.Errorf("opened %q %v", got, known)
|
||||
}
|
||||
// sealed for another key: Desktop wouldn't open it there either
|
||||
if got, known := desktopOpen(k, desktopSealHere(t, "anthropicApiKey", "sk")); known {
|
||||
t.Errorf("another key's seal opened to %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
// On Windows magpie opens the key Desktop sealed: magpie's own is on
|
||||
// magpie, another one sealed is a change.
|
||||
func TestClaudeDesktopSealedKeyOpened(t *testing.T) {
|
||||
home, p := desktopSandbox(t)
|
||||
os.MkdirAll(p.dir, 0o755)
|
||||
a := claudeDesktop(home)
|
||||
if err := a.Field("provider").Set("magpie"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
k := "inferenceGatewayApiKey"
|
||||
edit.SetJSON(p.prof, edit.KV{Path: k, Value: desktopSealHere(t, k, agentKey("claude-desktop"))})
|
||||
if c := a.Check(); c != "" {
|
||||
t.Errorf("check with magpie's key sealed: %s", c)
|
||||
}
|
||||
edit.SetJSON(p.prof, edit.KV{Path: k, Value: desktopSealHere(t, k, "sk-someone-elses")})
|
||||
if c := a.Check(); !strings.Contains(c, "was changed") {
|
||||
t.Errorf("check with another key sealed: %q", c)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user