Skip to content

fix(mp-rest-client): do not auto-propagate InboundHeadersProvider headers - #6117

Open
arimu1 wants to merge 1 commit into
eclipse-ee4j:4.xfrom
arimu1:fix/6101-inbound-headers-leak
Open

fix(mp-rest-client): do not auto-propagate InboundHeadersProvider headers#6117
arimu1 wants to merge 1 commit into
eclipse-ee4j:4.xfrom
arimu1:fix/6101-inbound-headers-leak

Conversation

@arimu1

@arimu1 arimu1 commented Aug 8, 2026

Copy link
Copy Markdown

Summary

Fixes nondeterministic leakage of application InboundHeadersProvider headers into outbound MicroProfile Rest Client requests (even when no ClientHeadersFactory is registered).

Root cause

  • DefaultInboundHeaderProvider and application InboundHeadersProvider instances were stored in a plain HashSet (unordered).
  • MethodModel.resolveCustomHeaders() accumulates every provider's inboundHeaders() into one map.
  • When DefaultInboundHeaderProvider is visited, its ClientHeadersFactory.update() copied that entire accumulated map into outbound headers.

So if an application provider was iterated before the default provider, inbound-only headers (e.g. Authorization, Cookie) were sent to the remote target. Order depended on HashSet iteration / hash bucket layout, so different client instances in the same JVM could differ.

Fix

  1. Use LinkedHashSet for inbound header providers in RestClientBuilderImpl and RestClientContext.Builder so DefaultInboundHeaderProvider (registered first) stays first.
  2. Harden DefaultInboundHeaderProvider.update() to only apply RestClientBuilder.header(...) values, never headers from other InboundHeadersProviders. Those remain available only to an explicit @RegisterClientHeaders / ClientHeadersFactory.

Testing

mvn -pl tests/integration/microprofile/rest-client -am test \
  -Dtest=InboundHeadersProvider* \
  -Dsurefire.failIfNoSpecifiedTests=false
  • InboundHeadersProviderLeakTest 3/3 (100× no-leak stress, builder header still applied, explicit factory still sees inbound)
  • InboundHeadersProviderTest 2/2
  • Temurin/JBR 17

Related

Fixes #6101

Co-reported / analysis by @Verdent; @OndroMih noted the LinkedHashSet ordering requirement.

Signed-off-by: arimu1 19286898+arimu1@users.noreply.github.com

…ders

DefaultInboundHeaderProvider and application InboundHeadersProviders were
stored in a HashSet, so iteration order was nondeterministic. When an
application provider ran before DefaultInboundHeaderProvider, its headers
were accumulated into inbound and then DefaultInboundHeaderProvider.update()
copied that entire map into the outbound request — even with no
ClientHeadersFactory.

- Use LinkedHashSet so DefaultInboundHeaderProvider stays first
- update() only applies RestClientBuilder.header(...) values, not other
  providers' inbound headers
- Regression tests for eclipse-ee4j#6101

Fixes eclipse-ee4j#6101

Signed-off-by: arimu1 <19286898+arimu1@users.noreply.github.com>
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.

jersey-mp-rest-client 3.1.11 nondeterministically copies inbound provider headers into outbound requests

1 participant