mirror of
https://github.com/pgsty/minio.git
synced 2026-07-23 14:10:25 +03:00
send proper IPv6 names avoid bracketing notation (#18699)
Following policies if present
```
"Condition": {
"IpAddress": {
"aws:SourceIp": [
"54.240.143.0/24",
"2001:DB8:1234:5678::/64"
]
}
}
```
And client is making a request to MinIO via IPv6 can
potentially crash the server.
Workarounds are turn-off IPv6 and use only IPv4
This commit is contained in:
@@ -113,16 +113,27 @@ func GetSourceIPFromHeaders(r *http.Request) string {
|
||||
return addr
|
||||
}
|
||||
|
||||
// GetSourceIP retrieves the IP from the request headers
|
||||
// GetSourceIPRaw retrieves the IP from the request headers
|
||||
// and falls back to r.RemoteAddr when necessary.
|
||||
func GetSourceIP(r *http.Request) string {
|
||||
// however returns without bracketing.
|
||||
func GetSourceIPRaw(r *http.Request) string {
|
||||
addr := GetSourceIPFromHeaders(r)
|
||||
if addr != "" {
|
||||
return addr
|
||||
if addr == "" {
|
||||
addr = r.RemoteAddr
|
||||
}
|
||||
|
||||
// Default to remote address if headers not set.
|
||||
addr, _, _ = net.SplitHostPort(r.RemoteAddr)
|
||||
raddr, _, _ := net.SplitHostPort(addr)
|
||||
if raddr == "" {
|
||||
return addr
|
||||
}
|
||||
return raddr
|
||||
}
|
||||
|
||||
// GetSourceIP retrieves the IP from the request headers
|
||||
// and falls back to r.RemoteAddr when necessary.
|
||||
func GetSourceIP(r *http.Request) string {
|
||||
addr := GetSourceIPRaw(r)
|
||||
if strings.ContainsRune(addr, ':') {
|
||||
return "[" + addr + "]"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user