Skip to content

x-envoy-upstream-stream-duration-ms is honoured from external clients (missing from header sanitisation) #48066

Closed

Description

@lboynton

Title: x-envoy-upstream-stream-duration-ms is honoured from external clients

Description:
The router honours the x-envoy-upstream-stream-duration-ms request header even when the request is external. It should be stripped from external requests, like the other router timeout and retry control headers.

ConnectionManagerUtility::cleanInternalHeaders removes those headers from requests that aren't internal (x-envoy-upstream-rq-timeout-ms, x-envoy-upstream-rq-per-try-timeout-ms, x-envoy-max-retries, x-envoy-retry-on, x-envoy-hedge-on-per-try-timeout, …), but not x-envoy-upstream-stream-duration-ms:

// Headers to be stripped from edge *and* intermediate-hop external requests.
// TODO: some of these should only be stripped at edge, i.e. moved into
// the block above.
request_headers.removeEnvoyRetriableStatusCodes();
request_headers.removeEnvoyRetriableHeaderNames();
request_headers.removeEnvoyRetryOn();
request_headers.removeEnvoyRetryGrpcOn();
request_headers.removeEnvoyMaxRetries();
request_headers.removeEnvoyUpstreamAltStatName();
request_headers.removeEnvoyUpstreamRequestTimeoutMs();
request_headers.removeEnvoyUpstreamRequestPerTryTimeoutMs();
request_headers.removeEnvoyUpstreamRequestTimeoutAltResponse();
request_headers.removeEnvoyExpectedRequestTimeoutMs();
request_headers.removeEnvoyForceTrace();
request_headers.removeEnvoyIpTags();
request_headers.removeEnvoyOriginalUrl();
request_headers.removeEnvoyHedgeOnPerTryTimeout();

The router then reads it with no internal-request check:

// Handle additional header processing.
const Http::HeaderEntry* header_max_stream_duration_entry =
headers.EnvoyUpstreamStreamDurationMs();
if (header_max_stream_duration_entry) {
dynamic_max_stream_duration_ =
FilterUtility::tryParseHeaderTimeout(*header_max_stream_duration_entry);
headers.removeEnvoyUpstreamStreamDurationMs();
}

It's also missing from the HTTP header sanitizing list. Unlike several neighbouring headers, its router docs don't say it's only honoured for internal clients. The header was added in #15433 (Envoy 1.20) without a matching sanitisation entry, so this looks like an omission. It's present on every release from v1.20.0 to v1.39.2 and on current main.

The effect is that any external client can set a per-request upstream stream duration and force Envoy to abort the upstream request and send a local reply. For gRPC-typed requests, that local reply is a trailers-only 200 OK with an empty body.

Suggested fix: add request_headers.removeEnvoyUpstreamStreamDurationMs(); to the external-request block of cleanInternalHeaders, add the header to header_sanitizing.rst, and note in the router docs that it's only honoured for internal clients.

Repro steps:
Envoy v1.39.2 (envoyproxy/envoy:v1.39.2) with the config below, in front of any HTTP/1.1 upstream that takes more than ~1 ms to respond. The results are identical with use_remote_address: false.

  1. Baseline: the request is proxied normally.
    curl -si http://localhost:10000/app.js | head -1
    # HTTP/1.1 200 OK
  2. With the header, Envoy aborts the upstream request after 1 ms:
    curl -si -H 'x-envoy-upstream-stream-duration-ms: 1' http://localhost:10000/app.js
    # HTTP/1.1 504 Gateway Timeout
    # upstream max stream duration reached

Config:

static_resources:
  listeners:
  - name: edge
    address:
      socket_address: { address: 0.0.0.0, port_value: 10000 }
    filter_chains:
    - filters:
      - name: envoy.filters.network.http_connection_manager
        typed_config:
          "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
          stat_prefix: edge
          use_remote_address: true
          route_config:
            virtual_hosts:
            - name: app
              domains: ["*"]
              routes:
              - match: { prefix: "/" }
                route: { cluster: origin }
          http_filters:
          - name: envoy.filters.http.router
            typed_config:
              "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
  clusters:
  - name: origin
    type: STRICT_DNS
    load_assignment:
      cluster_name: origin
      endpoints:
      - lb_endpoints:
        - endpoint:
            address:
              socket_address: { address: origin, port_value: 8080 }

Activity

  1. added
    triage
    on Oct 6, 2026
  2. added a commit that references this issue on Oct 7, 2026
    b820508
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugtriage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions