fix(security): valida JWT ES256 de Supabase (desbloquea producción)#56
Merged
Conversation
El path JWKS asumía RSA (RSAAlgorithm.from_jwk + algorithms=["RS256"]); Supabase emite JWT ES256 (claves EC) → InvalidKeyError "Not an RSA key" FUERA del try/except → 500 en toda ruta autenticada en prod (crear org → 500 directo / 504 vía Vercel). En local no salía porque con SUPABASE_JWT_SECRET se usa el path HS256. Fix: jwt.PyJWK(key).key detecta EC/RSA desde el JWK; algorithms=["RS256","ES256"]. Test nuevo (gap de la auditoría): ES256 valida, RS256 regresión, firma inválida → 401. Claude-Session: https://claude.ai/code/session_0198KfgRWvAM8BhiVz24uTok
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
El bug (producción rota)
Crear una organización en prod daba 500 (directo al backend) / 504 (vía Vercel). Causa: el path de validación de JWT por JWKS en
src/security.pyasumía RSA:Supabase emite JWT ES256 (claves EC).
RSAAlgorithm.from_jwkcon una clave EC lanzaInvalidKeyError: Not an RSA keyfuera del try/except → 500 en toda ruta autenticada. Reproducido contra el JWKS real (kty=EC alg=ES256).En local no aparecía porque con
SUPABASE_JWT_SECRETse toma el path HS256 (simétrico). En prod (sin ese secret) se usa el path JWKS → el bug. Era justo el path que la auditoría marcó como no testeado.El fix
jwt.PyJWK(key).keydetecta el tipo de clave (EC/RSA) desde el JWK.algorithms = ["RS256", "ES256"](sigue aceptando RSA; añade EC). No aceptanoneni downgrade.tests/test_security_jwks.py(nuevo): ES256 valida, RS256 regresión, firma inválida → 401.Plan de pruebas
.env. Regresión auth/security: 49 passed.Para desplegar el fix
main.maincon el fix).https://claude.ai/code/session_0198KfgRWvAM8BhiVz24uTok