[java-oidc-common] 01/02: JCOMOIDC-204 - Default URI validation condition for backend calls
Codeberg
noreply at shibboleth.net
Fri Nov 27 16:15:16 UTC 2026
This is an automated email from the git hooks/post-receive script.
codeberg pushed a commit to branch main
in repository java-oidc-common.
View the commit online:
https://codeberg.org/Shibboleth/java-oidc-common/commit/d7a44768933d9d7b0e3fa0528c5b8b7ec759b173
commit d7a44768933d9d7b0e3fa0528c5b8b7ec759b173
Author: Henri Mikkonen <henri.mikkonen at iki.fi>
AuthorDate: Fri Nov 27 16:58:51 2026 +0200
JCOMOIDC-204 - Default URI validation condition for backend calls
https://shibboleth.atlassian.net/browse/JCOMOIDC-204
Initial version, providing https-enforcement via configurable flag and address filtering via disallowed IPRanges.
---
.../DefaultBackChannelUriValidationCondition.java | 131 +++++++++++++++++++++
1 file changed, 131 insertions(+)
diff --git a/oidc-common-crypto-impl/src/main/java/net/shibboleth/oidc/security/impl/DefaultBackChannelUriValidationCondition.java b/oidc-common-crypto-impl/src/main/java/net/shibboleth/oidc/security/impl/DefaultBackChannelUriValidationCondition.java
new file mode 100644
index 00000000..fb3614a2
--- /dev/null
+++ b/oidc-common-crypto-impl/src/main/java/net/shibboleth/oidc/security/impl/DefaultBackChannelUriValidationCondition.java
@@ -0,0 +1,131 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.oidc.security.impl;
+
+import java.net.InetAddress;
+import java.net.URI;
+import java.net.UnknownHostException;
+import java.util.Collection;
+import java.util.Locale;
+import java.util.Optional;
+import java.util.function.Predicate;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
+import net.shibboleth.shared.collection.CollectionSupport;
+import net.shibboleth.shared.component.AbstractIdentifiableInitializableComponent;
+import net.shibboleth.shared.component.ComponentInitializationException;
+import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.net.IPRange;
+import net.shibboleth.shared.primitive.StringSupport;
+
+/**
+ * Default condition to verify a back-channel URI before passing it to the HTTP client. The host may not be null,
+ * enforcing of https scheme may be configured via {@link #setRequireHttps(boolean)} and all disallowed IP ranges for
+ * any resolved {@link InetAddress} may be configured via {@link #setDisallowedRanges(Collection)}.
+ *
+ * @since 3.4.0
+ */
+public class DefaultBackChannelUriValidationCondition extends AbstractIdentifiableInitializableComponent
+ implements Predicate<URI> {
+
+ /** Class logger. */
+ private final Logger log = LoggerFactory.getLogger(DefaultBackChannelUriValidationCondition.class);
+
+ /** List of CIDR blocks disallowed for the host of the URI. */
+ @NonnullAfterInit private Collection<IPRange> disallowedRanges;
+
+ /** Whether to require https-scheme in the URI. */
+ private boolean requireHttps = true;
+
+ /**
+ * Set the CIDR address ranges to disallow.
+ *
+ * @param ranges ranges to disallow
+ */
+ public void setDisallowedRanges(@Nonnull final Collection<IPRange> ranges) {
+ checkSetterPreconditions();
+ Constraint.isNotNull(ranges, "IPRange collection cannot be null");
+ if (ranges.isEmpty()) {
+ log.warn("Disallowed IPRange collection is empty, all the targets are allowed");
+ }
+ disallowedRanges = CollectionSupport.copyToList(ranges);
+ }
+
+ /**
+ * Set whether to require https-scheme in the URI.
+ *
+ * @param flag require https
+ */
+ public void setRequireHttps(final boolean flag) {
+ checkSetterPreconditions();
+ requireHttps = flag;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected void doInitialize() throws ComponentInitializationException {
+ super.doInitialize();
+ if (disallowedRanges == null) {
+ throw new ComponentInitializationException("Disallowed IPRange cannot be null");
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public boolean test(@Nullable final URI uri) {
+ final String host = Optional.ofNullable(uri)
+ .map(value -> value.getHost())
+ .map(StringSupport::trimOrNull)
+ .map(string -> string.toLowerCase(Locale.ROOT))
+ .orElse(null);
+ if (host == null) {
+ log.warn("No host could be resolved from URI {}", uri);
+ return false;
+ }
+ assert uri != null;
+ if (requireHttps && !"https".equalsIgnoreCase(uri.getScheme())) {
+ log.warn("No https scheme in the URI {}", uri);
+ return false;
+ }
+ try {
+ final InetAddress[] addresses = InetAddress.getAllByName(host);
+ if (addresses == null || addresses.length == 0) {
+ log.warn("No addresses resolved with host {}", host);
+ return false;
+ }
+ for (final InetAddress address : addresses) {
+ for (final IPRange range : disallowedRanges) {
+ assert address != null;
+ if (range.contains(address)) {
+ log.warn("The address {} from URI {} is disallowed by range {}", address, uri,
+ range.getNetworkAddress());
+ return false;
+ }
+ log.trace("The address {} is not disallowed by range {}", address, range.getNetworkAddress());
+ }
+ }
+ } catch (final UnknownHostException e) {
+ log.warn("Could not build an InetAddress of the host {}: {}", host, e.getMessage());
+ return false;
+ }
+ return true;
+ }
+}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list