mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-09-03 14:39:26 +08:00
fix(session): reject edge control characters
This commit is contained in:
@@ -42,15 +42,15 @@ type canonicalPart struct {
|
||||
// NormalizeExplicitID validates an explicit client-provided session identifier.
|
||||
// It preserves opaque printable values while rejecting oversized or control-bearing IDs.
|
||||
func NormalizeExplicitID(raw string) string {
|
||||
raw = strings.TrimSpace(raw)
|
||||
if raw == "" || len(raw) > 256 {
|
||||
return ""
|
||||
}
|
||||
for _, r := range raw {
|
||||
if unicode.IsControl(r) {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
raw = strings.TrimSpace(raw)
|
||||
if raw == "" || len(raw) > 256 {
|
||||
return ""
|
||||
}
|
||||
return raw
|
||||
}
|
||||
|
||||
|
||||
@@ -244,6 +244,14 @@ func TestEnrichDerivesAfterInvalidSessionIdentity(t *testing.T) {
|
||||
name: "oversized prompt cache key",
|
||||
payload: []byte(`{"prompt_cache_key":"` + strings.Repeat("x", 257) + `",` + baseMessages + `}`),
|
||||
},
|
||||
{
|
||||
name: "trailing control character prompt cache key",
|
||||
payload: []byte(`{"prompt_cache_key":"tenant\n",` + baseMessages + `}`),
|
||||
},
|
||||
{
|
||||
name: "leading control character prompt cache key",
|
||||
payload: []byte(`{"prompt_cache_key":"\ttenant",` + baseMessages + `}`),
|
||||
},
|
||||
{
|
||||
name: "control character session header",
|
||||
payload: []byte(`{` + baseMessages + `}`),
|
||||
|
||||
Reference in New Issue
Block a user