Skip to content

fix: support non-standard X-Forwarded-For header formats (#4572)#4591

Open
larkwins wants to merge 1 commit intogin-gonic:masterfrom
larkwins:fix/4572-xff-non-standard
Open

fix: support non-standard X-Forwarded-For header formats (#4572)#4591
larkwins wants to merge 1 commit intogin-gonic:masterfrom
larkwins:fix/4572-xff-non-standard

Conversation

@larkwins
Copy link
Copy Markdown

Handle non-standard IP formats in X-Forwarded-For header that are commonly set by reverse proxies like IIS and cloud load balancers:

  • IPv4 with port: '192.168.8.39:38792'
  • IPv6 with brackets: '[240e:318:2f4a:de56::240]'
  • IPv6 with brackets and port: '[240e:318:2f4a:de56::240]:38792'

Added parseNonstandardIP() helper function that uses net.SplitHostPort() and bracket stripping to extract the clean IP address before validation.

Closes #4572

)

Handle non-standard IP formats in X-Forwarded-For header that are
commonly set by reverse proxies like IIS and cloud load balancers:
- IPv4 with port: '192.168.8.39:38792'
- IPv6 with brackets: '[240e:318:2f4a:de56::240]'
- IPv6 with brackets and port: '[240e:318:2f4a:de56::240]:38792'

Added parseNonstandardIP() helper function that uses net.SplitHostPort()
and bracket stripping to extract the clean IP address before validation.

Closes gin-gonic#4572
@larkwins larkwins force-pushed the fix/4572-xff-non-standard branch from 28fcd50 to 7b53fa1 Compare March 23, 2026 07:30
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.44%. Comparing base (3dc1cd6) to head (7b53fa1).
⚠️ Report is 275 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4591      +/-   ##
==========================================
- Coverage   99.21%   98.44%   -0.77%     
==========================================
  Files          42       48       +6     
  Lines        3182     3152      -30     
==========================================
- Hits         3157     3103      -54     
- Misses         17       40      +23     
- Partials        8        9       +1     
Flag Coverage Δ
?
--ldflags="-checklinkname=0" -tags sonic 98.43% <100.00%> (?)
-tags go_json 98.30% <100.00%> (?)
-tags nomsgpack 98.35% <100.00%> (?)
go-1.18 ?
go-1.19 ?
go-1.20 ?
go-1.21 ?
go-1.25 98.38% <100.00%> (?)
go-1.26 98.44% <100.00%> (?)
macos-latest 98.38% <100.00%> (-0.84%) ⬇️
ubuntu-latest 98.44% <100.00%> (-0.77%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

larkwins pushed a commit to larkwins/gin that referenced this pull request Mar 23, 2026
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.

Non-standard X-Forwarded-For header content is not supported

1 participant