Repository navigation
Conversation
…q) y agrega flujo de lint y cobertura
…anos (HU-02) Reindenta ademas el bloque de clockTolerance a 2 espacios.
Prepara el rechazo de opciones desconocidas en verify(): 46 pruebas de 7 archivos pasaban opciones que verify() ignora en silencio. - algorithm -> algorithms en option-maxAge y jwt.hs (no restringia la lista blanca de algoritmos) - jetid -> jwtid en claim-jti (la prueba nunca ejercia jwtid) - se retiran typ, exp y nbf de las opciones de verify
verify() ignoraba en silencio cualquier opcion que no leyera, de modo que un error tipografico como "algoritms" descartaba la lista blanca de algoritmos. Ahora solo se aceptan las 13 opciones documentadas y cualquier otra produce JsonWebTokenError: '"<nombre>" is not an allowed option', lanzado o por callback. BREAKING CHANGE: verify() rechaza opciones no documentadas (por ejemplo algorithm, typ, exp, nbf o expiresIn).
…ptions.js (HU-04) Mueve fuera de verify() la lista de opciones permitidas y las reglas de tipo de clockTimestamp, clockTolerance, ignoreExpiration, ignoreNotBefore, nonce y allowInvalidAsymmetricKeyTypes. El modulo devuelve el JsonWebTokenError o null, y verify() lo entrega por done. Sin cambios de comportamiento: mismos mensajes y mismo orden. La funcion externa de verify() baja de complejidad 27 a menos de 15; el callback se mantiene en 57. El modulo nuevo tiene 100 % de cobertura.
amoramongeCenfo
force-pushed
the
tdd/validacion-opciones-verify
branch
from
October 26, 2026 02:05
541992e to
49be9d7
Compare
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.
Description
jwt.verify()validates the type of only four of the thirteen options it reads (clockTimestamp,nonce,maxAgeandallowInvalidAsymmetricKeyTypes).jwt.sign(), by contrast, validates its options against a schema. As a result, a misconfiguredverify()call can silently disable the expiration check.Reproduction on
v9.0.3(commitb924272), with a token that expired 60 seconds ago:All four calls should throw
TokenExpiredError. A string such as'false'(for example, read from an environment variable) is truthy, so the expiration check is skipped.clockTolerancevalues that are not finite numbers make the comparisonclockTimestamp >= exp + clockToleranceevaluate tofalse, so the token never expires.This PR adds the missing validation at the top of
verify(), next to the existing option checks and before the token is processed:clockTolerancemust be a finite number, otherwiseJsonWebTokenError: clockTolerance must be a finite number.ignoreExpirationandignoreNotBeforemust be booleans when defined, otherwiseJsonWebTokenError: <option> must be a boolean.Errors are returned through the callback when one is given, and thrown otherwise, consistent with the existing option validations.
Breaking changes. This is a behavior change for callers that pass invalid values today:
NaN,±Infinityandnullvalues forclockToleranceare now rejected. Before,nullbehaved like0.ignoreExpirationandignoreNotBefore(such as0,1,'true',{}) are now rejected. Valid callers (true,falseor the option omitted) are unaffected.Alternatives considered. Coercing the values (for example
'false'tofalse) was rejected because it would hide the configuration error instead of reporting it. Moving all validation to a schema likesign()uses is a larger refactor and is left out of this PR.Out of scope. Rejecting unknown option names (for example the typo
algoritms) is tracked as a separate change (HU-03). The test file already includes its 3 test cases, which still fail in this PR on purpose.References
sign():sign_options_schemainsign.js.Testing
New file:
test/verify-options-validation.test.js(27 cases), written before the implementation and run first to confirm it failed (24 failing, 3 passing).