-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
Issue with JWK Validation: Leading Zero in Coordinates #18
Comments
Hello, thank you for opening this issue. Are you able to share where you got this JWK from? If it's a public vendor such as an AWS product, Okta, Auth0, etc, I would like to send them an email regarding RFC compliance. The reason this happened is because the JWK being used is non-RFC compliant regarding padding with leading zeros. Please see this note in the README.md and these lines of RFC 7518:
I know saying "the JWK is non-RFC compliant" isn't a satisfying answer. I plan on adding a work-around for non-RFC compliant JWK with leading padding similar to the trailing padding issue. Unfortunately, this is unlikely to happen today, but is likely to happen before the week is over. Edit: |
Hello @MicahParks and thank you for your quick reply! Yes I can share that - the JWK comes from backstage: https://github.com/backstage/backstage If I hear something different or have any updates I will come back to you on this. I completely agree and would equally ask them to change their method of creating JWKs as they are not RFC compliant. That would be great, thank you very much! Kind regards, |
Hi @MicahParks, I took a look at the RFC 7518. I might be missing something since I did not read it fully, but to me the section on the
As far as I can see the Again I may be totally wrong here because I only looked for that term. |
@raskad thank you for politely pointing that out. It does look like these JWK parameters are defined by I'm going to mark this issue as bug. |
It's a shame that the RFC did not define some of these JWK parameters as Looking at The new validation method I'm working on will be comparing the affected JWK parameters |
That was also my first idea when I took a look at the code.
From my reading of the descriptions of |
@raskad I think the line you pointed out from RFC 7518 Section 6.2.1.2 is likely something I overlooked when implemented the affected portion of JWK.
If I am reading this correctly and remember what exists in the code base today. I also need to check how JWK parameters that are marked as I am going to sign off for the night, but plan on looking at this further tomorrow. If you want to take a peek at the work-in-progress branch, you can find that here: jwk-validation-rework. I am not attached to this WIP branch. Suggestions or pull requests that take a different approach are welcome. |
Addressing a subset of the questions posed by this issue is this PR: #19 The PR is meant to comply with the octet length requirements for ECDSA JWK parameters as discussed in this issue. I encourage any interested parties to review, comment, and emoji react on the PR. I am still investigating |
Please see the newly release version I've made two new issues relevant to this discussion.
|
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [github.com/MicahParks/jwkset](https://togithub.com/MicahParks/jwkset) | `v0.5.12` -> `v0.5.13` | [![age](https://developer.mend.io/api/mc/badges/age/go/github.com%2fMicahParks%2fjwkset/v0.5.13?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/go/github.com%2fMicahParks%2fjwkset/v0.5.13?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/go/github.com%2fMicahParks%2fjwkset/v0.5.12/v0.5.13?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/go/github.com%2fMicahParks%2fjwkset/v0.5.12/v0.5.13?slim=true)](https://docs.renovatebot.com/merge-confidence/) | | [github.com/aws/aws-sdk-go](https://togithub.com/aws/aws-sdk-go) | `v1.50.30` -> `v1.50.31` | [![age](https://developer.mend.io/api/mc/badges/age/go/github.com%2faws%2faws-sdk-go/v1.50.31?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/go/github.com%2faws%2faws-sdk-go/v1.50.31?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/go/github.com%2faws%2faws-sdk-go/v1.50.30/v1.50.31?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/go/github.com%2faws%2faws-sdk-go/v1.50.30/v1.50.31?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>MicahParks/jwkset (github.com/MicahParks/jwkset)</summary> ### [`v0.5.13`](https://togithub.com/MicahParks/jwkset/releases/tag/v0.5.13) [Compare Source](https://togithub.com/MicahParks/jwkset/compare/v0.5.12...v0.5.13) The purpose of this release is to correctly pad EC JWK parameters with leading zeros where required by RFC 7518. For `"x"` and `"y"`: > The length of this octet string MUST be the full size of a coordinate for the curve specified in the "crv" parameter. For example, if the value of "crv" is "P-521", the octet string must be 66 octets long. For `"d"`: > The length of this octet string MUST be ceiling(log-base-2(n)/8) octets (where n is the order of the curve). This is to bring the project into RFC compliance with RFC 7518 Section [6.2.1.2](https://datatracker.ietf.org/doc/html/rfc7518#section-6.2.1.2), [6.2.1.3](https://datatracker.ietf.org/doc/html/rfc7518#section-6.2.1.3), and [6.2.2.1](https://datatracker.ietf.org/doc/html/rfc7518#section-6.2.2.1). Relevant issues: - [https://github.com/MicahParks/jwkset/issues/18](https://togithub.com/MicahParks/jwkset/issues/18) #### What's Changed - Required leading zeros in ECDSA keys by [@​MicahParks](https://togithub.com/MicahParks) in [https://github.com/MicahParks/jwkset/pull/19](https://togithub.com/MicahParks/jwkset/pull/19) **Full Changelog**: MicahParks/jwkset@v0.5.12...v0.5.13 </details> <details> <summary>aws/aws-sdk-go (github.com/aws/aws-sdk-go)</summary> ### [`v1.50.31`](https://togithub.com/aws/aws-sdk-go/blob/HEAD/CHANGELOG.md#Release-v15031-2024-03-04) [Compare Source](https://togithub.com/aws/aws-sdk-go/compare/v1.50.30...v1.50.31) \=== ##### Service Client Updates - `service/cloudformation`: Updates service API and documentation - Add DetailedStatus field to DescribeStackEvents and DescribeStacks APIs - `service/fsx`: Updates service API and documentation - `service/organizations`: Updates service API and documentation - Documentation update for AWS Organizations </details> --- ### Configuration 📅 **Schedule**: Branch creation - "after 10pm every weekday,before 5am every weekday,every weekend" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 👻 **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://togithub.com/renovatebot/renovate/discussions) if that's undesired. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/nobl9/nobl9-go). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yMjAuMiIsInVwZGF0ZWRJblZlciI6IjM3LjIyMC4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Hi again @MicahParks, thanks for your update and the new version, we appreciate you work! That would help us too. Thanks and kind regards! |
@Useserall please see Edit, actually use |
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [github.com/MicahParks/jwkset](https://togithub.com/MicahParks/jwkset) | `v0.5.14` -> `v0.5.15` | [![age](https://developer.mend.io/api/mc/badges/age/go/github.com%2fMicahParks%2fjwkset/v0.5.15?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/go/github.com%2fMicahParks%2fjwkset/v0.5.15?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/go/github.com%2fMicahParks%2fjwkset/v0.5.14/v0.5.15?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/go/github.com%2fMicahParks%2fjwkset/v0.5.14/v0.5.15?slim=true)](https://docs.renovatebot.com/merge-confidence/) | | [github.com/MicahParks/keyfunc/v3](https://togithub.com/MicahParks/keyfunc) | `v3.2.8` -> `v3.2.9` | [![age](https://developer.mend.io/api/mc/badges/age/go/github.com%2fMicahParks%2fkeyfunc%2fv3/v3.2.9?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/go/github.com%2fMicahParks%2fkeyfunc%2fv3/v3.2.9?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/go/github.com%2fMicahParks%2fkeyfunc%2fv3/v3.2.8/v3.2.9?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/go/github.com%2fMicahParks%2fkeyfunc%2fv3/v3.2.8/v3.2.9?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>MicahParks/jwkset (github.com/MicahParks/jwkset)</summary> ### [`v0.5.15`](https://togithub.com/MicahParks/jwkset/releases/tag/v0.5.15): Less strict validation [Compare Source](https://togithub.com/MicahParks/jwkset/compare/v0.5.14...v0.5.15) The purpose of this release is to use less strict validation for JWK. This will allow users to work with non-RFC compliant JWK Sets for small padding mistakes. Two padding related reasons for this are: 1. Mandatory leading padding for ECDSA JWK parameters. 2. A common mistake adding leading padding to RSA JWK parameter "n". For padding specifically, this project is only comparing integers after they are parsed from Base64 raw URL encoding by default. To turn on strict validation, there will be a new field on jwkset.ValidateOptions named StrictPadding. An example for `1` would be a bug in this project were mandatory leading padding was absent: [https://github.com/MicahParks/jwkset/issues/18](https://togithub.com/MicahParks/jwkset/issues/18) An example for `2` would be a Firebase service that was reported to be incompatible with this project: [https://github.com/MicahParks/jwkset/issues/23](https://togithub.com/MicahParks/jwkset/issues/23) Relevant issues: - [https://github.com/MicahParks/jwkset/issues/23](https://togithub.com/MicahParks/jwkset/issues/23) - [https://github.com/MicahParks/jwkset/issues/20](https://togithub.com/MicahParks/jwkset/issues/20) - [https://github.com/MicahParks/jwkset/issues/18](https://togithub.com/MicahParks/jwkset/issues/18) Relevant pull requests: - [https://github.com/MicahParks/jwkset/pull/24](https://togithub.com/MicahParks/jwkset/pull/24) </details> <details> <summary>MicahParks/keyfunc (github.com/MicahParks/keyfunc/v3)</summary> ### [`v3.2.9`](https://togithub.com/MicahParks/keyfunc/compare/v3.2.8...v3.2.9) [Compare Source](https://togithub.com/MicahParks/keyfunc/compare/v3.2.8...v3.2.9) </details> --- ### Configuration 📅 **Schedule**: Branch creation - "after 10pm every weekday,before 5am every weekday,every weekend" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 👻 **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://togithub.com/renovatebot/renovate/discussions) if that's undesired. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/nobl9/nobl9-go). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yMzAuMCIsInVwZGF0ZWRJblZlciI6IjM3LjIzMC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
With the newest release, |
We have encountered a problem where loading JSON Web Keys (JWKs) results in the following error message:
"failed to validate JSON Web Key: failed to validate JWK: marshaled JWK does not match original JWK"
The JWK is set as follows:
Upon investigation, we found that the problem lies in one of the key coordinates starting with a leading zero. For example:
The x coordinate starts with "ALTu..." After the coordinate is changed with the following function
jwkset/marshal.go
Line 485 in b0b8e8b
[0 180 238...]
However, after calling Set.Bytes() on this value, the leading zero disappears..
jwkset/marshal.go
Line 231 in b0b8e8b
When converting the result back to bytes we see the following result:
[180 238...]
This discrepancy leads to the original error message because the deepEqual check here no longer validates correctly.
jwkset/jwk.go
Line 311 in b0b8e8b
We recommend addressing this issue by ensuring consistent handling of leading zeros in key coordinates during JWK validation.
We hope to hear soon from you!
Kind regards,
Hauke
The text was updated successfully, but these errors were encountered: