Skip to content
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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

willthames
Copy link

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

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
@google-cla
Copy link

google-cla bot commented Mar 28, 2023

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.

@google-oss-prow
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: willthames
Once this PR has been reviewed and has the lgtm label, please assign nareddyt for approval. For more information see the Kubernetes Code Review Process.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@google-oss-prow
Copy link

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@willthames
Copy link
Author

I'll mark this as draft while I work on getting the CLA sorted.

@nareddyt nareddyt self-requested a review March 30, 2023 19:18
Copy link
Contributor

@nareddyt nareddyt left a 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
* }
* }
* },
Copy link
Contributor

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.

Copy link
Author

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 =
Copy link
Contributor

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 /.

abseil/abseil-cpp#158 (comment)

Copy link

@CelsoSantos CelsoSantos Oct 4, 2024

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?

@nareddyt
Copy link
Contributor

/ok-to-test

@willthames
Copy link
Author

Private namespaced claims are recommended to be prefixed with URLs

Can you link to a specification that mentions this?

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)

@jgorinsky
Copy link

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
}

@CelsoSantos
Copy link

I also ran into this issue with Envoy and have been trying to figure out a way to handle this.
For Envoy it's not critical because we can use Lua scripting/filters to process the claim and place it in a header, but to solve this within Envoy source "natively" it would be way better if this lib had the support rather than having to work around it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants