mirror of
https://github.com/sot-tech/mochi.git
synced 2026-05-19 22:34:47 -07:00
add filter_private_ips option to discard private IPs.
Might be used when tracker is behind reverse proxy and one of provided addresses in `real_ip_header` is private/local address. Additional changes: * check if provided address is not multicast/broadcast * configure `http.Server.ReadHeaderTimeout` with `http.ReadTimeout` to mitigate Slowloris * update dependencies * minor docs fixes
This commit is contained in:
@@ -15,13 +15,13 @@ var (
|
||||
|
||||
// SanitizeAnnounce enforces a max and default NumWant and coerces the peer's
|
||||
// IP address into the proper format.
|
||||
func SanitizeAnnounce(r *AnnounceRequest, maxNumWant, defaultNumWant uint32) error {
|
||||
func SanitizeAnnounce(r *AnnounceRequest, maxNumWant, defaultNumWant uint32, filterPrivate bool) error {
|
||||
logger.Trace().Object("request", r).Msg("source announce")
|
||||
if r.Port == 0 {
|
||||
return ErrInvalidPort
|
||||
}
|
||||
|
||||
if !r.Validate() {
|
||||
if !r.Sanitize(filterPrivate) {
|
||||
return ErrInvalidIP
|
||||
}
|
||||
|
||||
@@ -37,13 +37,13 @@ func SanitizeAnnounce(r *AnnounceRequest, maxNumWant, defaultNumWant uint32) err
|
||||
|
||||
// SanitizeScrape enforces a max number of infohashes for a single scrape
|
||||
// request and checks if addresses are valid.
|
||||
func SanitizeScrape(r *ScrapeRequest, maxScrapeInfoHashes uint32) error {
|
||||
func SanitizeScrape(r *ScrapeRequest, maxScrapeInfoHashes uint32, filterPrivate bool) error {
|
||||
logger.Trace().Object("request", r).Msg("source scrape")
|
||||
if len(r.InfoHashes) > int(maxScrapeInfoHashes) {
|
||||
r.InfoHashes = r.InfoHashes[:maxScrapeInfoHashes]
|
||||
}
|
||||
|
||||
if !r.Validate() {
|
||||
if !r.Sanitize(filterPrivate) {
|
||||
return ErrInvalidIP
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user