mirror of
https://github.com/sot-tech/mochi.git
synced 2026-07-26 17:38:14 -07:00
middleware: add sanitization hook
This commit is contained in:
@@ -74,16 +74,11 @@ func ParseAnnounce(r *http.Request, realIPHeader string, allowIPSpoofing bool) (
|
||||
}
|
||||
request.Peer.Port = uint16(port)
|
||||
|
||||
request.Peer.IP = requestedIP(r, qp, realIPHeader, allowIPSpoofing)
|
||||
if request.Peer.IP == nil {
|
||||
request.Peer.IP.IP = requestedIP(r, qp, realIPHeader, allowIPSpoofing)
|
||||
if request.Peer.IP.IP == nil {
|
||||
return nil, bittorrent.ClientError("failed to parse peer IP address")
|
||||
}
|
||||
|
||||
// Sanitize IPv4 addresses to 4 bytes.
|
||||
if ip := request.Peer.IP.To4(); ip != nil {
|
||||
request.Peer.IP = ip
|
||||
}
|
||||
|
||||
return request, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user