-
Notifications
You must be signed in to change notification settings - Fork 43
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
Allow use of URL-namespaced claims #94
base: master
Are you sure you want to change the base?
Conversation
Kept as a separate commit to avoid complicating the review
Private namespaced claims are recommended to be prefixed with URLs, but having dots in domain names means that working out nested key structure by splitting on dots doesn't work. Instead we assume that if a claim starts with http:// or https:// then everything up to the third slash is part of the top-level key So https://example.com/nested.claims.key gets treated as https://example.com/nested -> claims -> key
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: willthames The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Hi @willthames. Thanks for your PR. I'm waiting for a google member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
I'll mark this as draft while I work on getting the CLA sorted. |
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.
Private namespaced claims are recommended to be prefixed with URLs
Can you link to a specification that mentions this?
@@ -520,27 +521,31 @@ TEST(JwtParseTest, GoodNestedJwt) { | |||
* "key-3": true, | |||
* "key-4": 9999 | |||
* } | |||
* } | |||
* }, |
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.
Can you add assertions to the test to verify these are accessible from the Jwt
object?
Also suggest you add a few corner cases to this token, such as URL with escaped /
characters, malformed URLs, etc.
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.
Haha, I went to a lot of effort to get the JWT token updated with the new claims and then somehow managed to not commit the tests that used it.
Added standard happy-path tests for now
// would be {"https://example.com/claims", "nested", "key"} | ||
if (absl::StartsWith(nested_names, "http://") || | ||
absl::StartsWith(nested_names, "https://")) { | ||
const std::vector<std::string> url_components = |
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.
I'm wary of doing this URL parsing manually with string manipulation instead of using an actual URL parser.
There's many things that can go wrong. At the very least, we should at least unescape the URL as %2F
is the same as /
.
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.
While that's not wrong, I am thinking: Is there ever a situation where the contents of the token could potentially be URLencoded after having been b64-decoded from the Authorization
header? Other than some user error maybe. And in that case, don't we want to fail because the token is not properly formatted?
Or is the assumption that the token is always obtained from said header wrong, for this use case, and we could actually run into this issue AND still want to process it as valid?
EDIT:
Actually, now that I'm revisiting this, I DO have one concern: What if the claim is a "url-like" string, but not starting with http://
or https://
, something like example.org/some_claim
instead of http://example.org/some_claim
? What then? Gracefully fail or let it try to unnest?
/ok-to-test |
https://auth0.com/docs/secure/tokens/json-web-tokens/create-custom-claims#namespaced-guidelines See also quarkusio/quarkus#26185 for a similar issue in another library It might only be auth0 who recommend this, but auth0 are a major advocate of JWT (they seem to be behind jwt.io for example) |
I ran into this issue while trying to extract namespaced JWT claims into headers with envoy. The JWT RFC (https://datatracker.ietf.org/doc/html/rfc7519#section-4.2) mentions using a domain name as a "Collision-Resistant Name" for claims and includes an example elsewhere using a domain namespaced claim: {
"iss":"joe",
"exp":1300819380,
"http://example.com/is_root":true
} |
I also ran into this issue with Envoy and have been trying to figure out a way to handle this. |
Private namespaced claims are recommended to be prefixed with URLs,
but having dots in domain names means that working out nested key
structure by splitting on dots doesn't work.
Instead we assume that if a claim starts with http:// or https://
then everything up to the third slash is part of the top-level key
So https://example.com/nested.claims.key gets treated as
https://example.com/nested -> claims -> key