Skip to content

Commit dd55cde

Browse files
committed
Apply subtle.WithDataIndependentTiming to token check
Once again, I am forced to trust myself with this power. It's not, like, some horrible violation that there's an `==` in here, right? Either way, since I am generally running this on arm64, I suppose some weird things could start to happen without this.
1 parent 72c76b2 commit dd55cde

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/ahamlinman/randomizer
22

3-
go 1.23
3+
go 1.24.0
44

55
require (
66
cloud.google.com/go/firestore v1.18.0

internal/slack/slack.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,17 @@ func (a App) ServeHTTP(w http.ResponseWriter, r *http.Request) {
7373
a.writeResult(w, result)
7474
}
7575

76-
func (a App) isTokenValid(ctx context.Context, params url.Values) (bool, error) {
76+
func (a App) isTokenValid(ctx context.Context, params url.Values) (ok bool, _ error) {
7777
gotToken := params.Get("token")
7878
wantToken, err := a.TokenProvider(ctx)
7979
if err != nil {
8080
return false, err
8181
}
8282

83-
return subtle.ConstantTimeCompare([]byte(gotToken), []byte(wantToken)) == 1, nil
83+
subtle.WithDataIndependentTiming(func() {
84+
ok = subtle.ConstantTimeCompare([]byte(gotToken), []byte(wantToken)) == 1
85+
})
86+
return
8487
}
8588

8689
func (a App) runRandomizer(ctx context.Context, params url.Values) (randomizer.Result, error) {

0 commit comments

Comments
 (0)