Make it an option for post uploads

This commit is contained in:
andreimarcu 2015-10-14 20:40:25 -04:00
parent 9b724725b3
commit 3c659601e2
2 changed files with 4 additions and 4 deletions

View File

@ -8,7 +8,7 @@ import (
// Do a strict referrer check, matching against both the Origin header (if // Do a strict referrer check, matching against both the Origin header (if
// present) and the Referrer header. If a list of headers is specified, then // present) and the Referrer header. If a list of headers is specified, then
// Referrer checking will be skipped if any of those headers are present. // Referrer checking will be skipped if any of those headers are present.
func strictReferrerCheck(r *http.Request, prefix string, whitelistHeaders []string) bool { func strictReferrerCheck(r *http.Request, prefix string, whitelistHeaders []string, allowBlank bool) bool {
p, _ := url.Parse(prefix) p, _ := url.Parse(prefix)
// if there's an Origin header, check it and skip other checks // if there's an Origin header, check it and skip other checks
@ -25,7 +25,7 @@ func strictReferrerCheck(r *http.Request, prefix string, whitelistHeaders []stri
referrer := r.Header.Get("Referer") referrer := r.Header.Get("Referer")
if referrer == "" { if allowBlank && referrer == "" {
return true return true
} }

View File

@ -46,7 +46,7 @@ type Upload struct {
} }
func uploadPostHandler(c web.C, w http.ResponseWriter, r *http.Request) { func uploadPostHandler(c web.C, w http.ResponseWriter, r *http.Request) {
if !strictReferrerCheck(r, Config.siteURL, []string{"Linx-Delete-Key", "Linx-Expiry", "Linx-Randomize", "X-Requested-With"}) { if !strictReferrerCheck(r, Config.siteURL, []string{"Linx-Delete-Key", "Linx-Expiry", "Linx-Randomize", "X-Requested-With"}, false) {
badRequestHandler(c, w, r) badRequestHandler(c, w, r)
return return
} }
@ -146,7 +146,7 @@ func uploadRemote(c web.C, w http.ResponseWriter, r *http.Request) {
} }
} else { } else {
// strict referrer checking is mandatory without remote auth keys // strict referrer checking is mandatory without remote auth keys
if !strictReferrerCheck(r, Config.siteURL, []string{"Linx-Delete-Key", "Linx-Expiry", "Linx-Randomize", "X-Requested-With"}) { if !strictReferrerCheck(r, Config.siteURL, []string{"Linx-Delete-Key", "Linx-Expiry", "Linx-Randomize", "X-Requested-With"}, true) {
badRequestHandler(c, w, r) badRequestHandler(c, w, r)
return return
} }