Skip to content

Commit

Permalink
routers: do not leak secrets via timing side channel (go-gitea#7364)
Browse files Browse the repository at this point in the history
* routers: do not leak secrets via timing side channel

* routers/repo: do not leak secrets via timing side channel
  • Loading branch information
leonklingele authored and jeffliu27 committed Jul 18, 2019
1 parent a39f022 commit 71df1a3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion routers/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
package routers

import (
"crypto/subtle"

"github.com/prometheus/client_golang/prometheus/promhttp"

"code.gitea.io/gitea/modules/context"
Expand All @@ -22,7 +24,9 @@ func Metrics(ctx *context.Context) {
ctx.Error(401)
return
}
if header != "Bearer "+setting.Metrics.Token {
got := []byte(header)
want := []byte("Bearer " + setting.Metrics.Token)
if subtle.ConstantTimeCompare(got, want) != 1 {
ctx.Error(401)
return
}
Expand Down
5 changes: 4 additions & 1 deletion routers/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package repo

import (
"container/list"
"crypto/subtle"
"fmt"
"io"
"path"
Expand Down Expand Up @@ -771,7 +772,9 @@ func TriggerTask(ctx *context.Context) {
if ctx.Written() {
return
}
if secret != base.EncodeMD5(owner.Salt) {
got := []byte(base.EncodeMD5(owner.Salt))
want := []byte(secret)
if subtle.ConstantTimeCompare(got, want) != 1 {
ctx.Error(404)
log.Trace("TriggerTask [%s/%s]: invalid secret", owner.Name, repo.Name)
return
Expand Down

0 comments on commit 71df1a3

Please sign in to comment.