Padding in Base64-encoded header/payload #1324
byronwolfman
started this conversation in
General
Replies: 1 comment 9 replies
-
|
@byronwolfman thanks. At first glance I'm okay with some sort of new option like |
Beta Was this translation helpful? Give feedback.
9 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I recently became aware that JWTs issued by AWS Application Load Balancers are technically not spec-compliant, in that the base64-encoded components include padding:
(via this doc on ALB user claims encoding and signature validation.)
The jwx v2 and v3 libraries therefore cannot verify these tokens, because when
Parse()is called, the header and payload are decoded (successfully, regardless of padding) but then re-encoded without padding for the sake of the signature check. The signature applies to the padded version though, so the re-encoded (and unpadded) versions fail verification. To be clear I do not view this as a bug in jwx, nor do I expect it to automatically carve out a special case. I've been reading some of the other discussions here and see a strong commitment to following the spec, which I appreciate, given that this problem stems from an implementation that does not respect the spec.What I'm wondering is if there's a recommendation on the "best" (or at least, least bad) way of dealing with padding in JWTs. Right now my approach is to manually verify the header+payload without jwx, and then call
jwt.WithVerify(false). It's a few extra steps, but it works. I wonder if there's appetite though for options such asjwt.WithPadding(bool)orjwt.WithEncoding(*base64.Encoding)I'm not convinced that adding these new options is a good idea though. Both essentially invite users to generate non-spec-conforming JWTs of their own, even accidentally (one wonders if ALBs ended up in this category). On the other hand, my approach with option 1 is to copy out portions of *ecdsaVerifier.Verify() to call directly before calling
jwt.Parse()and while it works, it also seems kind of crude. I haven't found a way to callVerifydirectly (which I suspect is intentional) but if there were a way, then I suppose that would be the easiest onramp.Anyway I'd love to hear if you think any of these are viable. If the answer is no, then that's all right too.
Thanks for an excellent library all the same.
Beta Was this translation helpful? Give feedback.
All reactions