[java-idp-oidc] 03/03: Improved catching of illegal/unexpected value formats/contents
Codeberg
noreply at shibboleth.net
Mon Nov 23 13:02:31 UTC 2026
This is an automated email from the git hooks/post-receive script.
codeberg pushed a commit to branch main
in repository java-idp-oidc.
View the commit online:
https://codeberg.org/Shibboleth/java-idp-oidc/commit/642fdb0e21aa46e7f6c28a6ef1f050b2d89ecc8d
commit 642fdb0e21aa46e7f6c28a6ef1f050b2d89ecc8d
Author: Henri Mikkonen <henri.mikkonen at iki.fi>
AuthorDate: Mon Nov 23 15:01:11 2026 +0200
Improved catching of illegal/unexpected value formats/contents
---
.../oidc/op/token/support/TokenClaimsSet.java | 7 ++-
.../admin/impl/IssueRegistrationAccessToken.java | 52 +++++++++++++---------
.../oauth2/profile/impl/ValidateRequestObject.java | 48 +++++++++++++-------
3 files changed, 67 insertions(+), 40 deletions(-)
diff --git a/idp-oidc-extension-api/src/main/java/net/shibboleth/idp/plugin/oidc/op/token/support/TokenClaimsSet.java b/idp-oidc-extension-api/src/main/java/net/shibboleth/idp/plugin/oidc/op/token/support/TokenClaimsSet.java
index b5e5ed1d..8f0a7292 100644
--- a/idp-oidc-extension-api/src/main/java/net/shibboleth/idp/plugin/oidc/op/token/support/TokenClaimsSet.java
+++ b/idp-oidc-extension-api/src/main/java/net/shibboleth/idp/plugin/oidc/op/token/support/TokenClaimsSet.java
@@ -49,6 +49,7 @@ import net.shibboleth.shared.security.DataSealerException;
import net.shibboleth.shared.security.IdentifierGenerationStrategy;
import java.net.URI;
+import java.net.URISyntaxException;
import java.text.ParseException;
import java.time.Instant;
@@ -374,8 +375,10 @@ public class TokenClaimsSet {
*/
@Nullable public URI getRedirectURI() {
try {
- return URI.create(assertedClaimsSet().getStringClaim(KEY_REDIRECT_URI));
- } catch (final ParseException|IllegalArgumentException e) {
+ if (assertedClaimsSet().getClaim(KEY_REDIRECT_URI) != null) {
+ return new URI(assertedClaimsSet().getStringClaim(KEY_REDIRECT_URI));
+ }
+ } catch (final ParseException|IllegalArgumentException | URISyntaxException e) {
log.error("error parsing redirect uri from token", e.getMessage());
}
// should never happen, programming error.
diff --git a/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/admin/impl/IssueRegistrationAccessToken.java b/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/admin/impl/IssueRegistrationAccessToken.java
index 51e1a269..be4f3f4e 100644
--- a/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/admin/impl/IssueRegistrationAccessToken.java
+++ b/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/admin/impl/IssueRegistrationAccessToken.java
@@ -397,33 +397,43 @@ public class IssueRegistrationAccessToken extends AbstractAdminApiProfileAction
"Invalid Request", "No metadata policy or policy ID could be resolved.");
return false;
}
+
+ clientId = clientIdLookupStrategy.apply(profileRequestContext);
+
+ final String lifetimeString = tokenLifetimeLookupStrategy.apply(profileRequestContext);
+ if (lifetimeString != null) {
+ try {
+ final Duration lifetime = Duration.parse(lifetimeString);
+ assert lifetime != null;
+ if (lifetime.isNegative() || lifetime.isZero()) {
+ log.warn("{} Token lifetime was not positive: {}", getLogPrefix(), lifetime);
+ sendError(HttpServletResponse.SC_BAD_REQUEST,
+ "Invalid Request", "Token lifetime was not positive.");
+ return false;
+ }
+ if (lifetime.compareTo(defaultTokenLifetime) > 0) {
+ log.warn("{} Requested token lifetime greater than default, lowering to default",
+ getLogPrefix());
+ tokenLifetime = defaultTokenLifetime;
+ } else {
+ tokenLifetime = lifetime;
+ }
+ } catch (final DateTimeParseException e) {
+ log.warn("{} Token lifetime was not in a supported format", getLogPrefix(), e);
+ sendError(HttpServletResponse.SC_BAD_REQUEST,
+ "Invalid Request", "Token lifetime was not in a supported format.");
+ return false;
+ }
+ } else {
+ log.debug("{} No token lifetime specified, using default", getLogPrefix());
+ tokenLifetime = defaultTokenLifetime;
+ }
} catch (final IOException e) {
log.error("{} I/O error issuing API response", getLogPrefix(), e);
ActionSupport.buildEvent(profileRequestContext, EventIds.IO_ERROR);
return false;
}
- clientId = clientIdLookupStrategy.apply(profileRequestContext);
-
- final String lifetimeString = tokenLifetimeLookupStrategy.apply(profileRequestContext);
- if (lifetimeString != null) {
- try {
- final Duration lifetime = Duration.parse(lifetimeString);
- assert lifetime != null;
- if (lifetime.compareTo(defaultTokenLifetime) > 0) {
- log.warn("Requested token lifetime greater than default, lowering to default", getLogPrefix());
- tokenLifetime = defaultTokenLifetime;
- } else {
- tokenLifetime = lifetime;
- }
- } catch (final DateTimeParseException e) {
- log.warn("{} Token lifetime was not in a supported format", getLogPrefix(), e);
- }
- } else {
- log.debug("{} No token lifetime specified, using default", getLogPrefix());
- tokenLifetime = defaultTokenLifetime;
- }
-
return true;
}
diff --git a/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oauth2/profile/impl/ValidateRequestObject.java b/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oauth2/profile/impl/ValidateRequestObject.java
index 874eac2b..0999ec65 100644
--- a/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oauth2/profile/impl/ValidateRequestObject.java
+++ b/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oauth2/profile/impl/ValidateRequestObject.java
@@ -44,6 +44,7 @@ import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.logic.Constraint;
import net.shibboleth.shared.primitive.LoggerFactory;
+import net.shibboleth.shared.primitive.StringSupport;
/**
* Action validates request object in response context.
@@ -158,13 +159,23 @@ public class ValidateRequestObject extends AbstractOAuthAuthorizationResponseAct
return;
}
- if (claimsSet.getClaims().containsKey("client_id")
- && !authorizationRequest.getClientID()
- .equals(new ClientID((String) claimsSet.getClaim("client_id")))) {
- log.error("{} client_id in request object not matching client_id request parameter", getLogPrefix());
- ActionSupport.buildEvent(profileRequestContext, OidcEventIds.INVALID_REQUEST_OBJECT);
- return;
- }
+ if (claimsSet.getClaims().containsKey("client_id")) {
+ if (claimsSet.getClaim("client_id") instanceof String string && StringSupport.trimOrNull(string) != null) {
+ if (!authorizationRequest.getClientID().equals(new ClientID(string))) {
+ log.error("{} client_id in request object not matching client_id request parameter",
+ getLogPrefix());
+ oidcResponseContext.setRequestObjectFailure(true);
+ ActionSupport.buildEvent(profileRequestContext, OidcEventIds.INVALID_REQUEST_OBJECT);
+ return;
+ }
+ } else {
+ log.error("{} Unable to parse client_id from request object value {}", getLogPrefix(),
+ claimsSet.getClaim("client_id"));
+ oidcResponseContext.setRequestObjectFailure(true);
+ ActionSupport.buildEvent(profileRequestContext, OidcEventIds.INVALID_REQUEST_OBJECT);
+ return;
+ }
+ }
// We let "none" to be used only if nothing else has been registered.
if (requestObject instanceof PlainJWT) {
@@ -204,20 +215,23 @@ public class ValidateRequestObject extends AbstractOAuthAuthorizationResponseAct
ActionSupport.buildEvent(profileRequestContext, OidcEventIds.INVALID_RESPONSE_TYPE);
return;
}
- try {
- if (claimsSet.getClaims().containsKey("response_type")
- && !requestedType.equals(new ResponseType(claimsSet.getStringClaim("response_type").split(" ")))) {
- log.error("{} response_type in request object not matching response_type request parameter",
- getLogPrefix());
+ if (claimsSet.getClaims().containsKey("response_type")) {
+ if (claimsSet.getClaim("response_type") instanceof String string
+ && StringSupport.trimOrNull(string) != null) {
+ if (!requestedType.equals(new ResponseType(string.split(" ")))) {
+ log.error("{} response_type in request object not matching response_type request parameter",
+ getLogPrefix());
+ oidcResponseContext.setRequestObjectFailure(true);
+ ActionSupport.buildEvent(profileRequestContext, OidcEventIds.INVALID_REQUEST_OBJECT);
+ return;
+ }
+ } else {
+ log.error("{} Unable to parse response_type from request object {}", getLogPrefix(),
+ claimsSet.getClaim("response_type"));
oidcResponseContext.setRequestObjectFailure(true);
ActionSupport.buildEvent(profileRequestContext, OidcEventIds.INVALID_REQUEST_OBJECT);
return;
}
- } catch (final ParseException e) {
- log.error("{} Unable to parse response_type from request object {}", getLogPrefix(), e.getMessage());
- oidcResponseContext.setRequestObjectFailure(true);
- ActionSupport.buildEvent(profileRequestContext, OidcEventIds.INVALID_REQUEST_OBJECT);
- return;
}
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list