mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-25 19:15:34 +00:00
drive: use secret token to authenticate access to file server on localhost
This prevents Mark-of-the-Web bypass attacks in case someone visits the localhost WebDAV server directly. Fixes tailscale/corp#19592 Signed-off-by: Percy Wegmann <percy@tailscale.com>
This commit is contained in:
parent
9d22ec0ba2
commit
0c11fd978b
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
|
"crypto/subtle"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
@ -117,7 +118,8 @@ func (s *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
parts := shared.CleanAndSplit(r.URL.Path)
|
parts := shared.CleanAndSplit(r.URL.Path)
|
||||||
|
|
||||||
token := parts[0]
|
token := parts[0]
|
||||||
if token != s.secretToken {
|
a, b := []byte(token), []byte(s.secretToken)
|
||||||
|
if len(a) != len(b) || subtle.ConstantTimeCompare(a, b) != 1 {
|
||||||
w.WriteHeader(http.StatusForbidden)
|
w.WriteHeader(http.StatusForbidden)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user