Commit 6589f3e3 by Tuomas Riihimäki

Fix hostname equality check when principal is null

1 parent 288fff6b
...@@ -167,6 +167,7 @@ public class HostnameFilter implements Filter { ...@@ -167,6 +167,7 @@ public class HostnameFilter implements Filter {
insertServerLoggingContext(httpRequest, authtype); insertServerLoggingContext(httpRequest, authtype);
String hostname = parseHostname(httpRequest); String hostname = parseHostname(httpRequest);
if (httpRequest.getUserPrincipal() == null) { if (httpRequest.getUserPrincipal() == null) {
// Check if we are logging in with rest // Check if we are logging in with rest
if (RestApplicationEntrypoint.REST_PATH.equals(httpRequest.getServletPath())) { if (RestApplicationEntrypoint.REST_PATH.equals(httpRequest.getServletPath())) {
...@@ -281,18 +282,19 @@ public class HostnameFilter implements Filter { ...@@ -281,18 +282,19 @@ public class HostnameFilter implements Filter {
scheme = url.substring(0, 5).toLowerCase(); scheme = url.substring(0, 5).toLowerCase();
} }
String userDomain = UserLoginUtils.getDomainFromJaas(httpRequest.getUserPrincipal()); Principal principal = httpRequest.getUserPrincipal();
if (!hostname.equals(userDomain)) { if (principal != null) {
String userDomain = UserLoginUtils.getDomainFromJaas(principal);
logbean.sendMessage(MoyaEventType.USER_PERMISSION_VIOLATION, // If there is no logged-in user, we can and should not check userDomain against hostname
"Hostname mismatch privilege escalation! User '", httpRequest.getUserPrincipal(), "' tried to change hostname from '", if (principal != null && !hostname.equals(userDomain)) {
userDomain, "' to '", hostname, ",");
throw new RuntimeException("Hostname mismatch!");
logbean.sendMessage(MoyaEventType.USER_PERMISSION_VIOLATION,
"Hostname mismatch privilege escalation! User '", httpRequest.getUserPrincipal(), "' tried to change hostname from '",
userDomain, "' to '", hostname, ",");
throw new RuntimeException("Hostname mismatch!");
}
} }
BortalLocalContextHolder.setHostname(hostname);
BortalLocalContextHolder.setInDevelopmentMode(developmentMode); BortalLocalContextHolder.setInDevelopmentMode(developmentMode);
return hostname; return hostname;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!