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

"ClientIP" handling is unsafe #161

Closed
Geometry6151 opened this issue Aug 1, 2022 · 2 comments · Fixed by #401
Closed

"ClientIP" handling is unsafe #161

Geometry6151 opened this issue Aug 1, 2022 · 2 comments · Fixed by #401
Assignees
Labels
enhancement New feature or request

Comments

@Geometry6151
Copy link

hertz/pkg/app/context.go

Lines 980 to 994 in 3ac19d5

var defaultClientIP = func(ctx *RequestContext) string {
RemoteIPHeaders := []string{"X-Real-IP", "X-Forwarded-For"}
for _, headerName := range RemoteIPHeaders {
ip := ctx.Request.Header.Get(headerName)
if ip != "" {
return ip
}
}
if ip, _, err := net.SplitHostPort(strings.TrimSpace(ctx.RemoteAddr().String())); err == nil {
return ip
}
return ""
}

This code has a security risk, when using the ClientIP function it is easy to be spoofed by "X-Real-IP" and "X-Forwarded-For" to bypass the checks。

This problem also occurs with the Gin framework -> gin-gonic/gin#2473
The fix can be found in their issue。

@welkeyever
Copy link
Member

Thanks for reporting! Are you interested in submitting a pr to fix it?
It's OK if it is not so, I'll put it into TODOs.

@li-jin-gou li-jin-gou added the enhancement New feature or request label Aug 2, 2022
@BaiZe1998
Copy link
Contributor

i want to try it, please assign me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging a pull request may close this issue.

4 participants