Repository navigation
Backport(v1.19): in_http: reset the client address for each request (#5650) - #5705
Merged
Merged
Conversation
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
approved these changes
Nov 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue(s) this PR fixes:
Backport #5650
Fixes #5649
What this PR does / why we need it:
in_httpreadX-Forwarded-Forinto@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, andadd_remote_addrrecorded that address.on_headers_completealready resets@env,@content_type,@content_encodingand@authorizationat its start, so the connection address is restored there too.io.remote_addris resolved once per connection, so this adds no lookup. Nothing else changes: a request withX-Forwarded-Forstill 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.rbreports no offenses.Docs Changes:
N/A
Release Note:
in_http: keep the client address per request on a keepalive connection