mirror of
https://github.com/tinyauthapp/tinyauth.git
synced 2026-09-09 00:23:31 +08:00
fix: use constant-time secret comparisons
Co-Authored-By: OpenAI <noreply@openai.com>
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/sha256"
|
||||||
|
"crypto/subtle"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -545,7 +547,9 @@ func (controller *OIDCController) Token(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if client.ClientSecret != creds.ClientSecret {
|
clientSecretHash := sha256.Sum256([]byte(client.ClientSecret))
|
||||||
|
providedSecretHash := sha256.Sum256([]byte(creds.ClientSecret))
|
||||||
|
if subtle.ConstantTimeCompare(clientSecretHash[:], providedSecretHash[:]) != 1 {
|
||||||
controller.log.App.Warn().Str("clientId", creds.ClientID).Msg("Invalid client secret")
|
controller.log.App.Warn().Str("clientId", creds.ClientID).Msg("Invalid client secret")
|
||||||
c.JSON(400, gin.H{
|
c.JSON(400, gin.H{
|
||||||
"error": "invalid_client",
|
"error": "invalid_client",
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
|
"crypto/subtle"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@@ -882,7 +883,7 @@ func (service *OIDCService) ValidatePKCE(codeChallenge string, codeVerifier stri
|
|||||||
if codeChallenge == "" {
|
if codeChallenge == "" {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return codeChallenge == service.hashAndEncodePKCE(codeVerifier)
|
return subtle.ConstantTimeCompare([]byte(codeChallenge), []byte(service.hashAndEncodePKCE(codeVerifier))) == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
func (service *OIDCService) hashAndEncodePKCE(codeVerifier string) string {
|
func (service *OIDCService) hashAndEncodePKCE(codeVerifier string) string {
|
||||||
|
|||||||
Reference in New Issue
Block a user