Skip to content

permit at+jwt typ header value in jwt access tokens #126687

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

Merged
merged 6 commits into from
Apr 15, 2025

Conversation

richard-dennehy
Copy link
Contributor

Resolves #119370

Permit at+jwt typ header values when parsing Access tokens, as required by RFC 9068.

We continue to accept typ = JWT or null to maintain backwards compatibility.

@richard-dennehy richard-dennehy added >enhancement :Security/Authentication Logging in, Usernames/passwords, Realms (Native/LDAP/AD/SAML/PKI/etc) Team:Security Meta label for security team labels Apr 11, 2025
@elasticsearchmachine
Copy link
Collaborator

Hi @richard-dennehy, I've created a changelog YAML for you.

Comment on lines 22 to 25
public static final JwtTypeValidator ID_TOKEN_INSTANCE = new JwtTypeValidator(JOSEObjectType.JWT, null);

// strictly speaking, this should only permit `at+jwt`, but removing the other two options is a breaking change
public static final JwtTypeValidator ACCESS_TOKEN_INSTANCE = new JwtTypeValidator(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

split validator into 2, as we don't want to allow at+jwt for ID tokens

@richard-dennehy richard-dennehy requested a review from n1v0lg April 11, 2025 13:37
@richard-dennehy richard-dennehy marked this pull request as ready for review April 11, 2025 13:37
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-security (Team:Security)

Copy link
Contributor

@n1v0lg n1v0lg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

For additional functional coverage, I'd also tweak one of our JWT REST tests (here) to randomly set a at+jwt header -- provided that it's an application token JWT. This will take a bit of tweaking to the method signature, i.e., something like a boolean flag allowAtJwtType.

Let's also open a backport to 8.19.

} catch (Exception e) {
throw new AssertionError("validation should have passed without exception", e);
}
}

public void testInvalidType() throws ParseException {
final JwtTypeValidator validator = randomFrom(JwtTypeValidator.ID_TOKEN_INSTANCE, JwtTypeValidator.ACCESS_TOKEN_INSTANCE);

final JWSHeader jwsHeader = JWSHeader.parse(
Map.of("typ", randomAlphaOfLengthBetween(4, 8), "alg", randomAlphaOfLengthBetween(3, 8))
Copy link
Contributor

@n1v0lg n1v0lg Apr 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also add AT+JWT here -- this case isn't captured by a random alpha string and seems like an edge-case worth explicitly covering as invalid.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

turns out the parser ignores case - I've added AT+JWT to the success test case instead

JOSEObjectType.JWT,
new JOSEObjectType("at+jwt"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: let's make this a private constant

@richard-dennehy richard-dennehy added auto-backport Automatically create backport pull requests when merged v8.19.0 labels Apr 14, 2025
@richard-dennehy richard-dennehy merged commit 9e3476e into elastic:main Apr 15, 2025
22 checks passed
@richard-dennehy richard-dennehy deleted the at+jwt-support branch April 15, 2025 10:08
@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
8.x

elasticsearchmachine added a commit that referenced this pull request Apr 15, 2025
* permit at+jwt typ header value in jwt access tokens

* Update docs/changelog/126687.yaml

* address review comments

* [CI] Auto commit changes from spotless

* update Type Validator tests for parser ignoring case

---------

Co-authored-by: elasticsearchmachine <[email protected]>
afoucret pushed a commit to afoucret/elasticsearch that referenced this pull request Apr 16, 2025
* permit at+jwt typ header value in jwt access tokens

* Update docs/changelog/126687.yaml

* address review comments

* [CI] Auto commit changes from spotless

* update Type Validator tests for parser ignoring case

---------

Co-authored-by: elasticsearchmachine <[email protected]>
leemthompo added a commit to elastic/docs-content that referenced this pull request Apr 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Automatically create backport pull requests when merged >enhancement :Security/Authentication Logging in, Usernames/passwords, Realms (Native/LDAP/AD/SAML/PKI/etc) Team:Security Meta label for security team v8.19.0 v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support at+jwt Types in JWT Realm
3 participants