Skip to content

fix: trim forwarded IP headers before parsing#4007

Open
immanuwell wants to merge 1 commit into
gravitl:developfrom
immanuwell:bugfix_trim-forwarded-ip
Open

fix: trim forwarded IP headers before parsing#4007
immanuwell wants to merge 1 commit into
gravitl:developfrom
immanuwell:bugfix_trim-forwarded-ip

Conversation

@immanuwell
Copy link
Copy Markdown

Fixes a small edge in /api/getip.

X-Forwarded-For is comma separated, and proxies often leave a space after the comma. Before this, 10.0.0.1, 8.8.8.8 made net.ParseIP(" 8.8.8.8") nope out, so the handler fell through to RemoteAddr and could return ip is a private address.

Repro:

  1. call parseIP/getip with X-FORWARDED-FOR: 10.0.0.1, 8.8.8.8
  2. set RemoteAddr to a private IP
  3. current code errors instead of picking 8.8.8.8

This trims X-REAL-IP and each forwarded entry before parsing. Tiny fix, no behavior change for already clean headers.

Tests:
go test ./controllers -count=1
go test ./functions ./models ./validation ./netclient/ncutils ./logic -run Test -count=1

@tenki-reviewer
Copy link
Copy Markdown
Contributor

immanuwell does not have permission to run Code Reviewer. You can manage permissions in your settings.

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.

1 participant