Feat v0.6.6 final hardening (#41)
All checks were successful
All checks were successful
Co-authored-by: Jeffrey Smith <jasafpro@gmail.com> Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
This commit was merged in pull request #41.
This commit is contained in:
@@ -218,8 +218,8 @@ func (h *AuthHandler) OIDCCallback(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// Verify state (nonce + redirectTo retrieved but not yet validated — TODO)
|
||||
_, _, err := h.stores.GlobalConfig.ConsumeOIDCState(c.Request.Context(), state)
|
||||
// Verify state and retrieve nonce for ID token validation
|
||||
storedNonce, _, err := h.stores.GlobalConfig.ConsumeOIDCState(c.Request.Context(), state)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid or expired state"})
|
||||
return
|
||||
@@ -246,6 +246,15 @@ func (h *AuthHandler) OIDCCallback(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// Validate nonce in the ID token to prevent token replay/substitution
|
||||
if tokenResp.IDToken != "" && storedNonce != "" {
|
||||
if err := oidcProv.ValidateIDTokenNonce(tokenResp.IDToken, storedNonce); err != nil {
|
||||
log.Printf("[auth/oidc] nonce validation failed: %v", err)
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "nonce validation failed"})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Use the ID token (or access token) to authenticate via the provider
|
||||
// Temporarily set the Authorization header so Authenticate() can read it
|
||||
tokenToValidate := tokenResp.IDToken
|
||||
|
||||
Reference in New Issue
Block a user