Skip to content

Commit 0cf64e8

Browse files
steveiliop56codex
andcommitted
fix: use constant-time secret comparisons
Co-Authored-By: OpenAI <noreply@openai.com>
1 parent b61fc6b commit 0cf64e8

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

‎internal/controller/oidc_controller.go‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package controller
22

33
import (
4+
"crypto/sha256"
5+
"crypto/subtle"
46
"encoding/json"
57
"errors"
68
"fmt"
@@ -545,7 +547,9 @@ func (controller *OIDCController) Token(c *gin.Context) {
545547
return
546548
}
547549

548-
if client.ClientSecret != creds.ClientSecret {
550+
clientSecretHash := sha256.Sum256([]byte(client.ClientSecret))
551+
providedSecretHash := sha256.Sum256([]byte(creds.ClientSecret))
552+
if subtle.ConstantTimeCompare(clientSecretHash[:], providedSecretHash[:]) != 1 {
549553
controller.log.App.Warn().Str("clientId", creds.ClientID).Msg("Invalid client secret")
550554
c.JSON(400, gin.H{
551555
"error": "invalid_client",

‎internal/service/oidc_service.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"crypto/rand"
77
"crypto/rsa"
88
"crypto/sha256"
9+
"crypto/subtle"
910
"crypto/x509"
1011
"encoding/base64"
1112
"encoding/json"
@@ -882,7 +883,7 @@ func (service *OIDCService) ValidatePKCE(codeChallenge string, codeVerifier stri
882883
if codeChallenge == "" {
883884
return true
884885
}
885-
return codeChallenge == service.hashAndEncodePKCE(codeVerifier)
886+
return subtle.ConstantTimeCompare([]byte(codeChallenge), []byte(service.hashAndEncodePKCE(codeVerifier))) == 1
886887
}
887888

888889
func (service *OIDCService) hashAndEncodePKCE(codeVerifier string) string {

0 commit comments

Comments
 (0)