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 @@ -34,6 +34,7 @@ public class ReservedCharValidator {

// https://tools.ietf.org/html/rfc3986#section-2.2
private static final Pattern RESERVED_CHARS_PATTERN = Pattern.compile("[:/?#@!$&()*+,;=\\[\\]\\\\]");
private static final Pattern RESERVED_REALM_NAME_CHARS_PATTERN = Pattern.compile("[%^]");

// KEYCLOAK-14231 - Supported Locales: Three new characters were added on top of this RFC: "{", "}", "%"
private static final Pattern RESERVED_CHARS_LOCALES_PATTERN = Pattern.compile("[:/?#@!$&()*+,;=\\[\\]\\\\{}%]");
Expand Down Expand Up @@ -65,8 +66,13 @@ public static void validateNoSpace(String str) {
public static void validate(String str) {
validate(str, RESERVED_CHARS_PATTERN);
}

public static void validateRealmName(String realmName) {
validate(realmName, RESERVED_CHARS_PATTERN);
validate(realmName, RESERVED_REALM_NAME_CHARS_PATTERN);
}

public static void validateLocales(Iterable<String> strIterable) {
public static void validateLocales(Iterable<String> strIterable) {
if (strIterable == null) return;

for (String str: strIterable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,10 @@ public RealmModel createRealm(String id, String name) {
else {
ReservedCharValidator.validate(id);
}
ReservedCharValidator.validate(name);
ReservedCharValidator.validateRealmName(name);
RealmModel realm = model.createRealm(id, name);
//ReservedCharValidator.validate(name);
//RealmModel realm = model.createRealm(id, name);
realm.setName(name);

// setup defaults
Expand Down Expand Up @@ -645,7 +647,8 @@ public RealmModel importRealm(RealmRepresentation rep, Runnable userImport) {

try {
session.getContext().setRealm(realm);
ReservedCharValidator.validate(rep.getRealm());
//ReservedCharValidator.validate(rep.getRealm());
ReservedCharValidator.validateRealmName(rep.getRealm());
ReservedCharValidator.validateLocales(rep.getSupportedLocales());
ReservedCharValidator.validateSecurityHeaders(rep.getBrowserSecurityHeaders());
SMTPUtil.checkSMTPConfiguration(session, rep.getSmtpServer());
Expand Down
Loading