Skip to content

Fix jwt sign#2473

Open
GCHQDeveloper581 wants to merge 5 commits into
gchq:masterfrom
GCHQDeveloper581:fix-jwt
Open

Fix jwt sign#2473
GCHQDeveloper581 wants to merge 5 commits into
gchq:masterfrom
GCHQDeveloper581:fix-jwt

Conversation

@GCHQDeveloper581
Copy link
Copy Markdown
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug report: JWT sign broken again

1 participant