-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
add(std/jwt): Implement the new jwt module #7991
Conversation
@kitsonk ready for a second review. |
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.
LGTM, thanks for addressing all the feedback!!!
I only stumbled on this issue because i was checking up on webcrypto presence in deno. Having some experience with JOSE as a whole i wanted to check what std jwt module may look like. With no disrespect towards the authors whatsoever, everyone involved has my upmost respect for contributing to open source, I think maybe this should be reverted - or at the very least further worked on until being released as std.
I'm rewriting my jose module into a new universal ESM module with TS (wip here), so once Web Crypto API lands in Deno, it'll be long ready and released (with no dependencies this time). This new universal module (and the current node-specific version too) comes with almost all of JOSE (as long as supported by Web Crypto API), not just JWT, but also JWS, JWE, JWK, Flattened and General serializations, etc... Again thank you all for the time invested here. But as a developer I would be looking for a different kind of module in a std.
|
A lot of words but little substance. I am sure the deno devs will be happy to accept your PR, if it satisfies their conditions, in the future. |
I understand your defensive response, being the proud author of the module, I also want to reiterate, because this can never be said enough - thank you for being a fellow open source maintainer and I mean no disrespect or to offend here.
Substance is there, just please consider not taking this as an attack that you need to somehow defend, but rather me trying to help point this module in a better, more secure future proof direction. |
@panva thank you for your feedback... we will discuss internally and figure out what to do. |
@kitsonk thank you for considering my feedback valuable. Good luck, stay safe. |
Edit: I think you implied that an algorithm would not have to be specified, meaning even |
I checked the readme docs. Entirely my fault clearly. Who reads docs anymore. Anyway, @kitsonk if you wish to discuss around some of the more high level points, please let me know and i can join discord/slack/whatever. |
This reverts commit 034ab48.
Hei @panva Thank you for your concern raising. @timonson and I will work on a patch. What did you mean exactly by
? The spec demands the implementation of |
The key material type passed in should be responsible for what algorithm is "allowed". When Uint8Array is passed in as key - only HMAC algs can be used, when ECDSA key object is passed in there's always only one algorithm (mapped per EC key curve). When RSA key object key is passed in - only RSASSA-PKCS1-v1_5 or RSASSA-PSS can be used. The list of algorithms can then be further limited by providing the algorithms option, but the algorithms should never stray from what a given key is capable of verifying/signing. Why HS512 is a bad default and string is a bad idea? Because someone eventually will pass in a PEM public key thinking they're verifying e.g. PS256 but its the octets of the key used for HMAC instead. Hence - key object representation. Uint8Array for secrets, CryptoKey (when available) for everything else. Since it's currently only in scope to do HMAC - you only have one key type to worry about, but please, don't make string a valid input, have developers pass in a Uint8Array instance. (note: getting Uint8Array out of a string is as simple as Once Web Crypto API is supported by Deno, you'll be have the other public/private key objects native to your runtime. As far as "none" goes. If you feel like you MUST support it to be spec conform, then make "none" a special kind of key object representation. E.g. a singleton like i've done here. Only when this key is passed in can "none" JWTs be "verified" or "signed". I've been dealing with JOSE for a very long time so this feedback / these suggestions come from a great deal of experience, especially in the node/browser JS ecosystems. Mixing "none" with the rest of the secure API is inherently a bad idea, going with a special "none" key object is the least amount of work (and goes in line with the general idea of "key type drives the algorithms", alternatively - provide a completely different API just for "none" alg validation. As an aside: to be 100% conform for HMAC algorithms you also must ensure that the key is at least the bitsize of the HMAC algorithm blocksize - so >=256 bits for HS256, >=384 bits for HS384, >=512 bits for HS512. |
There are WebAPIs on which a more complete JWT could be build once available. https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API |
@panva
|
There are two sides to this - one - the key passed in, two - the algorithms option. Unless you want to be dealing with edge cases where Uint8Array key is passed in but algorithms option lists "none", go with a key object instead.
It doesn't, usually when keys are shorter they get padded to the required size, when they're longer, they're automatically hashed by the HMAC implementation. |
Co-authored-by: Tim Reichen <[email protected]>
Co-authored-by: Tim Reichen <[email protected]>
Co-authored-by: Tim Reichen <[email protected]>
Co-authored-by: Tim Reichen <[email protected]>
Co-authored-by: Tim Reichen <[email protected]>
Co-authored-by: Tim Reichen <[email protected]>
Co-authored-by: Tim Reichen <[email protected]>
Co-authored-by: Tim Reichen <[email protected]>
Co-authored-by: Tim Reichen <[email protected]>
With the release of Deno v1.18 https://deno.land/x/jose can now be considered stable and safe to use. I am aware it is not a |
This PR contains the new
std/jwt
module and therefore closes #7771 .@timreichen and I put equal amounts of work into this. So big Thank you to him!
A few additional things to consider:
Although not necessary now,
verify
andcreate
return promises because weexpect coming encryption functions to return promises in the future. E.g. for
RSA
algorithms.This application uses the JWS Compact Serialization according to the
JWS specification.