Fix #1000: Prevent callback from being called twice on payload claim conflict#1011
Open
cobyfrombrooklyn-bot wants to merge 1 commit intoauth0:masterfrom
Open
Fix #1000: Prevent callback from being called twice on payload claim conflict#1011cobyfrombrooklyn-bot wants to merge 1 commit intoauth0:masterfrom
cobyfrombrooklyn-bot wants to merge 1 commit intoauth0:masterfrom
Conversation
When jwt.sign() was called with a callback and the payload had a claim that conflicted with an option (e.g., payload.iss + options.issuer), the callback was invoked twice: once with the error and once with a signed token. This happened because the options-to-payload mapping used forEach(), where 'return failure()' only returned from the forEach callback, not from the outer function. Execution continued to jws.createSign(). Replaced forEach with a for loop so 'return failure()' properly exits the sign function. Fixes auth0#1000
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.
When
jwt.sign()is called with a callback and the payload has a claim that conflicts with an option (e.g.,payload.iss+options.issuer), the callback was invoked twice: once with the error and once with a successfully signed token.Root Cause
The options-to-payload mapping at line 217 used
forEach(). Inside the forEach callback,return failure()only returns from the forEach callback function, not from the outersignfunction. So after the error callback fires, the forEach continues processing remaining keys, and then execution falls through tojws.createSign()which calls the callback again with a token.Fix
Replaced
forEachwith aforloop so thatreturn failure()properly exits thesignfunction, preventing the signing logic from executing after an error.Test
Added test in
async_sign.tests.js: "should call the callback only once with an error". It:issin payload andissuerin optionsWithout the fix, the callback fires twice (error + token). With the fix, it fires once (error only).
Full test suite: 512 passing, 1 pending. Tested locally on macOS ARM (Apple Silicon).
Fixes #1000