-
Notifications
You must be signed in to change notification settings - Fork 149
fix: drop dependency on jwk-to-pem by using native crypto #1283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for endearing-brigadeiros-63f9d0 canceled.
|
This replaces jwk-to-pem with simply using crypto.createPublicKey. This further drops elliptic from the dependency tree, which has known security issues (note this is mostly for hygiene as jwk-to-pem doesn't use the vulnerable code paths, per Brightspace/node-jwk-to-pem#187).
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1283 +/- ##
=======================================
Coverage 83.35% 83.35%
=======================================
Files 70 70
Lines 3004 3004
Branches 499 499
=======================================
Hits 2504 2504
Misses 397 397
Partials 103 103 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
jescalada
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! I added a test that uses crypto.createPublicKey, but it still injects the getJwks stub function for validateJwt. Do you think this is sufficient? @dgl
it('should validate a JWT generated with crypto.createPublicKey', async () => {
const { privateKey, publicKey } = generateRsaKeyPair();
const jwk = publicKeyToJwk(publicKey, 'my-kid');
const tokenPayload = jwt.sign(
{
sub: 'user123',
azp: 'client-id',
admin: 'admin',
},
privateKey,
{
algorithm: 'RS256',
issuer: 'https://issuer.com',
audience: 'client-id',
keyid: 'my-kid',
}
);
const getJwksStub = sinon.stub().resolves([jwk]);
const { verifiedPayload, error } = await validateJwt(
tokenPayload,
'https://issuer.com',
'client-id',
'client-id',
getJwksStub
);
expect(error).to.be.null;
expect(verifiedPayload.sub).to.equal('user123');
expect(verifiedPayload.admin).to.equal('admin');
});
This replaces jwk-to-pem with simply using crypto.createPublicKey. This further drops elliptic from the dependency tree, which has known security issues (note this is mostly for hygiene as jwk-to-pem doesn't use the vulnerable code paths, per
Brightspace/node-jwk-to-pem#187).