bug: Copied listener and parser code has drifted (hop-by-hop response headers, SSE BOM/CR handling)

Chiusa
#1,567 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Refactoring
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go

Direzione di ricerca

Start with the four response-header copy loops in core/listener/forwardproxy/server.go and the SSE parsers in core/plugins/a2aparser/plugin.go and core/plugins/mcpparser/plugin.go; compare them with stripForUpstream and normalizeSSE. Then inspect the listener helpers named in the issue and the shared package locations it proposes. Done means the response filtering, SSE line handling, and helper extraction cover every listed call site.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

Problem

The listeners and protocol parsers have copied code that has drifted apart. One listener or parser got a fix that its copies did not. Line numbers are at ab5f01f26.

1. Hop-by-hop response headers reach the client

Hop-by-hop headers (like Keep-Alive) describe one connection and must not be forwarded. The forward proxy has four near-identical loops that copy resp.Header to the client verbatim: core/listener/forwardproxy/server.go:827-831, 1918-1922, 2020-2024, 2130-2134. Requests are stripped (stripForUpstream, :1358-1369), but responses are not. The comment at :1917 says "clear hop-by-hop headers as net/http would", and no code does.

  • Case: a client negotiates h2 with the TLS bridge, and the HTTP/1.1 origin sends Keep-Alive: timeout=5. The header goes out in an HTTP/2 HEADERS frame, because Go's h2 server strips only Connection.
  • Reproduced locally: Node 24 http2 fails with ERR_HTTP2_STREAM_ERROR when the header is present and succeeds without it.
  • The reverse proxy is not affected, because httputil.ReverseProxy strips these headers.

Fix: one copyResponseHeader(w, resp) that skips the list stripForUpstream uses, plus any header named in Connection. Use it at all four sites.

2. Only one SSE parser handles a BOM or CR-only line endings

SSE (server-sent events) is the streaming format the parsers read. The buffered-response data: scanners are:

  • core/plugins/inferenceparser: anthropic.go:502, responses.go:566, plugin.go:779. These call normalizeSSE (plugin.go:627).
  • core/plugins/a2aparser/plugin.go:324, 402 and core/plugins/mcpparser/plugin.go:478. These split on \n only.

Case: an MCP or A2A response that starts with a UTF-8 BOM (byte-order mark), or uses CR-only line endings, matches no data: line. TrimSpace does not strip U+FEFF, and a CR-only body is one line. The MCP/A2A extension stays empty, and IBAC treats the request as unclassified, which passes by default (ibac/plugin.go:389-399). normalizeSSE's own comment (plugin.go:613-619) describes this exact failure.

The streaming path is fine, because sseframe.Reader handles both cases.

Fix: move normalizeSSE (or a shared ForEachDataLine) into core/plugins/internal/parsercommon and use it at all six sites.

3. Request helpers copied between listeners
  • isEventStream is defined three times: forwardproxy/server.go:1830, reverseproxy/server.go:1047, extproc/server.go:1420.
  • reverseproxy/server.go:406-412 and :419-440 inline copies of forwardproxy's setBody (:1401) and syncHeaders (:1331).

They match today, but this is where the next one-sided fix will land, as problem 1 already shows.

Fix: move them into core/listener/httpx.

Found by a code audit of main at ab5f01f26.

Assisted-By: Claude (Anthropic AI) [email protected]

Lingua principale
Go
Stelle
21
Fork
43
Merge medio
13h 32m
PR unite (30g)
256

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di rossoctl/cortex

Tutte le issue di rossoctl/cortex

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.