Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Max Mecklin
/
Moya
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 6589f3e3
authored
Jan 08, 2018
by
Tuomas Riihimäki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix hostname equality check when principal is null
1 parent
288fff6b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
9 deletions
code/moya-web/src/main/java/fi/codecrew/moya/HostnameFilter.java
code/moya-web/src/main/java/fi/codecrew/moya/HostnameFilter.java
View file @
6589f3e
...
...
@@ -167,6 +167,7 @@ public class HostnameFilter implements Filter {
insertServerLoggingContext
(
httpRequest
,
authtype
);
String
hostname
=
parseHostname
(
httpRequest
);
if
(
httpRequest
.
getUserPrincipal
()
==
null
)
{
// Check if we are logging in with rest
if
(
RestApplicationEntrypoint
.
REST_PATH
.
equals
(
httpRequest
.
getServletPath
()))
{
...
...
@@ -281,18 +282,19 @@ public class HostnameFilter implements Filter {
scheme
=
url
.
substring
(
0
,
5
).
toLowerCase
();
}
String
userDomain
=
UserLoginUtils
.
getDomainFromJaas
(
httpRequest
.
getUserPrincipal
());
if
(!
hostname
.
equals
(
userDomain
))
{
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!"
);
Principal
principal
=
httpRequest
.
getUserPrincipal
();
if
(
principal
!=
null
)
{
String
userDomain
=
UserLoginUtils
.
getDomainFromJaas
(
principal
);
// If there is no logged-in user, we can and should not check userDomain against hostname
if
(
principal
!=
null
&&
!
hostname
.
equals
(
userDomain
))
{
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
);
return
hostname
;
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment