Skip to content

Backport(v1.19): in_http: reset the client address for each request (#5650) - #5705

Merged
Watson1978 merged 1 commit into
v1.19from
backport-to-v1.19/pr5650
Nov 30, 2026
Merged

Watson1978 merged 1 commit into
v1.19from
backport-to-v1.19/pr5650

Conversation

@github-actions

Copy link
Copy Markdown

Which issue(s) this PR fixes:
Backport #5650
Fixes #5649

What this PR does / why we need it:

in_http read X-Forwarded-For into @remote_addr, the same variable that holds the address of the connection (lib/fluent/plugin/in_http.rb:470). Once a request sent the header, a later request on that keepalive connection without the header reused the most recent forwarded address, and add_remote_addr recorded that address.

on_headers_complete already resets @env, @content_type, @content_encoding and @authorization at its start, so the connection address is restored there too. io.remote_addr is resolved once per connection, so this adds no lookup. Nothing else changes: a request with X-Forwarded-For still overrides the address, and the authentication warning keeps logging whichever address applies to the request.

Verified: bundle exec ruby -Ilib -Itest test/plugin/test_in_http.rb -n /remote_addr_is_not_carried/ fails on master with <"127.0.0.1">(UTF-8) expected but was <"192.0.2.1">(ASCII-8BIT) and passes with the change; the whole file passes 66 tests, 238 assertions, 0 failures. rubocop lib/fluent/plugin/in_http.rb test/plugin/test_in_http.rb reports no offenses.

Docs Changes:
N/A

Release Note:
in_http: keep the client address per request on a keepalive connection

Handler#on_headers_complete wrote the X-Forwarded-For address into
@remote_addr, which holds the address of the connection. A later request
on the same keepalive connection that did not send the header was then
recorded with the forwarded address of the earlier request.

Restore @remote_addr from the connection at the start of each request,
together with @env, @content_type, @content_encoding and @authorization.
A request with X-Forwarded-For still overrides the address.

Fixes #5649

Signed-off-by: Raed <Raed2180416@users.noreply.github.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
@Watson1978
Watson1978 merged commit de988a8 into v1.19 Nov 30, 2026
21 checks passed
@Watson1978
Watson1978 deleted the backport-to-v1.19/pr5650 branch November 30, 2026 07:13
@Watson1978 Watson1978 added the bug Something isn't working label Nov 30, 2026
@Watson1978 Watson1978 added this to the v1.19.5 milestone Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants