Browse Source

Use Authorization header for secret

DarthSim 8 years ago
parent
commit
1ba9360599
1 changed files with 5 additions and 2 deletions
  1. 5 2
      server.go

+ 5 - 2
server.go

@@ -126,7 +126,10 @@ func repondWithForbidden(rw http.ResponseWriter) {
 }
 
 func checkSecret(s string) bool {
-	return len(conf.Secret) == 0 || subtle.ConstantTimeCompare([]byte(s), []byte(conf.Secret)) == 1
+	if len(conf.Secret) == 0 {
+		return true
+	}
+	return strings.HasPrefix(s, "Bearer ") && subtle.ConstantTimeCompare([]byte(strings.TrimPrefix(s, "Bearer ")), []byte(conf.Secret)) == 1
 }
 
 func (h httpHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
@@ -134,7 +137,7 @@ func (h httpHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
 
 	t := time.Now()
 
-	if !checkSecret(r.Header.Get("X-Imgproxy-Secret")) {
+	if !checkSecret(r.Header.Get("Authorization")) {
 		repondWithForbidden(rw)
 		return
 	}