0x0_air on X (10-28): with masking on, the agent stopped and asked again.
Their EVM address (0x89dfBD9b…, public) went as a secret placeholder and
the vendor's model told them to rotate it in case it was a private key;
the server IP they typed went as {{IP_…}} and the model refused to ssh
to it and asked for the real host.
- model.go: the local model's SECRET/ACCOUNT span on 0x and 40 hex
digits (evmRe) is left as written; no rule matched it, the model's
label did (the 0x prefix and mixed case got past hexRe). A 64-hex
private key is masked still, and so is a 40-hex value called a key
(secretCued).
- shape.go: an IP the IP rule masks goes as an address from the
documentation ranges (192.0.2/198.51.100/203.0.113 .101-.254, IPv6
2001:db8::/32), stable for the value, never shared by two values
(falls back to {{IP_…}} past 462 IPv4 ones), and put back only as a
whole address in replies and streamed tool calls (restoreAddr).
Preview shows the same stand-in.
- docs: gateway-routing.md, and masking.html in en/zh/ja.
Run:
- Real models through the local gateway, the screenshot's ssh prompt
with the placeholder vs a documentation address: with
{{IP_k3v9x2mq}}, deepseek-v4-pro, glm-5.3, kimi-k3 and
claude-sonnet-5-5 mostly searched ~/.ssh or asked for the real IP;
with 203.0.113.147 or 192.0.2.183 all 20 runs over 5 models ran ssh
at once.
- New tests (internal/redact/standin_ip_test.go): the screenshot's
message, the tool call restored whole and streamed cut at every byte,
boundary cases, IPv6, 472 addresses never sharing, the screenshot's
address under labels secret and account_number with every category
on, and a 64-hex key still masked. gateway TestRedactedKinds now
wants a documentation address upstream.
- Broken by hand: without the evmRe check TestEVMAddressGoesAsWritten
is red for every text and label; without restoreAddr the boundary
cases are red; without the IP stand-in all three IP tests and
gateway TestRedactedKinds are red.
- On mote at this head (rebased on 27bf14790): gofmt -l, go vet
./... for darwin, linux (-tags nogui) and windows, go test -count=1 -timeout 45m
-tags nogui ./... (and go build for
darwin, linux -tags nogui and windows): every package ok, exit 0.
The run before at 56602426d had TestMoreKinds red, which wanted
{{IP_…}}; it now wants the documentation address.
- Rebased again on 56d26f0bb (two gateway commits, #4004): go vet
and go test -tags nogui of internal/redact, internal/gateway and
internal/maskrec on mote at this head: ok.
Not tried:
- the real AstrLink model on an EVM address (the fake model gives it
the labels it can give);
- a host name (user@host) still goes as {{HOSTNAME_…}};
- a documentation address the user writes themselves can match a
stand-in in a reply and be put back as the real one;
- stand-ins are not kept across a restart or once their slot is
evicted, like every placeholder.
69 lines
2.9 KiB
Go
69 lines
2.9 KiB
Go
package gateway
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"regexp"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/provider"
|
|
"github.com/yetone/magpie/internal/settings"
|
|
)
|
|
|
|
// docIP is an IPv4 stand-in: an address in RFC 5737's ranges, .101 to .254
|
|
var docIP = regexp.MustCompile(`(?:192\.0\.2|198\.51\.100|203\.0\.113)\.(?:1\d\d|2[0-4]\d|25[0-4])`)
|
|
|
|
// The kinds of personal data the user turned on or off in settings
|
|
// (redactKinds) are what the vendor doesn't see, the others as their
|
|
// defaults say; what it answers with a placeholder comes back as the value.
|
|
func TestRedactedKinds(t *testing.T) {
|
|
const ssn, ip, bucket, user = "536-22-1847", "34.117.59.81", "acme-prod-logs", "rinakato"
|
|
var got []byte
|
|
up := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
got, _ = io.ReadAll(r.Body)
|
|
p := docIP.FindString(string(got))
|
|
chunk := func(s string) string {
|
|
b, _ := json.Marshal(map[string]any{"id": "c1", "model": "m1", "choices": []any{map[string]any{"index": 0, "delta": map[string]any{"content": s}}}})
|
|
return "data: " + string(b)
|
|
}
|
|
w.Header().Set("Content-Type", "text/event-stream")
|
|
io.WriteString(w, sse(chunk("ping "+p), `data: {"id":"c1","model":"m1","choices":[{"index":0,"delta":{},"finish_reason":"stop"}],"usage":{"prompt_tokens":3,"completion_tokens":2}}`, "data: [DONE]"))
|
|
}))
|
|
defer up.Close()
|
|
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
|
t.Setenv("XDG_CACHE_HOME", t.TempDir())
|
|
if err := provider.Save(provider.Provider{ID: "fake", Name: "Fake", Key: "k", Models: []string{"m1"}, Chat: up.URL + "/v1"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := settings.Save(settings.Settings{Redact: true, RedactPersonal: true, RedactKinds: map[string]bool{"ip": true}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
req := `{"model":"fake/m1","max_tokens":10,"stream":true,"messages":[{"role":"user","content":"SSN ` + ssn + `, server ` + ip + `, logs in s3://` + bucket + `/x, cwd /Users/` + user + `/src"}]}`
|
|
code, body := post(t, "/v1/messages", req)
|
|
if code != 200 {
|
|
t.Fatalf("%d %s", code, body)
|
|
}
|
|
sent := string(got)
|
|
// an address goes as one from the documentation ranges, not a
|
|
// placeholder, so the model uses it rather than asking for the real one
|
|
if strings.Contains(sent, ssn) || strings.Contains(sent, ip) || !strings.Contains(sent, "{{SSN_") || !docIP.MatchString(sent) || strings.Contains(sent, "{{IP_") {
|
|
t.Fatalf("SSN (on by default) or IP (turned on) went out: %s", sent)
|
|
}
|
|
if !strings.Contains(sent, "s3://"+bucket+"/x") || !strings.Contains(sent, "/Users/"+user+"/src") {
|
|
t.Fatalf("a bucket or a home folder (off by default) masked: %s", sent)
|
|
}
|
|
var text strings.Builder
|
|
for _, e := range events(body) {
|
|
if d, ok := e["delta"].(map[string]any); ok {
|
|
s, _ := d["text"].(string)
|
|
text.WriteString(s)
|
|
}
|
|
}
|
|
if text.String() != "ping "+ip {
|
|
t.Fatalf("text %q in:\n%s", text.String(), body)
|
|
}
|
|
}
|