Skip to content

in_http: reset the client address for each request - #5650

Open
Raed2180416 wants to merge 1 commit into
fluent:masterfrom
Raed2180416:in-http-remote-addr-per-request
Open

Raed2180416 wants to merge 1 commit into
fluent:masterfrom
Raed2180416:in-http-remote-addr-per-request

Conversation

@Raed2180416

@Raed2180416 Raed2180416 commented Nov 17, 2026 •

Copy link
Copy Markdown

Which issue(s) this PR fixes:
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, so a later request
on the same keepalive connection that did not send the header was attributed
to the client of the earlier one.

Signed-off-by: Raed <Raed2180416@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 17, 2026 22:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@Raed2180416
Raed2180416 force-pushed the in-http-remote-addr-per-request branch from 72c2152 to 792051e Compare November 18, 2026 09:06

@Watson1978 Watson1978 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the fix. I reproduced #5649 on master, and the new test fails there and passes with this change.

I also tried TLS, pipelined requests, HTTP/1.0 keep-alive, and Expect: 100-continue. A request without X-Forwarded-For now gets the connection address, and a request with the header still uses the header value. When a later request failed authentication, the warning logged the connection address.

@Watson1978 Watson1978 added bug Something isn't working backport to v1.19 We will backport this fix to the LTS branch labels Nov 18, 2026
@Watson1978 Watson1978 added this to the v1.21.0 milestone Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport to v1.19 We will backport this fix to the LTS branch bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

in_http: a request without X-Forwarded-For keeps the address of an earlier request on the same keepalive connection

3 participants