Protect local Tailscale sign-in credentials

This commit is contained in:
Ian Gulliver
2026-10-21 07:11:55 -07:00
parent 4f88f8a4f4
commit 0d3ed1fdd3
4 changed files with 60 additions and 6 deletions
+10 -2
View File
@@ -2,6 +2,7 @@ package server
import (
"context"
"crypto/subtle"
"encoding/json"
"errors"
"fmt"
@@ -130,10 +131,17 @@ func (s *Server) Handler() http.Handler {
return http.NewCrossOriginProtection().Handler(mux)
}
func (s *Server) LoopbackHandler() http.Handler {
func (s *Server) LoopbackHandler(token string) http.Handler {
mux := http.NewServeMux()
mux.HandleFunc("GET /api/tailnet", s.GetTailnet)
return mux
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if subtle.ConstantTimeCompare([]byte(r.Header.Get("Authorization")), []byte("Bearer "+token)) != 1 {
http.Error(w, "unauthorized", http.StatusUnauthorized)
return
}
w.Header().Set("Cache-Control", "no-store")
mux.ServeHTTP(w, r)
})
}
func (s *Server) GetTailnet(w http.ResponseWriter, r *http.Request) {