Skip to content

router: fix null-deref in addDownstreamSetCookie when downstream connection is null - #45134

Closed
omkhar wants to merge 4 commits into
envoyproxy:mainfrom
omkhar:fix/router-cookie-hash-async-null-deref
Closed

omkhar wants to merge 4 commits into
envoyproxy:mainfrom
omkhar:fix/router-cookie-hash-async-null-deref

Conversation

@omkhar

@omkhar omkhar commented May 18, 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 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.

Additional Description:

The TODO comment in router.h line 500 had already flagged the risk
("Need to check for null conn if this is ever used by Http::AsyncClient
in the future"); this PR addresses that TODO.

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.

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: Manual review of the affected code path against the
private-fork regression test. Happy to add a focused regression test
in test/common/router/router_test.cc that exercises the null-
connection path if maintainers would like; it adds enough scope that
I kept it out of this initial PR to keep the fix small.

Docs Changes: None required.

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

Platform Specific Features: None.

…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]>
@omkhar
omkhar temporarily deployed to external-contributors May 18, 2026 21:51 — with GitHub Actions Inactive
@repokitteh-read-only

Copy link
Copy Markdown

Hi @omkhar, welcome and thank you for your contribution.

We will try to review your Pull Request as quickly as possible.

In the meantime, please take a look at the contribution guidelines if you have not done so already.

🐱

Caused by: #45134 was opened by omkhar.

see: more, trace.

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]>
@omkhar
omkhar had a problem deploying to external-contributors May 19, 2026 16:17 — with GitHub Actions Error
Comment thread changelogs/current.yaml Outdated

bug_fixes:
# *Changes expected to improve the state of the world and are unlikely to have negative effects*
- area: router

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.

needs to use new changelog layout - see #45095

/wait

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]>
@omkhar

omkhar commented May 23, 2026

Copy link
Copy Markdown
Contributor Author

Addressed @phlax — migrated the bug_fix entry to changelogs/current/bug_fixes/router__fixed-crash-in-adddownstreamsetcookie-when-connection-null.rst per #45095 / #45093, and merged upstream/main to clear the conflict. No code changes since 51eb3a1c; the router fix stands. Ready for re-review when CI clears.

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]>

@mattklein123 mattklein123 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.

This needs a test.

/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 Jun 28, 2026
@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown

This pull request has been automatically closed because it has not had activity in the last 37 days. 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 closed this Jul 5, 2026
omkhar pushed a commit to omkhar/envoy that referenced this pull request Jul 5, 2026
…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]>
yanavlasov pushed a commit that referenced this pull request Nov 3, 2026
…tion (#45984)

**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.

---------

Signed-off-by: Omkhar Arasaratnam <[email protected]>
Co-authored-by: Omkhar Arasaratnam <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale stalebot believes this issue/PR has not been touched recently waiting

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)

3 participants