8000 implement wildcard hostnames by silviokennecke · Pull Request #14118 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,36 @@ private static String relativeToAbsoluteURI(KeycloakSession session, String root

private static boolean matchesRedirects(Set<String> validRedirects, String redirect) {
for (String validRedirect : validRedirects) {
// check wildcard hostname
if (!validRedirect.startsWith("/")) {
int vrHostnamePosStart = validRedirect.indexOf("//") + 2;
String vrScheme = validRedirect.substring(0, vrHostnamePosStart);
String vrHostname = validRedirect.substring(vrHostnamePosStart);

int vrHostnamePosEnd = vrHostname.contains(":") ? vrHostname.indexOf(":") : vrHostname.indexOf("/");
String vrPath = vrHostname.substring(vrHostnamePosEnd);
vrHostname = vrHostname.substring(0, vrHostnamePosEnd);

if (vrHostname.contains("*") && vrHostname.length() > 1) {
int vrWildcardPos = vrHostname.indexOf("*");
String vrHostnameStart = vrHostname.substring(0, vrWildcardPos);
String vrHostnameEnd = vrHostname.substring(vrWildcardPos + 1);

int rHostnamePos = redirect.indexOf("//") + 2;
String rHostname = redirect.substring(rHostnamePos);

int rHostnamePosEnd = rHostname.contains(":") ? rHostname.indexOf(":") : rHostname.indexOf("/");
rHostname = rHostname.substring(0, rHostnamePosEnd);

if (rHostname.startsWith(vrHostnameStart) && rHostname.endsWith(vrHostnameEnd)) {
// replace wildcard hostname with actual hostname for further checks
validRedirect = vrScheme + rHostname + vrPath;
} else {
continue;
}
}
}

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ mapper.nameid.format.tooltip=Name ID Format using Mapper
root-url=Root URL
root-url.tooltip=Root URL appended to relative URLs
valid-redirect-uris=Valid Redirect URIs
valid-redirect-uris.tooltip=Valid URI pattern a browser can redirect to after a successful login or logout. Simple wildcards are allowed such as 'http://example.com/*'. Relative path can be specified too such as /my/relative/path/*. Relative paths are relative to the client root URL, or if none is specified the auth server root URL is used. For SAML, you must set valid URI patterns if you are relying on the consumer service URL embedded with the login request.
valid-redirect-uris.tooltip=Valid URI pattern a browser can redirect to after a successful login or logout. Simple wildcards are allowed such as 'http://example.com/*' or 'http://*.example.com/*'. Relative path can be specified too such as /my/relative/path/*. Relative paths are relative to the client root URL, or if none is specified the auth server root URL is used. For SAML, you must set valid URI patterns if you are relying on the consumer service URL embedded with the login request.
base-url.tooltip=Default URL to use when the auth server needs to redirect or link back to the client.
admin-url=Admin URL
admin-url.tooltip=URL to the admin interface of the client. Set this if the client supports the adapter REST API. This REST API allows the auth server to push revocation policies and other administrative tasks. Usually this is set to the base URL of the client.
Expand Down
0