Skip to content

Validate OAuth and JWKS endpoint URLs - #2252

Open
sdelamo wants to merge 7 commits into
5.3.xfrom
foo
Open

Validate OAuth and JWKS endpoint URLs#2252
sdelamo wants to merge 7 commits into
5.3.xfrom
foo

Conversation

@sdelamo

@sdelamo sdelamo commented Jul 14, 2026

Copy link
Copy Markdown
Member

This changes micronaut-security-jwt and micronaut-security-oauth2 to depend on Micronaut Validation instead of just depending on jakarta.validation-api.

The changes uses the @URL annotation from Micronaut validation to reject invalid JWKS and OAuth endpoint URLs during configuration binding. This enforces absolute HTTP(S) URLs across OAuth endpoint settings and OpenID JWKS URIs, wires nested endpoint validation, and updates tests and dependencies to cover accepted and rejected URL values.

Close: #2245
Close: #2179

lissam1 and others added 4 commits July 8, 2026 15:19
This changes micronaut-security-jwt and oauth2 to depend on Micronaut Validation instead of just depending on `jakarta.validation-api`.

The changes uses the `@URL` annotation from Micronaut validation to reject invalid JWKS and OAuth endpoint URLs during configuration binding. This enforces absolute HTTP(S) URLs across OAuth endpoint settings and OpenID JWKS URIs, wires nested endpoint validation, and updates tests and dependencies to cover accepted and rejected URL values.

Close: #2245
Close: #2179
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 14, 2026 10:37
@sdelamo sdelamo added the type: improvement A minor improvement to an existing feature label Jul 14, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR moves OAuth2 and JWT modules from relying on jakarta.validation-api to using Micronaut Validation so invalid OAuth endpoint URLs and JWKS URIs are rejected early during configuration binding.

Changes:

  • Add Micronaut @URL validation to OAuth endpoint configuration URLs and OpenID jwks-uri, and cascade validation into nested endpoint configs via @Valid.
  • Add/adjust tests to cover accepted and rejected URL values (OAuth2 + JWKS signature configuration).
  • Update module dependencies to use mnValidation.micronaut.validation and bump the Micronaut platform version catalog.

Reviewed changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
security-oauth2/src/test/java/io/micronaut/security/oauth2/configuration/OauthClientConfigurationTest.java Adds validation-focused tests for OAuth endpoint URLs and OpenID JWKS URI.
security-oauth2/src/test/groovy/io/micronaut/security/oauth2/client/condition/PasswordGrantConditionSpec.groovy Fixes a previously-invalid OpenID token URL test input to match new URL validation.
security-oauth2/src/main/java/io/micronaut/security/oauth2/configuration/OauthClientConfigurationProperties.java Cascades validation into nested endpoint configuration and validates openid.jwks-uri.
security-oauth2/src/main/java/io/micronaut/security/oauth2/configuration/OauthClientConfiguration.java Minor formatting/indent adjustment (no behavioral change).
security-oauth2/src/main/java/io/micronaut/security/oauth2/configuration/endpoints/EndpointConfiguration.java Adds @URL constraint to the endpoint URL contract and provides a shared http/https regex.
security-oauth2/build.gradle.kts Switches to Micronaut Validation as an API dependency for oauth2 module.
security-jwt/src/test/java/io/micronaut/security/token/jwt/signature/jwks/JwksSignatureConfigurationPropertiesTest.java Adds coverage ensuring invalid JWKS signature URLs fail during context startup/binding.
security-jwt/src/test/groovy/io/micronaut/security/token/jwt/signature/jwks/JwksProxySpec.groovy Updates JWKS URL test configuration to use an absolute URL.
security-jwt/src/main/java/io/micronaut/security/token/jwt/signature/jwks/JwksSignatureConfigurationProperties.java Adds @URL validation to the configured JWKS signature URL.
security-jwt/build.gradle.kts Switches to Micronaut Validation as an API dependency for jwt module.
gradle/libs.versions.toml Bumps micronaut-platform version to 5.0.4.

sdelamo and others added 2 commits July 14, 2026 13:06
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@sonarqubecloud

Copy link
Copy Markdown

@sdelamo
sdelamo requested review from dstepanov and lissam1 July 14, 2026 13:51
@sdelamo

sdelamo commented Jul 14, 2026

Copy link
Copy Markdown
Member Author

@dstepanov I am a bit worried about making Micronaut Validation a dependency of security. Unfortunately, Micronaut Validation annotations are not in a separate dependency.

@sdelamo
sdelamo requested a review from graemerocher July 15, 2026 07:29
* @since 1.2.0
*/
public interface EndpointConfiguration {
String HTTP_OR_HTTPS_URL_REGEX = "(?i)https?://.*";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

probably worth adding javadoc to this public constant

Comment on lines +533 to +537
private @Valid RegistrationEndpointConfigurationProperties registration;
private @Valid UserInfoEndpointConfigurationProperties userInfo;
private @Valid AuthorizationEndpointConfigurationProperties authorization;
private @Valid TokenEndpointConfigurationProperties token;
private @Valid EndSessionConfigurationProperties endSession = new EndSessionConfigurationProperties();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

since this cascades validation down, maybe you want to add more tests for different validation use cases

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

Labels

type: improvement A minor improvement to an existing feature

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

Improve Error messages on OAuth verification

4 participants