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

TrustedProxies: Add default IPv6 support and refactor #2967

Merged
merged 22 commits into from
Dec 3, 2021

Conversation

Bisstocuz
Copy link
Contributor

@Bisstocuz Bisstocuz commented Nov 29, 2021

  1. Tidy: Complete TrustedProxies feature #2887 didn't support IPv6 by default, now fixed it. (It return unexpected remote IP when nginx proxy pass to "localhost" address. #2966)
  2. Move two functions with receiver Engine from context.go to gin.go.
  3. Refactor for function validateHeader to decrease Codecov coverage misses.
  4. Refactor for Context.RemoteIP():
    4.1. This is a public function, its usage should be friendly to users.
    4.2. RemoteAddr is almost impossible to fake. If I wanna get the remote address directly by RemoteIP(), it's unnecessary to know if trusted. The Trusted Proxies checking should be finished in ClientIP().
  5. Improve checking logic in Engine.isUnsafeTrustedProxies().

This PR has passed checks on my side: Bisstocuz#3

@codecov
Copy link

codecov bot commented Nov 29, 2021

Codecov Report

Merging #2967 (ddc5c55) into master (a06d546) will increase coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2967      +/-   ##
==========================================
+ Coverage   98.57%   98.60%   +0.03%     
==========================================
  Files          41       41              
  Lines        3085     3084       -1     
==========================================
  Hits         3041     3041              
+ Misses         31       30       -1     
  Partials       13       13              
Flag Coverage Δ
go-1.13 ∅ <ø> (∅)
go-1.14 ∅ <ø> (∅)
go-1.15 ∅ <ø> (∅)
go-1.16 98.60% <100.00%> (+0.03%) ⬆️
go-1.17 98.50% <100.00%> (+0.03%) ⬆️
macos-latest 98.60% <100.00%> (+0.03%) ⬆️
nomsgpack 98.58% <100.00%> (+0.03%) ⬆️
ubuntu-latest 98.60% <100.00%> (+0.03%) ⬆️

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

Impacted Files Coverage Δ
context.go 97.89% <100.00%> (+0.08%) ⬆️
gin.go 99.17% <100.00%> (+0.05%) ⬆️

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 a06d546...ddc5c55. Read the comment docs.

@Bisstocuz
Copy link
Contributor Author

Linked issue #2966 by @beanbest

Code review plz @thinkerou

gin.go Outdated Show resolved Hide resolved
gin.go Outdated Show resolved Hide resolved
@Bisstocuz Bisstocuz requested a review from thinkerou November 29, 2021 06:04
@Bisstocuz
Copy link
Contributor Author

@appleboy code review plz

@thinkerou thinkerou requested a review from appleboy November 29, 2021 11:55
@thinkerou thinkerou added this to the v1.8 milestone Nov 29, 2021
Copy link
Member

@thinkerou thinkerou left a comment

Choose a reason for hiding this comment

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

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants