Brief description
The api_key_auth HTTP filter (envoy.filters.http.api_key_auth) dereferences the :path pseudo-header without a null check when stripping a query key source from the request. A classic HTTP CONNECT request legitimately carries no :path, and Envoy explicitly permits that. A client holding a valid API key can crash the Envoy process with a single request when the filter is configured with forwarding.hide_credentials: true and a query key source alongside another key source.
Affected component
envoy.filters.http.api_key_auth — security_posture: robust_to_untrusted_downstream, status: alpha.
- Sink:
KeySources::Source::removeKey in source/extensions/filters/http/api_key_auth/api_key_auth.cc, reached from the unconditional loop in KeySources::removeKey.
Attack vector
A client holding a valid API key sends a path-less CONNECT with the key in a header-backed key source, against a filter configured with at least two key sources (one of them query) and forwarding.hide_credentials: true. Authentication succeeds, credential stripping then walks every configured source, and the query source dereferences the absent :path.
Envoy runs all workers in a single process, so the crash drops every connection the instance was serving and can be replayed indefinitely.
Example exploit or proof-of-concept
- name: envoy.filters.http.api_key_auth
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.api_key_auth.v3.ApiKeyAuth
key_sources:
- header: "x-api-key"
- query: "api_key"
forwarding:
hide_credentials: true
credentials:
- key: "supersecret"
client: "acme"
with an ordinary route table (match: { prefix: "/" }, no connect_matcher). Trigger, with a valid key:
printf 'CONNECT anything:443 HTTP/1.1\r\nHost: anything:443\r\nx-api-key: supersecret\r\n\r\n' \
| nc <envoy-host> 10000
Result: SIGSEGV in KeySources::Source::removeKey.
Details
Why :path can be absent
HeaderUtility::checkRequiredRequestHeaders requires :path only in the non-CONNECT branch; for CONNECT it requires only Host. The HTTP/1 server codec does not set :path for an authority-form CONNECT target, and an HTTP/2 CONNECT with :authority and no :path/:scheme/:protocol reaches the same state.
Why the filter chain runs at all
The connection manager's "route does not permit upgrades" 403 is only evaluated when a route has matched. For a path-less request no route matches unless a connect_matcher route is configured, because RouteMatcher::route skips every candidate whose supportsPathlessHeaders() is false and only ConnectRouteEntryImpl overrides that to true. So under any ordinary prefix/path/safe_regex route table the request falls through directly to the filter chain. Omitting CONNECT support from the route table is the vulnerable configuration, not a mitigation.
The defect
KeySources::removeKey iterates every configured source, regardless of which one actually produced the validated key:
void KeySources::removeKey(Http::RequestHeaderMap& headers) const {
for (const auto& source : key_sources_) {
source.removeKey(headers);
}
}
and the query branch of KeySources::Source::removeKey ends with:
headers.setPath(params.replaceQueryString(headers.Path()->value())); // null deref
The lookup path is already null-safe — KeySources::Source::getKey reads the path through headers.getPathValue(), which returns an empty view when :path is absent. Only the removal path dereferences the pointer. That asymmetry is why the bug survives normal testing: the query source correctly finds nothing, a header source supplies the key, authentication succeeds, and the crash happens afterwards during credential stripping.
Fix
The query branch of KeySources::Source::removeKey now returns early when :path is absent, so credential stripping skips query-string rewriting for path-less requests. A regression test covering a path-less CONNECT has been added.
Affected versions
All versions since the filter was introduced in 1.33.0.
Fixed versions
1.36.12, 1.37.8, 1.38.6, 1.39.3
Mitigations
Insert an RBAC filter before api_key_auth in http_filters, denying :method: CONNECT:
- name: envoy.filters.http.rbac
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.rbac.v3.RBAC
rules:
action: DENY
policies:
deny-connect:
permissions:
- header: { name: ":method", string_match: { exact: "CONNECT" } }
principals:
- any: true
This is safe on path-less requests: the header matcher reads :method, which is always present, and RBAC's own path matcher explicitly handles a null :path.
Alternatively, either drop the query key source or set forwarding.hide_credentials: false. Either alone prevents the sink from being reached.
Not a mitigation: omitting CONNECT from upgrade_configs. As shown above, that is the vulnerable configuration.
Detection
The process dies while handling the request, so the offending request generally does not reach the access log. Look for:
- Fatal-error backtrace with frames through
Envoy::Extensions::HttpFilters::ApiKeyAuth::KeySources::Source::removeKey.
- Repeated process restarts on listeners running the filter, especially at a steady interval, indicating a replayed request.
- Upstream of the proxy, in CDN or load-balancer logs: authority-form
CONNECT requests with no path, immediately followed by a connection reset.
- On patched builds, an access log format including
%REQ(:METHOD)% and %REQ(:PATH)% will show CONNECT with an empty path reaching these listeners — each such entry would have crashed a vulnerable build.
Credits
threatroute66
References
Brief description
The
api_key_authHTTP filter (envoy.filters.http.api_key_auth) dereferences the:pathpseudo-header without a null check when stripping aquerykey source from the request. A classic HTTPCONNECTrequest legitimately carries no:path, and Envoy explicitly permits that. A client holding a valid API key can crash the Envoy process with a single request when the filter is configured withforwarding.hide_credentials: trueand aquerykey source alongside another key source.Affected component
envoy.filters.http.api_key_auth—security_posture: robust_to_untrusted_downstream,status: alpha.KeySources::Source::removeKeyinsource/extensions/filters/http/api_key_auth/api_key_auth.cc, reached from the unconditional loop inKeySources::removeKey.Attack vector
A client holding a valid API key sends a path-less
CONNECTwith the key in a header-backed key source, against a filter configured with at least two key sources (one of themquery) andforwarding.hide_credentials: true. Authentication succeeds, credential stripping then walks every configured source, and thequerysource dereferences the absent:path.Envoy runs all workers in a single process, so the crash drops every connection the instance was serving and can be replayed indefinitely.
Example exploit or proof-of-concept
with an ordinary route table (
match: { prefix: "/" }, noconnect_matcher). Trigger, with a valid key:Result: SIGSEGV in
KeySources::Source::removeKey.Details
Why
:pathcan be absentHeaderUtility::checkRequiredRequestHeadersrequires:pathonly in the non-CONNECT branch; for CONNECT it requires onlyHost. The HTTP/1 server codec does not set:pathfor an authority-form CONNECT target, and an HTTP/2CONNECTwith:authorityand no:path/:scheme/:protocolreaches the same state.Why the filter chain runs at all
The connection manager's "route does not permit upgrades" 403 is only evaluated when a route has matched. For a path-less request no route matches unless a
connect_matcherroute is configured, becauseRouteMatcher::routeskips every candidate whosesupportsPathlessHeaders()is false and onlyConnectRouteEntryImploverrides that to true. So under any ordinary prefix/path/safe_regex route table the request falls through directly to the filter chain. Omitting CONNECT support from the route table is the vulnerable configuration, not a mitigation.The defect
KeySources::removeKeyiterates every configured source, regardless of which one actually produced the validated key:and the
querybranch ofKeySources::Source::removeKeyends with:The lookup path is already null-safe —
KeySources::Source::getKeyreads the path throughheaders.getPathValue(), which returns an empty view when:pathis absent. Only the removal path dereferences the pointer. That asymmetry is why the bug survives normal testing: the query source correctly finds nothing, a header source supplies the key, authentication succeeds, and the crash happens afterwards during credential stripping.Fix
The
querybranch ofKeySources::Source::removeKeynow returns early when:pathis absent, so credential stripping skips query-string rewriting for path-less requests. A regression test covering a path-lessCONNECThas been added.Affected versions
All versions since the filter was introduced in 1.33.0.
Fixed versions
1.36.12, 1.37.8, 1.38.6, 1.39.3
Mitigations
Insert an RBAC filter before
api_key_authinhttp_filters, denying:method: CONNECT:This is safe on path-less requests: the header matcher reads
:method, which is always present, and RBAC's own path matcher explicitly handles a null:path.Alternatively, either drop the
querykey source or setforwarding.hide_credentials: false. Either alone prevents the sink from being reached.Not a mitigation: omitting CONNECT from
upgrade_configs. As shown above, that is the vulnerable configuration.Detection
The process dies while handling the request, so the offending request generally does not reach the access log. Look for:
Envoy::Extensions::HttpFilters::ApiKeyAuth::KeySources::Source::removeKey.CONNECTrequests with no path, immediately followed by a connection reset.%REQ(:METHOD)%and%REQ(:PATH)%will showCONNECTwith an empty path reaching these listeners — each such entry would have crashed a vulnerable build.Credits
threatroute66
References
ext_authz, same defect class — theext_authzportion of the original report was addressed under that advisory)oauth2, same defect class)d2dbc0539b— "auth: new api auth implementation (#36968)", 2024-12-11