Skip to content

Commit 8d4881c

Browse files
author
Mmadu Manasseh
committed
Filter based on referer
1 parent ab54551 commit 8d4881c

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

cmd/api.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,13 @@ func authIP(handler http.HandlerFunc) http.HandlerFunc {
4545
ip, _, err := net.SplitHostPort(r.RemoteAddr)
4646

4747
originURL, _ := url.Parse(r.Header.Get("Origin"))
48-
if err == nil && (contains(WhiteListedHosts, ip) || contains(WhiteListedHosts, "*") || contains(WhiteListedHosts, originURL.Host)) {
48+
refererURL, _ := url.Parse(r.Header.Get("Referer"))
49+
if err == nil && (contains(WhiteListedHosts, ip) || contains(WhiteListedHosts, "*") || contains(WhiteListedHosts, originURL.Host) || contains(WhiteListedHosts, refererURL.Host)) {
4950
handler.ServeHTTP(w, r)
5051
} else {
51-
log.Debug("Rejecting Request: Host not whitelisted")
52-
accessDeniedHandler(w, r)
53-
}
52+
log.Debugf("Rejecting Request: Host %s/%s Not whitelisted", originURL.Host, refererURL.Host)
53+
accessDeniedHandler(w, r)
54+
}
5455
}
5556
}
5657

0 commit comments

Comments
 (0)