-
-
Notifications
You must be signed in to change notification settings - Fork 419
sec: constant-time admin token compare #294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,6 +3,7 @@ package main | |||||||||
| import ( | ||||||||||
| "bytes" | ||||||||||
| "context" | ||||||||||
| "crypto/subtle" | ||||||||||
| "database/sql" | ||||||||||
| "encoding/base64" | ||||||||||
| "encoding/json" | ||||||||||
|
|
@@ -124,7 +125,8 @@ func (s *server) GetHealth() http.HandlerFunc { | |||||||||
| func (s *server) authadmin(next http.Handler) http.Handler { | ||||||||||
| return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||||||||||
| token := r.Header.Get("Authorization") | ||||||||||
| if token != *adminToken { | ||||||||||
| // Constant-time compare to avoid timing-attack leak of admin token bytes. | ||||||||||
| if subtle.ConstantTimeCompare([]byte(token), []byte(*adminToken)) != 1 { | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While
Suggested change
|
||||||||||
| s.Respond(w, r, http.StatusUnauthorized, errors.New("unauthorized")) | ||||||||||
| return | ||||||||||
| } | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To support a more robust constant-time comparison that avoids leaking the token length, the "crypto/sha256" package is required.