Skip to content

router: fix crash in addDownstreamSetCookie when no downstream connection - #45984

Merged
yanavlasov merged 8 commits into
envoyproxy:mainfrom
omkhar:fix/router-cookie-hash-async-null-deref
Nov 3, 2026
Merged

yanavlasov merged 8 commits into
envoyproxy:mainfrom
omkhar:fix/router-cookie-hash-async-null-deref

Conversation

@omkhar

@omkhar omkhar commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Commit Message:
router: fix crash in addDownstreamSetCookie when no downstream connection

Filter::addDownstreamSetCookie() unconditionally dereferences
downstreamConnection() to compose the per-connection seed for the
generated cookie value. When the router is invoked without a downstream
connection (e.g. Http::AsyncClient-driven paths such as ext_authz or
ratelimit side calls, mirror/shadow, and health checks) the connection
pointer is null and the worker process crashes whenever a cookie hash
policy is configured.

Skip the connection-derived seed and return an empty cookie value for
those callers. The resulting cookie hashes identically across all async
invocations, which preserves hash-stability for the cookie hash policy on
this path.

Additional Description:

Supersedes #45134, which was auto-closed as stale; this PR carries the same
one-line router fix plus the regression test requested in review there
(GitHub does not permit reopening #45134 once its head branch advanced).
The TODO in router.h had already flagged the risk ("Need to check for
null conn if this is ever used by Http::AsyncClient in the future").

Reported privately via GHSA-47qr-fw7j-6m57; the envoy security team asked
for this to be fixed in the open as a non-security bug because the
misconfiguration would surface in basic functional testing.

Fixes #45133.

Risk Level: Low.
Defensive null check; no behavior change for the existing (downstream-
connection-present) path. Affected async-router paths previously crashed
and now degrade to an empty cookie value, which is a strict improvement.

Testing: Added RouterTest.AddCookieNullDownstreamConnection, which
drives a request through a cookie hash policy with no downstream connection
and asserts the worker does not crash and a stable empty cookie is produced
(no Set-Cookie header emitted). Verified locally with
bazel test //test/common/router:router_test.

Docs Changes: None.

Release Notes: Added under changelogs/current/bug_fixes/ (area: router).

Platform Specific Features: None.

Omkhar Arasaratnam and others added 6 commits May 18, 2026 17:50
…tion

Filter::addDownstreamSetCookie() dereferences downstreamConnection()
unconditionally to compose the per-connection seed for the generated
cookie value. When the router is invoked without a downstream
connection (Http::AsyncClient-driven paths: ext_authz / ratelimit
side calls, mirror/shadow, and health checks) the connection pointer
is null and the worker process segfaults whenever a cookie hash
policy is configured.

Skip the connection-derived seed and return an empty cookie value
for those callers. The resulting cookie hashes identically across
all async invocations, which preserves hash-stability for the
cookie hash policy on this path.

Reported privately via GHSA-47qr-fw7j-6m57; envoy security team
asked for this to be fixed in the open as a non-security bug
because the misconfiguration would surface in basic functional
testing (the affected configuration does not appear in production
deployments that exercise the async-router paths).

Signed-off-by: Omkhar Arasaratnam <[email protected]>
Replace 'segfault' with 'crash' in the bug_fixes entry from the
previous commit; envoy's pedantic spell check does not recognize
'segfault'.

Signed-off-by: Omkhar Arasaratnam <[email protected]>
Per @phlax's review feedback (envoyproxy#45134 review comment on
changelogs/current.yaml:54): the bug_fix entry moves out of the legacy
current.yaml (which is now mostly defunct after envoyproxy#45093) and into a
per-file RST under changelogs/current/bug_fixes/ matching the new
layout described in envoyproxy#45095.

Signed-off-by: Omkhar Arasaratnam <[email protected]>
envoy's tools/spelling/check_spelling_pedantic.py dictionary has
'dereference', 'dereferences', 'dereferencing' but not the past-tense
'dereferenced'. Reword to past-conditional ('would unconditionally
dereference') in both the source comment and the matching changelog
RST. No behavior change.

Signed-off-by: Omkhar Arasaratnam <[email protected]>
…m connection

Adds RouterTest.AddCookieNullDownstreamConnection, which exercises the
Http::AsyncClient-driven router path (ext_authz / ratelimit side calls,
mirror/shadow) where downstreamConnection() is null and a cookie hash
policy is configured.

Because the router under test (RouterTestFilter) hard-overrides
downstreamConnection() to return a non-null member, the test adds a
test-only knob, downstream_connection_is_null_, to RouterTestFilter that
makes that override return nullptr. The test sets the knob, drives a
request through the cookie hash policy, and asserts the worker does not
crash and the generated cookie degrades to a stable empty value (no
Set-Cookie header emitted).

Pre-fix this path unconditionally dereferenced the null downstream
connection and crashed the worker; the test reproduces that crash and
verifies the fix in commit "router: fix crash in addDownstreamSetCookie
when no downstream connection".

Requested by @mattklein123 on envoyproxy#45134.

Signed-off-by: Omkhar Arasaratnam <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@omkhar

omkhar commented Jul 5, 2026

Copy link
Copy Markdown
Contributor Author

CI note: the tsan failure is unrelated to this change — two known-flaky integration tests: //test/extensions/filters/http/ext_proc:ext_proc_integration_test (failed 1 of 8 shards) and //test/extensions/filters/network/ext_proc:ext_proc_integration_test. This PR only adds a single router unit test plus a test-only fixture flag; //test/common/router:router_test (including the new RouterTest.AddCookieNullDownstreamConnection) passes both locally and in CI. A tsan re-run should clear it — I don't have permission to retrigger CI myself.

@RyanTheOptimist

Copy link
Copy Markdown
Contributor

/assign @tyxia

@agrawroh

Copy link
Copy Markdown
Member

@tyxia Gentle ping on this for a review.

@tyxia tyxia left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for delay on the review I missed it. The fix itself looks straightforward, but i am wondering should we investigate further why and when do we have a null downstream connection

std::string value;
const Network::Connection* conn = downstreamConnection();
// Need to check for null conn if this is ever used by Http::AsyncClient in the future.
// Async-client-driven router invocations (ext_authz, ratelimit side calls,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yanavlasov You mentioned that you have a pending fix to async client lifetime issue in general.

Could you take a look if this issue/fix can be part of it?

@phlax

phlax commented Aug 17, 2026

Copy link
Copy Markdown
Member

@tyxia @yanavlasov i think this is waiting on your direction

@phlax

phlax commented Aug 21, 2026

Copy link
Copy Markdown
Member

ping @yanavlasov

1 similar comment
@mathetake

Copy link
Copy Markdown
Member

ping @yanavlasov

@ravenblackx

Copy link
Copy Markdown
Contributor

/retest

And ping @yanavlasov again (now with bonus back-channel ping)

@yanavlasov
yanavlasov enabled auto-merge (squash) September 7, 2026 19:04
@yanavlasov

Copy link
Copy Markdown
Contributor

/retest

1 similar comment
@nezdolik

Copy link
Copy Markdown
Member

/retest

@nezdolik

Copy link
Copy Markdown
Member

@omkhar please merge main, that should fix ci

@nezdolik

Copy link
Copy Markdown
Member

/wait

@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@github-actions github-actions Bot added the stale stalebot believes this issue/PR has not been touched recently label Oct 23, 2026
…ash-async-null-deref

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@github-actions github-actions Bot removed the stale stalebot believes this issue/PR has not been touched recently label Oct 26, 2026
@omkhar

omkhar commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @nezdolik, and sorry for the slow turnaround on this. I've merged main and everything passes except tsan, which failed only on //test/extensions/filters/network/ext_proc:ext_proc_integration_test. That's the same flaky ext_proc test from before and unrelated to this router change. Could someone kick off a /retest? Thanks!

@omkhar

omkhar commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

/retest

@yanavlasov
yanavlasov merged commit 4edefad into envoyproxy:main Nov 3, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

router: addDownstreamSetCookie() null-derefs when invoked without downstream connection (cookie hash policy on async-router paths)

9 participants