Fix Unix listener causing 500s on Mac (#4243)

Some platforms use `@` for a Unix socket address, and some leave it
empty. In the empty case this causes the rate limiting code to throw a
500 error. This commit standardizes on using `@` for incoming
connections over a Unix socket.
This commit is contained in:
Jeff Mitchell authored and GitHub committed 2024-01-17 11:38:53 -08:00
1 parent 957cd59d91
commit 8c1bdb2190
1 file changed
+6
+6
View File
@@ -34,6 +34,12 @@ func ClientIpFromRequest(ctx context.Context, listenerCfg *listenerutil.Listener
if err != nil {
return "", errors.Wrap(ctx, err, op)
}
if listenerCfg.Type == "unix" && ip == "" {
// Some platforms (Linux) use "@" in this case but some like Mac
// leave it empty which causes issues with the rate limiting logic,
// so standardize on "@" in this case.
return "@", nil
}
return ip, nil
case trustedForwardedFor == nil && remoteAddr != nil:
// not reachable given listenerutil.TrustedFromXForwardedFor