Skip to content

Allow request IP candidates to contain ports#174

Open
Nextra wants to merge 1 commit intompolden:masterfrom
Nextra:allow-ports
Open

Allow request IP candidates to contain ports#174
Nextra wants to merge 1 commit intompolden:masterfrom
Nextra:allow-ports

Conversation

@Nextra
Copy link

@Nextra Nextra commented Aug 18, 2023

This changes the flow of ipFromRequest to run all remoteIP candidates through net.SplitPortHost (if applicable) regardless of source, instead of treating http.Request.RemoteAddr as the lone special case.

The motivation behind this is that Azure Application Gateways add the X-Forwarded-For header as a comma separated list of IP:port instead of each entry just containing the IP address (ref), making it unnecessarily difficult to deploy echoip as-is to Azure Web App.

{"127.0.0.1:9999", "X-Forwarded-For", "1.3.3.7:1337,4.2.4.2:4242", []string{"X-Forwarded-For"}, "1.3.3.7"}, // X-Forwarded-For with multiple entries (commas separator, with port)
{"127.0.0.1:9999", "X-Forwarded-For", "1.3.3.7:1337, 4.2.4.2:4242", []string{"X-Forwarded-For"}, "1.3.3.7"}, // X-Forwarded-For with multiple entries (space+comma separator, with port)
{"127.0.0.1:9999?ip=1.2.3.4:1234", "", "", nil, "1.2.3.4"}, // passed in "ip" parameter (with port)
{"127.0.0.1:9999?ip=1.2.3.4:1234", "X-Forwarded-For", "1.3.3.7:1337,4.2.4.2:4242", []string{"X-Forwarded-For"}, "1.2.3.4"}, // ip parameter wins over X-Forwarded-For with multiple entries (with port)
Copy link
Owner

Choose a reason for hiding this comment

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

Thanks! Can you undo all the other changes in the diff and add just the new case?

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.

2 participants