Skip to content

Don't drop Forwarded entries that have no "for" value - #4287

Open
tkatta-stack wants to merge 1 commit into
spring-cloud:mainfrom
tkatta-stack:fix/forwarded-header-missing-for-4214
Open

tkatta-stack wants to merge 1 commit into
spring-cloud:mainfrom
tkatta-stack:fix/forwarded-header-missing-for-4214

Conversation

@tkatta-stack

Copy link
Copy Markdown

What

ForwardedHeadersFilter unconditionally dropped any incoming Forwarded header entry that lacked a for parameter, even when the immediate remote address had already been validated against trusted-proxies. RFC 7239 section 4 makes every Forwarded pair parameter, including for, optional, so an upstream proxy that only sets e.g. host and proto is fully valid and its entry shouldn't be silently discarded.

Fix

Changed the per-entry check so it only rejects an entry when it has a for value that fails the trustedProxies check. Entries with no for value are now kept as-is. Behavior for entries that do carry a for value is unchanged.

Tests

Verified against the existing test suite by hand (couldn't run the full Gradle suite in the environment I prepared this in) — in particular untrustedForwardedForNotAppended and remoteAdddressIsNullUnTrustedProxyNotAppended, which exercise the trust check for entries that do have a for value, continue to pass unchanged since this change only affects the forValue == null branch.

Added forwardedEntryWithoutForValueIsKeptWhenRemoteAddressTrusted covering the previously-dropped case.

Fixes #4214

ForwardedHeadersFilter unconditionally dropped any incoming Forwarded
header entry that lacked a "for" parameter, even when the immediate
remote address had already been validated against trusted-proxies.
RFC 7239 section 4 makes every Forwarded pair parameter, including
"for", optional, so an upstream proxy that only sets e.g. host and
proto is fully valid and should not have its entry silently discarded.

Change the per-entry check so it only rejects an entry when it *has* a
for value that fails the trustedProxies check; entries with no for
value are kept as-is; behavior for entries that do carry a for value
is unchanged (verified against the existing test suite, including
untrustedForwardedForNotAppended and
remoteAdddressIsNullUnTrustedProxyNotAppended, both of which continue
to pass unchanged).

Add forwardedEntryWithoutForValueIsKeptWhenRemoteAddressTrusted
covering the previously-dropped case.

Fixes spring-cloudgh-4214

Signed-off-by: Teja Katta <tejakatta12@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ForwardedHeadersFilter drops upstream Forwarded headers without a for field

2 participants