From 4361c44128f3a2312df32c8d6b20a2f4c432ec79 Mon Sep 17 00:00:00 2001 From: Viktor Oreshkin Date: Sun, 1 Mar 2020 03:23:54 +0300 Subject: [PATCH] fix domain field in setAccessKeyCookies --- access.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/access.go b/access.go index bacea24..bf32013 100644 --- a/access.go +++ b/access.go @@ -3,7 +3,10 @@ package main import ( "encoding/json" "errors" + "log" "net/http" + "net/url" + "path" "regexp" "strings" "time" @@ -70,19 +73,25 @@ func checkAccessKey(r *http.Request, metadata *backends.Metadata) (accessKeySour return accessKeySourceNone, errInvalidAccessKey } -func setAccessKeyCookies(w http.ResponseWriter, domain, fileName, value string, expires time.Time) { +func setAccessKeyCookies(w http.ResponseWriter, siteURL, fileName, value string, expires time.Time) { + u, err := url.Parse(siteURL) + if err != nil { + log.Printf("cant parse siteURL (%v): %v", siteURL, err) + return + } + cookie := http.Cookie{ Name: accessKeyHeaderName, Value: value, HttpOnly: true, - Domain: domain, + Domain: u.Hostname(), Expires: expires, } - cookie.Path = Config.sitePath + fileName + cookie.Path = path.Join(u.Path, fileName) http.SetCookie(w, &cookie) - cookie.Path = Config.sitePath + Config.selifPath + fileName + cookie.Path = path.Join(u.Path, Config.selifPath, fileName) http.SetCookie(w, &cookie) }