[java-idp-oidc] 01/02: JOIDC-321 - Improve pairwise subject type handling in dynamic client registration

Codeberg noreply at shibboleth.net
Thu Nov 26 15:27:14 UTC 2026


This is an automated email from the git hooks/post-receive script.

codeberg pushed a commit to branch maint-4.4
in repository java-idp-oidc.

View the commit online:
https://codeberg.org/Shibboleth/java-idp-oidc/commit/4d928816409afd635155fa784b4545ccbcd59dae

commit 4d928816409afd635155fa784b4545ccbcd59dae
Author: Henri Mikkonen <henri.mikkonen at iki.fi>
AuthorDate: Thu Nov 26 17:10:27 2026 +0200

    JOIDC-321 - Improve pairwise subject type handling in dynamic client registration
    
    https://shibboleth.atlassian.net/browse/JOIDC-321
    
    Modofied CheckRedirectURIs to perform the additional checks for non-web clients and redirection URI sets with a null host or more than one host.
---
 .../oidc/op/profile/impl/CheckRedirectURIs.java    | 51 +++++++++++++++++++---
 .../idp/flows/oidc/register/register-beans.xml     |  3 +-
 .../op/profile/impl/CheckRedirectUrisTest.java     | 36 +++++++++++++++
 3 files changed, 84 insertions(+), 6 deletions(-)

diff --git a/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/CheckRedirectURIs.java b/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/CheckRedirectURIs.java
index 54fa8ca1..9ca91089 100644
--- a/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/CheckRedirectURIs.java
+++ b/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/CheckRedirectURIs.java
@@ -21,6 +21,8 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 import java.util.Set;
+import java.util.function.Function;
+import java.util.stream.Collectors;
 
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
@@ -42,6 +44,7 @@ import org.slf4j.Logger;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.nimbusds.oauth2.sdk.GrantType;
+import com.nimbusds.openid.connect.sdk.SubjectType;
 import com.nimbusds.openid.connect.sdk.rp.ApplicationType;
 import com.nimbusds.openid.connect.sdk.rp.OIDCClientMetadata;
 import com.nimbusds.openid.connect.sdk.rp.OIDCClientRegistrationRequest;
@@ -49,6 +52,7 @@ import com.nimbusds.openid.connect.sdk.rp.OIDCClientRegistrationRequest;
 import net.shibboleth.idp.profile.AbstractProfileAction;
 import net.shibboleth.oidc.profile.core.OidcEventIds;
 import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
+import net.shibboleth.shared.annotation.constraint.NonnullBeforeExec;
 import net.shibboleth.shared.component.ComponentInitializationException;
 import net.shibboleth.shared.logic.Constraint;
 import net.shibboleth.shared.primitive.LoggerFactory;
@@ -66,6 +70,9 @@ import net.shibboleth.shared.primitive.LoggerFactory;
  * using the http: scheme with localhost as the hostname. Authorization Servers MAY place additional constraints on 
  * Native Clients. Authorization Servers MAY reject Redirection URI values using the http scheme, other than the 
  * localhost case for Native Clients. </p>
+ * 
+ * <p>Since 4.4.0 the following checks are done when requested subject_type (or default when it's missing) is pairwise:
+ * require sector ID for non-web applications and require single host in redirection URIs when sector ID is missing.</p>
  */
 public class CheckRedirectURIs extends AbstractProfileAction {
 
@@ -85,9 +92,16 @@ public class CheckRedirectURIs extends AbstractProfileAction {
     /** JSON object mapper. */
     @NonnullAfterInit private ObjectMapper objectMapper;
 
+    /** The default {@link SubjectType} if it was not defined in the request. */
+    private SubjectType defaultSubjectType;
+
+    /** Requested metadata to operate on. */
+    @NonnullBeforeExec private OIDCClientMetadata metadata;
+
     /** Constructor. */
     public CheckRedirectURIs() {
         super();
+        defaultSubjectType = SubjectType.PUBLIC;
     }
     
     /**
@@ -125,6 +139,17 @@ public class CheckRedirectURIs extends AbstractProfileAction {
         objectMapper = Constraint.isNotNull(mapper, "Object mapper cannot be null");
     }
 
+    /**
+     * Set the default {@link SubjectType} to be used if it was not defined in the request.
+     * 
+     * @param subjectType The default {@link SubjectType} to be used if it was not defined in the request.
+     * @since 4.4.0
+     */
+    public void setDefaultSubjectType(@Nonnull final SubjectType subjectType) {
+        checkSetterPreconditions();
+        defaultSubjectType = Constraint.isNotNull(subjectType, "The default subjectType cannot be null");
+    }
+
     /** {@inheritDoc} */
     public void doInitialize() throws ComponentInitializationException {
         super.doInitialize();
@@ -181,7 +206,7 @@ public class CheckRedirectURIs extends AbstractProfileAction {
         final URI sectorIdUri = metadata.getSectorIDURI();
         if (sectorIdUri != null) {
             log.debug("{} Found sector_identifier_uri {}", getLogPrefix(), sectorIdUri);
-            if (!sectorIdUri.getScheme().equals("https")) {
+            if (!"https".equalsIgnoreCase(sectorIdUri.getScheme())) {
                 log.warn("{} Invalid sector_identifier_uri scheme {}", getLogPrefix(), sectorIdUri.getScheme());
                 ActionSupport.buildEvent(profileRequestContext, EventIds.INVALID_MESSAGE);
                 return;
@@ -226,6 +251,22 @@ public class CheckRedirectURIs extends AbstractProfileAction {
                 log.debug("{} Accepting a redirect URI {} for a native application", getLogPrefix(), redirectUri);
             }
         }
+        final SubjectType subjectType = metadata.getSubjectType() != null ? metadata.getSubjectType() :
+            defaultSubjectType;
+        if (SubjectType.PAIRWISE.equals(subjectType) && sectorIdUri == null) {
+            if (applicationType != null && !ApplicationType.WEB.equals(applicationType)) {
+                log.warn("{} Pairwise subject type requires sector ID URI for a non-web application", getLogPrefix());
+                ActionSupport.buildEvent(profileRequestContext, EventIds.INVALID_MESSAGE);
+                return;
+            }
+            final Set<String> hosts = redirectURIs.stream().map(uri -> uri.getHost()).collect(Collectors.toSet());
+            if (hosts.contains(null) || hosts.size() != 1) {
+                log.warn("{} Pairwise subject type with null or multiple host in redirect URIs requires sector ID URI",
+                        getLogPrefix());
+                ActionSupport.buildEvent(profileRequestContext, EventIds.INVALID_MESSAGE);
+                return;
+            }
+        }
         //TODO: should the URIs be checked against black/white-lists?
         log.debug("{} Redirect URIs ({}) checked", getLogPrefix(), redirectURIs.size());
     }
@@ -294,9 +335,9 @@ public class CheckRedirectURIs extends AbstractProfileAction {
      * @param scheme The scheme to check.
      * @return true if scheme was used in all URIs, false otherwise.
      */
-    protected boolean checkScheme(final Set<URI> redirectURIs, final String scheme) {
+    protected boolean checkScheme(final Set<URI> redirectURIs, @Nonnull final String scheme) {
         for (final URI redirectUri : redirectURIs) {
-            if (!redirectUri.getScheme().equals(scheme)) {
+            if (!scheme.equalsIgnoreCase(redirectUri.getScheme())) {
                 log.trace("{} Found '{}' as the scheme in the redirect URI, all should be {}", getLogPrefix(), 
                         redirectUri.getScheme(), scheme);
                 return false;
@@ -311,9 +352,9 @@ public class CheckRedirectURIs extends AbstractProfileAction {
      * @param scheme The scheme to check.
      * @return true if scheme was found once or more, false otherwise.
      */
-    protected boolean checkForbiddenScheme(final Set<URI> redirectURIs, final String scheme) {
+    protected boolean checkForbiddenScheme(final Set<URI> redirectURIs, @Nonnull final String scheme) {
         for (final URI redirectUri : redirectURIs) {
-            if (redirectUri.getScheme().equals(scheme)) {
+            if (scheme.equalsIgnoreCase(redirectUri.getScheme())) {
                 log.trace("{} Found forbidden '{}' as the scheme in the redirect URI {}", getLogPrefix(), 
                         scheme, redirectUri);
                 return true;
diff --git a/idp-oidc-extension-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/oidc/register/register-beans.xml b/idp-oidc-extension-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/oidc/register/register-beans.xml
index 749f063f..1ba9aef4 100644
--- a/idp-oidc-extension-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/oidc/register/register-beans.xml
+++ b/idp-oidc-extension-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/oidc/register/register-beans.xml
@@ -101,7 +101,8 @@
         scope="prototype"
         p:httpClient="#{getObject('shibboleth.oidc.NonBrowser.HttpClient') ?: getObject('shibboleth.InternalHttpClient')}"
         p:httpClientSecurityParameters="#{getObject('shibboleth.oidc.NonBrowser.HttpClientSecurityParameters')}"
-        p:objectMapper-ref="shibboleth.oidc.JSONObjectMapper" />
+        p:objectMapper-ref="shibboleth.oidc.JSONObjectMapper"
+        p:defaultSubjectType-ref="shibboleth.oidc.DefaultSubjectType" />
 
     <bean id="GenerateClientID"
         class="net.shibboleth.idp.plugin.oidc.op.profile.impl.GenerateClientID"
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/CheckRedirectUrisTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/CheckRedirectUrisTest.java
index 0a292b87..95c3913b 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/CheckRedirectUrisTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/CheckRedirectUrisTest.java
@@ -37,6 +37,8 @@ import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.nimbusds.openid.connect.sdk.SubjectType;
+import com.nimbusds.openid.connect.sdk.rp.ApplicationType;
 import com.nimbusds.openid.connect.sdk.rp.OIDCClientMetadata;
 import com.nimbusds.openid.connect.sdk.rp.OIDCClientRegistrationRequest;
 
@@ -158,6 +160,40 @@ public class CheckRedirectUrisTest extends BaseOIDCRegistrationRequestTest {
         action.initialize();
     }
 
+    @Test
+    public void testNativePublic() throws Exception {
+        final OIDCClientMetadata metadata = new OIDCClientMetadata();
+        metadata.setSubjectType(SubjectType.PUBLIC);
+        metadata.setApplicationType(ApplicationType.NATIVE);
+        assertEvent(null, metadata, URI.create("http://localhost"));
+    }
+
+    @Test
+    public void testNativePairwiseNoSector() throws Exception {
+        final OIDCClientMetadata metadata = new OIDCClientMetadata();
+        metadata.setSubjectType(SubjectType.PAIRWISE);
+        metadata.setApplicationType(ApplicationType.NATIVE);
+        assertEvent(EventIds.INVALID_MESSAGE, metadata, URI.create("http://localhost"));
+    }
+
+    @Test
+    public void testCustomSchemePairwise() throws Exception {
+        final OIDCClientMetadata metadata = new OIDCClientMetadata();
+        metadata.setSubjectType(SubjectType.PAIRWISE);
+        assertEvent(EventIds.INVALID_MESSAGE, metadata, URI.create("custom.test:test"));
+    }
+
+    @Test
+    public void testCustomSchemeDefaultPairwise() throws Exception {
+        action = new CheckRedirectURIs();
+        action.setObjectMapper(new ObjectMapper());
+        action.setHttpClient(buildMockHttpClient("mock"));
+        action.setDefaultSubjectType(SubjectType.PAIRWISE);
+        action.initialize();
+        final OIDCClientMetadata metadata = new OIDCClientMetadata();
+        assertEvent(EventIds.INVALID_MESSAGE, metadata, URI.create("custom.test:test"));
+    }
+
     protected void initializeActionWithClient(@Nonnull final HttpClient httpClient) throws ComponentInitializationException {
         action = new CheckRedirectURIs();
         action.setHttpClient(httpClient);

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list