Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

gateway: a masked value's snip is copied, not cut from the request it kept whole (#2278)

yetone3f87493fc3ef
diff --git a/internal/gateway/masked.go b/internal/gateway/masked.go
index 11afdf00e..c5d741041 100644
--- a/internal/gateway/masked.go
+++ b/internal/gateway/masked.go
@@ -168,7 +168,10 @@ func snipsOf(sent string, hits []gwmw.Hit) map[string]string {
if b < end {
s += "…"
}
- out[x.Placeholder] = s
+ // a value that is a whole string of the body is a snip cut from
+ // it: copied, or the record kept the whole request (up to
+ // SentMax) for as long as memory keeps its snips (#2278)
+ out[x.Placeholder] = strings.Clone(s)
}
return out
}
diff --git a/internal/gateway/masked_test.go b/internal/gateway/masked_test.go
index 70255c982..f4610a782 100644
--- a/internal/gateway/masked_test.go
+++ b/internal/gateway/masked_test.go
@@ -9,6 +9,7 @@ import (
"strconv"
"strings"
"testing"
+ "unsafe"
"github.com/yetone/magpie/internal/gwmw"
"github.com/yetone/magpie/internal/maskrec"
@@ -141,3 +142,20 @@ func TestMaskedBodyCopiedOnlyWhenKept(t *testing.T) {
t.Fatalf("over SentMax: %d bytes allocated", n)
}
}
+
+// A snip is the text around a value, never a window into the request:
+// a value that is a whole JSON string came back as a substring of the
+// body, and a record holding it kept the whole request (#2278).
+func TestSnipsHoldNoneOfTheBody(t *testing.T) {
+ const p = "{{API_KEY_ccccdddd}}"
+ sent := `{"api_key":"` + p + `","input":"` + strings.Repeat("a", 1<<20) + `"}`
+ snips := snipsOf(sent, []gwmw.Hit{{Placeholder: p}})
+ got, ok := snips[p]
+ if !ok || got != p {
+ t.Fatalf("snips: %q", snips)
+ }
+ start := uintptr(unsafe.Pointer(unsafe.StringData(sent)))
+ if at := uintptr(unsafe.Pointer(unsafe.StringData(got))); at >= start && at < start+uintptr(len(sent)) {
+ t.Fatal("the snip is a window into the request body, which it keeps whole")
+ }
+}