Skip to content

Conversation

@tmshn
Copy link
Contributor

@tmshn tmshn commented Jan 15, 2020

IP address extraction using HTTP header requires additional care. Otherwise attackers might have a chance to deceive wrong ip address.

I fixed this problem.

See also: #855

I wrote detailed doc in labstack/echox#134, tl; dr:

  • Don't use HTTP header unless it's reported by trustable client
  • For XFF header, use rightmost untrustable value, not the leftmost value.
  • When proxing, don't relay incoming X-Real-IP unless it's reported by trustable client

Especially about XFF header parsing, see implementations from other players:

Another note about XFF header:

@codecov
Copy link

codecov bot commented Jan 15, 2020

Codecov Report

Merging #1478 into master will increase coverage by 0.36%.
The diff coverage is 96.92%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1478      +/-   ##
==========================================
+ Coverage   84.42%   84.79%   +0.36%     
==========================================
  Files          27       28       +1     
  Lines        2093     2157      +64     
==========================================
+ Hits         1767     1829      +62     
- Misses        212      213       +1     
- Partials      114      115       +1
Impacted Files Coverage Δ
echo.go 85.75% <ø> (ø) ⬆️
context.go 90.43% <0%> (-0.73%) ⬇️
ip.go 100% <100%> (ø)
middleware/proxy.go 66% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 504f39a...d669727. Read the comment docs.

@tmshn tmshn force-pushed the trustable-ip branch 4 times, most recently from bdff2da to 44976af Compare January 20, 2020 06:32
@tmshn tmshn changed the title [WIP] Safer/trustable extraction of real ip from request Safer/trustable extraction of real ip from request Feb 9, 2020
@vishr vishr merged commit 7c5af01 into labstack:master Feb 24, 2020
@vishr
Copy link
Member

vishr commented Feb 24, 2020

@tmshn thanks for your work!

@tmshn tmshn deleted the trustable-ip branch February 26, 2020 09:41
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