proper constant time compare for hidden domain
This commit is contained in:
parent
1889908fe9
commit
0b4d62892c
7
auth.go
7
auth.go
|
@ -58,7 +58,9 @@ func NewStaticAuth(param_url *url.URL) (*StaticAuth, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func requireBasicAuth(wr http.ResponseWriter, req *http.Request, hidden_domain string) {
|
func requireBasicAuth(wr http.ResponseWriter, req *http.Request, hidden_domain string) {
|
||||||
if hidden_domain != "" && req.URL.Host != hidden_domain && req.Host != hidden_domain {
|
if hidden_domain != "" &&
|
||||||
|
(subtle.ConstantTimeCompare([]byte(req.URL.Host), []byte(hidden_domain)) != 1 &&
|
||||||
|
subtle.ConstantTimeCompare([]byte(req.Host), []byte(hidden_domain)) != 1) {
|
||||||
http.Error(wr, "Bad Request", http.StatusBadRequest)
|
http.Error(wr, "Bad Request", http.StatusBadRequest)
|
||||||
} else {
|
} else {
|
||||||
wr.Header().Set("Proxy-Authenticate", `Basic realm="dumbproxy"`)
|
wr.Header().Set("Proxy-Authenticate", `Basic realm="dumbproxy"`)
|
||||||
|
@ -83,8 +85,7 @@ func (auth *StaticAuth) Validate(wr http.ResponseWriter, req *http.Request) bool
|
||||||
ok := (subtle.ConstantTimeCompare([]byte(token), []byte(auth.token)) == 1)
|
ok := (subtle.ConstantTimeCompare([]byte(token), []byte(auth.token)) == 1)
|
||||||
if ok {
|
if ok {
|
||||||
if auth.hiddenDomain != "" &&
|
if auth.hiddenDomain != "" &&
|
||||||
(subtle.ConstantTimeCompare([]byte(req.Host), []byte(auth.hiddenDomain)) == 1 ||
|
(req.Host == auth.hiddenDomain || req.URL.Host == auth.hiddenDomain) {
|
||||||
subtle.ConstantTimeCompare([]byte(req.URL.Host), []byte(auth.hiddenDomain)) == 1) {
|
|
||||||
http.Error(wr, "Browser auth triggered!", http.StatusGone)
|
http.Error(wr, "Browser auth triggered!", http.StatusGone)
|
||||||
return false
|
return false
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue