Overview
When proxying client requests to upstream HTTP/1.1 backend services, the Tyk Gateway may abort upstream connections and return HTTP 500 Internal Server Error or 502 Bad Gateway responses to the client.
Symptom & Error Message
The following error appears in the Tyk Gateway error logs:
http: Transport: connection broken: too many transfer encodingsThe upstream HTTP request fails immediately and the calling client receives an HTTP 500 or 502 status response from Tyk Gateway.
Root Cause
Under the HTTP/1.1 specification (RFC 7230 / RFC 9112), a request or response message MUST NOT contain multiple or conflicting Transfer-Encoding headers. In HTTP/1.1, multiple chunked directives or a malformed combination of chunked encodings introduce HTTP request smuggling vulnerabilities.
The Go standard library net/http reverse proxy transport strictly enforces this RFC requirement. When an upstream web server, reverse proxy, or application framework inadvertently emits duplicate Transfer-Encoding: chunked headers (or injects a manual Transfer-Encoding header on an already-chunked payload stream), the Go HTTP transport terminates the TCP connection abruptly to safeguard against smuggling desynchronization.
Resolution Steps
Inspect Upstream Response Headers: Bypass Tyk Gateway and execute a direct HTTP request against the upstream backend endpoint using
curl -vto inspect raw headers:curl -v -N -H "Host: api.internal" https://upstream-backend.internal/api/resourceCheck if the response contains multiple
Transfer-Encodingheader lines.- Remediate Upstream Web Server / Ingress Configuration: If the backend runs behind an upstream reverse proxy (such as NGINX, Apache, or an Ingress controller), ensure the proxy does not re-add chunked encoding when passing traffic from the application. In NGINX, ensure
proxy_set_header Transfer-Encoding "";or remove manual chunked headers from backend code. - Configure Header Stripping in Tyk: If the backend cannot be modified immediately, configure Tyk response header transformation middleware to strip redundant response headers before forwarding to downstream clients.
Applies To
Tyk Gateway v5.0+ and all upstream HTTP/1.1 services.
Comments
0 comments
Please sign in to leave a comment.