Skip to content
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

routers: do not leak secrets via timing side channel #7364

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this

  1. use md5?
  2. use owner's salt instead of some secret?

And who calls this API? Couldn't find any callers inside gitea itself.

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