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

[feature] Disable IP address detection #2289

Open
ex-tag opened this issue Oct 2, 2022 · 2 comments
Open

[feature] Disable IP address detection #2289

ex-tag opened this issue Oct 2, 2022 · 2 comments

Comments

@ex-tag
Copy link

ex-tag commented Oct 2, 2022

https://echo.labstack.com/guide/ip-address/

Our privacy policy forbids the use of customer IP address detection.
Any recommendation on how to disable the IPExtractor?

router.IPExtractor = nil

Or...

router.IPExtractor = func() echo.IPExtractor {
  return func(req *http.Request) string {
    req.RemoteAddr = ""
    return ""
  }
}()
@aldas
Copy link
Contributor

aldas commented Oct 5, 2022

Probably any variant that does not cause unexpected problems. I think setting it to nil should be OK. IPExtractor is only used where c.RealIP() is called so if you can avoid calling it - you are good to go.

@tomruk
Copy link

tomruk commented Feb 17, 2023

By default, IPExtractor is nil — it is not set anywhere. And it is only accessed from

echo/context.go

Line 283 in 6b09f3f

return c.echo.IPExtractor(c.request)
and
if req.Header.Get(echo.HeaderXRealIP) == "" || c.Echo().IPExtractor != nil {

So unless you use RealIP or use the proxy middleware, you never call the IPExtractor.

Also the RemoteAddr is used in

echo/context.go

Line 301 in 6b09f3f

ra, _, _ := net.SplitHostPort(c.request.RemoteAddr)

and

echo/ip.go

Line 219 in 6b09f3f

ra, _, _ := net.SplitHostPort(req.RemoteAddr)

So unless you use RealIP or use the ExtractIPDirect, you never use the RemoteAddr.

The most guaranteed approach in your case is to write your own IPExtractor that returns an empty string (you can set it to nil, but just in case), and never use the things mentioned above.

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

No branches or pull requests

3 participants