Fix jwt sign#2473
Open
GCHQDeveloper581 wants to merge 5 commits into
Open
Conversation
…ad header parameter
…on to convert pkcs1 to pkcs8
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
Fix #2434 (JWT Sign broken) by replacing jsonwebtoken library with the more modern jose.
As per comments in #1768 jsonwebtoken is essentially broken for browser usage and there seems little appetite for the maintainers to resolve this - see auth0/node-jsonwebtoken#892 , auth0/node-jsonwebtoken#939. The older version now has security vulnerabilities so downgrading is no longer a real option.
The library swap is mostly straightforward, with the only significant complexity being caused by JOSE not accepting PKCS1 format RSA Private Keys. There doesn't appear to be any commonly available library to do this that functions in both Node and Browser, so a relatively simple conversion utility has been added to convert from PKCS1 to PKCS8 format.
Existing Issue
Fixes #2434, which mirrors an old issue, #1768.
New issue #2472 has been raised to cover the work to convert the remaining uses of jsonwebtoken. That has not been done as part of this PR so as to keep the incremental changes smaller.
AI disclosure
GPT 5 was used to assist with writing the PKCS1 to PKCS8 conversion. The convertor code is relatively straightforward. It lacks higher degrees of error checking but any errors will be caught by the PKCS8 parsing that happens afterwards.
Test Coverage
Existing functional tests pass with minimal changes to the Edge/Error case tests to account for the different error reporting.
A new functional test has been added to test for the added handling of errors in the user-supplied header.
A basic "sunny day" browser test has also been added to catch any future regressions in in-browser use.