Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logging of real remote IP - in case of proxies #138

Merged
merged 4 commits into from
Sep 15, 2022

Conversation

dlvoy
Copy link
Contributor

@dlvoy dlvoy commented Sep 14, 2022

Extends logging to capture X-Forwarded-For header (in case of proxies)

Description

When server is used behind reverse proxy, reported remote_addr reflects internal interface and port, not client external IP. This PR adds additional real_remote_ip that is filled with contents of X-Forwarded-For

Motivation and Context

Main motivation is enable logs to be used with web statistics tools (like AWStats) that require IP addresses to be present in log files

How Has This Been Tested?

Tested by providing (or not) X-Forwarded-For header with Postman

Copy link
Collaborator

@joseluisq joseluisq left a comment

Choose a reason for hiding this comment

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

Could you just provide some log output of how this looks like?

And please add a short description about this feature on https://sws.joseluisq.net/features/logging/ and under some new Log Real Remote IP subtitle. See logging.md page for more details.

src/handler.rs Outdated Show resolved Hide resolved
@joseluisq joseluisq added enhancement New feature or request v2 v2 release labels Sep 14, 2022
dlvoy and others added 2 commits September 14, 2022 23:22
Co-authored-by: Jose Quintana <1700322+joseluisq@users.noreply.github.com>
@dlvoy
Copy link
Contributor Author

dlvoy commented Sep 14, 2022

I've added documentation and added parsing of header - while creating documentation i found articles regarding log poisoning and simply appending contents of header would pose security risk - so current implementation requires header to contain valid, parsable IP

sample call and log to test it:

curl --header "X-Forwarded-For: 203.0.113.195, 2001:db8:85a3:8d3:1319:8a2e:370:7348" http://0.0.0.0:8080
2022-05-23T22:24:50.519540Z  INFO static_web_server::handler: incoming request: method=GET uri=/ remote_addr=192.168.1.126:57625 real_remote_ip=203.0.113.195

Copy link
Collaborator

@joseluisq joseluisq left a comment

Choose a reason for hiding this comment

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

Ready for the next release. Thanks 👍

@joseluisq joseluisq merged commit 5f10771 into static-web-server:master Sep 15, 2022
@joseluisq
Copy link
Collaborator

Released on v2.12.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request v2 v2 release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants