From 9d783efbc942d55ef60412e870f4f9f0e5bc5074 Mon Sep 17 00:00:00 2001
From: Stian Thorgersen <stianst@gmail.com>
Date: Mon, 17 Oct 2016 14:12:14 +0000
Subject: [PATCH] KEYCLOAK-3635 Not possible to filter debug/trace logging
---
src/main/java/org/keycloak/protocol/cas/utils/RedirectUtils.java | 49 +++++++++++++++++++++++++++++++++++++------------
1 files changed, 37 insertions(+), 12 deletions(-)
diff --git a/src/main/java/org/keycloak/protocol/cas/utils/RedirectUtils.java b/src/main/java/org/keycloak/protocol/cas/utils/RedirectUtils.java
index ff4601f..03bc9e6 100644
--- a/src/main/java/org/keycloak/protocol/cas/utils/RedirectUtils.java
+++ b/src/main/java/org/keycloak/protocol/cas/utils/RedirectUtils.java
@@ -1,3 +1,20 @@
+/*
+ * Copyright 2016 Red Hat, Inc. and/or its affiliates
+ * and other contributors as indicated by the @author tags.
+ *
+ * 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 org.keycloak.protocol.oidc.utils;
import org.jboss.logging.Logger;
@@ -52,18 +69,15 @@
private static String verifyRedirectUri(UriInfo uriInfo, String rootUrl, String redirectUri, RealmModel realm, Set<String> validRedirects) {
if (redirectUri == null) {
- if (validRedirects.size() != 1) return null;
- String validRedirect = validRedirects.iterator().next();
- int idx = validRedirect.indexOf("/*");
- if (idx > -1) {
- validRedirect = validRedirect.substring(0, idx);
- }
- redirectUri = validRedirect;
+ logger.debug("No Redirect URI parameter specified");
+ return null;
} else if (validRedirects.isEmpty()) {
logger.debug("No Redirect URIs supplied");
redirectUri = null;
} else {
- String r = redirectUri.indexOf('?') != -1 ? redirectUri.substring(0, redirectUri.indexOf('?')) : redirectUri;
+ redirectUri = lowerCaseHostname(redirectUri);
+
+ String r = redirectUri;
Set<String> resolveValidRedirects = resolveValidRedirects(uriInfo, rootUrl, validRedirects);
boolean valid = matchesRedirects(resolveValidRedirects, r);
@@ -96,8 +110,17 @@
}
}
+ private static String lowerCaseHostname(String redirectUri) {
+ int n = redirectUri.indexOf('/', 7);
+ if (n == -1) {
+ return redirectUri.toLowerCase();
+ } else {
+ return redirectUri.substring(0, n).toLowerCase() + redirectUri.substring(n);
+ }
+ }
+
private static String relativeToAbsoluteURI(UriInfo uriInfo, String rootUrl, String relative) {
- if (rootUrl == null) {
+ if (rootUrl == null || rootUrl.isEmpty()) {
URI baseUri = uriInfo.getBaseUri();
String uri = baseUri.getScheme() + "://" + baseUri.getHost();
if (baseUri.getPort() != -1) {
@@ -111,15 +134,17 @@
private static boolean matchesRedirects(Set<String> validRedirects, String redirect) {
for (String validRedirect : validRedirects) {
- if (validRedirect.endsWith("*")) {
+ if (validRedirect.endsWith("*") && !validRedirect.contains("?")) {
+ // strip off the query component - we don't check them when wildcards are effective
+ String r = redirect.contains("?") ? redirect.substring(0, redirect.indexOf("?")) : redirect;
// strip off *
int length = validRedirect.length() - 1;
validRedirect = validRedirect.substring(0, length);
- if (redirect.startsWith(validRedirect)) return true;
+ if (r.startsWith(validRedirect)) return true;
// strip off trailing '/'
if (length - 1 > 0 && validRedirect.charAt(length - 1) == '/') length--;
validRedirect = validRedirect.substring(0, length);
- if (validRedirect.equals(redirect)) return true;
+ if (validRedirect.equals(r)) return true;
} else if (validRedirect.equals(redirect)) return true;
}
return false;
--
Gitblit v1.10.0