mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: Support x-forwarded-for headers for IPs (#4684)
* feat: Support x-forwarded-for headers for IPs Fixes #4430. * Fix realip accepting headers * Fix unused headers
This commit is contained in:
+4
-16
@@ -129,12 +129,8 @@ func InitRequest[T Auditable](w http.ResponseWriter, p *RequestParams) (*Request
|
||||
}
|
||||
}
|
||||
|
||||
ip, err := parseIP(p.Request.RemoteAddr)
|
||||
if err != nil {
|
||||
p.Log.Warn(logCtx, "parse ip", slog.Error(err))
|
||||
}
|
||||
|
||||
err = p.Audit.Export(ctx, database.AuditLog{
|
||||
ip := parseIP(p.Request.RemoteAddr)
|
||||
err := p.Audit.Export(ctx, database.AuditLog{
|
||||
ID: uuid.New(),
|
||||
Time: database.Now(),
|
||||
UserID: httpmw.APIKey(p.Request).UserID,
|
||||
@@ -166,16 +162,8 @@ func either[T Auditable, R any](old, new T, fn func(T) R) R {
|
||||
}
|
||||
}
|
||||
|
||||
func parseIP(ipStr string) (pqtype.Inet, error) {
|
||||
var err error
|
||||
|
||||
ipStr, _, err = net.SplitHostPort(ipStr)
|
||||
if err != nil {
|
||||
return pqtype.Inet{}, err
|
||||
}
|
||||
|
||||
func parseIP(ipStr string) pqtype.Inet {
|
||||
ip := net.ParseIP(ipStr)
|
||||
|
||||
ipNet := net.IPNet{}
|
||||
if ip != nil {
|
||||
ipNet = net.IPNet{
|
||||
@@ -187,5 +175,5 @@ func parseIP(ipStr string) (pqtype.Inet, error) {
|
||||
return pqtype.Inet{
|
||||
IPNet: ipNet,
|
||||
Valid: ip != nil,
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user