2015-10-09 05:27:04 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
func strictReferrerCheck(r *http.Request, prefix string, whitelistHeaders []string) bool {
|
|
|
|
for _, header := range whitelistHeaders {
|
|
|
|
if r.Header.Get(header) != "" {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if referrer := r.Header.Get("Referer"); !strings.HasPrefix(referrer, prefix) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2015-10-12 05:06:14 +02:00
|
|
|
if origin := r.Header.Get("Origin"); origin != "" && !strings.HasPrefix(origin, strings.TrimSuffix(prefix, "/")) {
|
2015-10-09 05:27:04 +02:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|