mirror of
https://github.com/hashicorp/vault.git
synced 2025-11-20 10:11:34 +01:00
auth/app-id: protect against timing attack. Credit @kenbreeman
This commit is contained in:
parent
0ac071d15c
commit
d54ff83113
@ -2,6 +2,7 @@ package appId
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
|
"crypto/subtle"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
@ -82,8 +83,11 @@ func (b *backend) pathLogin(
|
|||||||
|
|
||||||
// Verify that the app is in the list
|
// Verify that the app is in the list
|
||||||
found := false
|
found := false
|
||||||
|
appIdBytes := []byte(appId)
|
||||||
for _, app := range strings.Split(apps, ",") {
|
for _, app := range strings.Split(apps, ",") {
|
||||||
if strings.TrimSpace(app) == appId {
|
match := []byte(strings.TrimSpace(app))
|
||||||
|
// Protect against a timing attack with the app_id comparison
|
||||||
|
if subtle.ConstantTimeCompare(match, appIdBytes) == 1 {
|
||||||
found = true
|
found = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user