fix: prevent double callback invocation on payload conflict#1016
Open
abhu85 wants to merge 1 commit intoauth0:masterfrom
Open
fix: prevent double callback invocation on payload conflict#1016abhu85 wants to merge 1 commit intoauth0:masterfrom
abhu85 wants to merge 1 commit intoauth0:masterfrom
Conversation
When jwt.sign() is called with a callback and the payload already contains a claim (iss, sub, aud, jti) that conflicts with a corresponding option (issuer, subject, audience, jwtid), the callback was being invoked twice: once with the error, and again with the signed token. Root cause: The forEach loop at lines 217-225 used 'return failure()' to report the error, but 'return' inside a forEach callback only exits that callback, not the outer function. The loop continued processing remaining keys, and execution proceeded to sign and return the token via callback. Fix: Replace forEach with a for...of loop so that 'return failure()' correctly exits the outer function immediately upon detecting a conflict. 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.
Summary
When
jwt.sign()is called with a callback and the payload already contains a claim (iss,sub,aud,jti) that conflicts with a corresponding option (issuer,subject,audience,jwtid), the callback was being invoked twice: once with the error, and again with the signed token.Root Cause
The
forEachloop atsign.js:217-225usedreturn failure()to report the error, butreturninside aforEachcallback only exits that callback function, not the outersign()function. The loop continued processing remaining keys, and execution proceeded to sign and return the token via callback.Fix
Replace
forEachwith afor...ofloop so thatreturn failure()correctly exits the outer function immediately upon detecting a conflict.Before
After
Test Plan
test/issue_1000.tests.jswith 9 test cases covering:Fixes #1000