Skip to content

Commit

Permalink
API key change should take effect on restart only
Browse files Browse the repository at this point in the history
  • Loading branch information
calmh committed Jun 5, 2014
1 parent 20a018d commit 1cff9cc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cmd/syncthing/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var (
guiErrors = []guiError{}
guiErrorsMut sync.Mutex
static func(http.ResponseWriter, *http.Request, *log.Logger)
apiKey string
)

const (
Expand Down Expand Up @@ -115,6 +116,7 @@ func startGUI(cfg config.GUIConfiguration, assetDir string, m *model.Model) erro
mr.Action(router.Handle)
mr.Map(m)

apiKey = cfg.APIKey
loadCsrfTokens()

go http.Serve(listener, mr)
Expand Down Expand Up @@ -363,7 +365,7 @@ func basic(username string, passhash string) http.HandlerFunc {
}

func validAPIKey(k string) bool {
return len(cfg.GUI.APIKey) > 0 && k == cfg.GUI.APIKey
return len(apiKey) > 0 && k == apiKey
}

func embeddedStatic() func(http.ResponseWriter, *http.Request, *log.Logger) {
Expand Down
1 change: 1 addition & 0 deletions cmd/syncthing/gui_csrf.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func csrfMiddleware(w http.ResponseWriter, r *http.Request) {
if validAPIKey(r.Header.Get("X-API-Key")) {
return
}

if strings.HasPrefix(r.URL.Path, "/rest/") {
token := r.Header.Get("X-CSRF-Token")
if !validCsrfToken(token) {
Expand Down

0 comments on commit 1cff9cc

Please sign in to comment.