-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feat: add PS JWA support #573
Conversation
Nice 👏 🤔 Even if this is only available for certain node versions, this is not a breaking change because all consumers using current functionality can continue working the same. However, we have the problem of:
Could you take a look to those points? also to extend the current testing up to 11 (travis config) |
Not necessarily, to some extent PS verifying worked prior to this PR already (due to the RS/PS similarities). To my knowledge the behaviour before was undefined, where it is now well defined. That's a breaking change.
from the PR's .travis.yml
This is already testing 11 (current stable).
Not sure how to best approach this. Node versions are strictly checked during |
First of, +1 on this, secondly:
Per SEMVER specifications:
I strongly believe this is a case of a semver minor and not a breaking change. This will still work in Node version that do not support PS. |
I just tested your changes using Node 4 and Node 7, with these results:
Up to now (before your changes) if you try to sign using PS256 What I meant is, since it is not a breaking change, just there is no need to modify the travis config to accurate the node versions, you can use the "ifs" that I pasted from jwa repo for testing. |
If an application receives a PS signed token and attempts to validate it in versions not supporting it there will be an uncaught exception (worst case) because of the constants not being available and PS all of a sudden passing the jsonwebtoken algorithm validations if statements would therefore be needed in the code as well, not just the test suite hence, a breaking change, no? |
If you want to maintain backwards compatibility and include PS you could require it to be explicitly specified algorithm during verify rather than a default. Either that or throw a JsonWebTokenError with unsupported algo if unsupported. This should already be covered in existing applications. |
🤔 yeah you are right @panva @Nicholaiii the problem is the algorithm inference we have based on the key on Thoughts? |
If by "undefined" you meant "anything could happen", then the new version's behavior is still compatible with that. (If version 1 says doing X can cause anything to happen with no guarantees, and version 2 says doing X is guaranteed to do a specific thing, then that's not a breaking change. Code written against version 1 isn't following the API correctly if it expects doing X to reliably do a specific thing like throw an error.)
I might be misunderstanding the situation, but won't the token only be successfully verified if the application specified the PS algorithm as being supported and the correct private key? Why would the developer in that case pass an unsupported private key, and then consider it a breaking change when that private key starts being supported? (How would the application user get a signed JWT for an unused private key if it wasn't intended to be used?) Any new feature added to a library is in some sense a breaking change if there was already code in the wild trying to make use of the non-existent feature and then expecting a failure. If that was considered a breaking change by semver, then there wouldn't ever be anything that qualified as a non-breaking change for a minor version upgrade. |
Oh, if adding PS support caused the PS algorithm to automatically be inferred in some cases, then I can imagine how that would be a problem if the new version ever inferred differently than older ones. I didn't know this library did that. I assumed that the algorithm had to be specified always. (Is that documented? I scanned through the readme a few times.) Personally I'd expect that inferring the algorithm could be a source of footguns after seeing this be a source of issues in various JWT libraries. |
Unfortunately this would also be a breaking change as verify with PS algorithms already somewhat works in earlier versions. The thing is, since the use of constants isn't safeguarded in
same point as above
You are assuming the library is only used in closed & controlled environments. That is not true. A common use of jsonwebtoken is to secure public facing APIs and you simply do not control the inputs. Given that a malicious party could've sent a PS signature before and it worked (produced expected library error) and doesn't now (in node 4, causes an uncaught) - if a developer is handling specific library error prototypes only. Explicitly disallowing PS in the non applicable node versions breaks (altho probably not intended) someone verifying PS signatures already. Unfortunately new installations are already affected and run into unspecified behaviours - the jws update was released as minor, disregarding the fact that PS verifications worked before. |
Bottom line, @ziluvatar it's your call, i can change the PR to whatever you want but I wanted to make it visible that trying to maintain backwards node compatibility is introducing new breaking changes. And we got those introduced already since node-jws doesn't safeguard the use of constants for PS when they're not available. I'm not going to be affected by these breaking changes myself so |
updated as per @ziluvatar's wishes |
FWIW i retraced my steps and confirmed there's indeed no breaking change, if anything this PR will fix unexpected errors produced by the fact that |
Thanks @panva ! 👏 Released on v8.5.0 |
@panva Can you describe how you were using Also from the sounds of it, are you suggesting the current I'm happy to accept an issue or a PR from you on either of jws or jwa. |
No, the constants are just convenience, before the node crypto API didn't have an option to pass anything else but a PEM cert.
I realized ad acta that i already had a transient node-jwa dep version installed that supported PS. False 📢 |
the PS family of JSON Web Algorithms is supported in node.js versions ^6.12.0, not 7, and then >=8