middleware: add sanitization hook

This commit is contained in:
Leo Balduf
2016-11-28 20:55:04 +01:00
parent 91ce2aaf77
commit 3c098c0703
15 changed files with 248 additions and 63 deletions
+2 -7
View File
@@ -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
}