diff --git a/CHANGELOG.md b/CHANGELOG.md index e8bfd37..736c242 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,6 +53,7 @@ All notable changes to this project are documented in this file. The format is b - **Asset service links**: the Services tab only uses an asset URL as `href` when it is `http:` or `https:`. `javascript:`, `data:`, and other schemes render as text. - **Chat session directories**: `ChatAgent.Chat` accepts only `[A-Za-z0-9_-]` session ids (at most 64 bytes) before joining them under `/sessions`, so `..` and path separators cannot escape that directory. - **Change-password rate limit**: `POST /api/auth/change-password` uses the same limiter as login, keyed by client IP and by the session token, so a stolen session cannot guess the current password without backoff. +- **Ingested traffic headers**: `RecordExternal` rejects a method that is not an HTTP token and header names or values that contain CR, LF, or NUL, matching Replay, so ingested exchanges cannot inject extra header lines into stored evidence. - **ask_operator image_path**: the screenshot path must resolve inside the task working directory (`/tasks/`). Absolute paths, `..` segments, and symlinks that leave that directory are refused, so the tool cannot copy an arbitrary server image into the operator transcript. - **insert_assets fail-closed**: when intercept or task allow/block rules cannot be loaded, `insert_assets` refuses the whole call instead of evaluating an empty rule set (which allowed every asset). The tool result does not include the underlying database error. - **BlobRange length no longer wraps int64**: `offset+length > size` overflowed when length was near MaxInt64, so the cap was skipped and `make([]byte, length)` could exhaust memory. The bound is now `length > size-offset`. diff --git a/traffic/external.go b/traffic/external.go index 9e849dc..6df2eb5 100644 --- a/traffic/external.go +++ b/traffic/external.go @@ -38,6 +38,15 @@ func (t *Traffic) RecordExternal(e ExternalExchange) error { if method == "" { return fmt.Errorf("empty method for %q", e.URL) } + if !validHeaderName(method) { + return fmt.Errorf("invalid method %q", e.Method) + } + if err := validateExternalHeaders(e.RequestHeaders); err != nil { + return err + } + if err := validateExternalHeaders(e.ResponseHeaders); err != nil { + return err + } status := e.Status if status == 0 { status = 200 @@ -120,6 +129,18 @@ VALUES(?,?,?,?,?,?,?)`, return nil } +func validateExternalHeaders(h map[string]string) error { + for k, v := range h { + if !validHeaderName(k) { + return fmt.Errorf("invalid header name %q", k) + } + if strings.ContainsAny(v, "\r\n\x00") { + return fmt.Errorf("header %s contains a line break", k) + } + } + return nil +} + func toHeaderMap(flat map[string]string) map[string][]string { m := make(map[string][]string, len(flat)) for k, v := range flat { diff --git a/traffic/external_test.go b/traffic/external_test.go index acf62b8..f2d415e 100644 --- a/traffic/external_test.go +++ b/traffic/external_test.go @@ -68,10 +68,18 @@ func TestRecordExternalRejectsBadInput(t *testing.T) { {Method: "GET", URL: "not a url"}, {Method: "GET", URL: ""}, {Method: "", URL: "https://api.example.com/"}, + {Method: "GET\r\nX-Injected: 1", URL: "https://api.example.com/"}, + {Method: "GET", URL: "https://api.example.com/", RequestHeaders: map[string]string{"X-Bad\nName": "1"}}, + {Method: "GET", URL: "https://api.example.com/", RequestHeaders: map[string]string{"x-ok": "one\r\ntwo"}}, + {Method: "GET", URL: "https://api.example.com/", ResponseHeaders: map[string]string{"x-capture": "ok\r\nX-Forged-Header: injected"}}, + {Method: "GET", URL: "https://api.example.com/", ResponseHeaders: map[string]string{"x-nul": "a\x00b"}}, } for i, c := range cases { if err := tr.RecordExternal(c); err == nil { t.Fatalf("case %d: expected an error for %+v", i, c) } } + if n, _ := tr.Count(); n != 0 { + t.Fatalf("rejected exchanges were stored: count=%d", n) + } }