Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix XSS (CVE-2020-5497) #1534

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -79,8 +79,9 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons
// if they're logging into this server from a remote OIDC server, pass through their user info
OIDCAuthenticationToken oidc = (OIDCAuthenticationToken) auth;
if (oidc.getUserInfo() != null) {
JsonElement json = gson.fromJson(oidc.getUserInfo().toJson().toString(), JsonElement.class);
request.setAttribute("userInfo", oidc.getUserInfo());
request.setAttribute("userInfoJson", oidc.getUserInfo().toJson());
request.setAttribute("userInfoJson", gson.toJson(json));
} else {
request.setAttribute("userInfo", null);
request.setAttribute("userInfoJson", "null");
Expand All @@ -94,8 +95,9 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons

// if we have one, inject it so views can use it
if (user != null) {
JsonElement json = gson.fromJson(user.toJson().toString(), JsonElement.class);
request.setAttribute("userInfo", user);
request.setAttribute("userInfoJson", user.toJson());
request.setAttribute("userInfoJson", gson.toJson(json));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
<%@attribute name="pageName" required="false"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="security" uri="http://www.springframework.org/security/tags"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="o" tagdir="/WEB-INF/tags"%>
<c:choose>
<c:when test="${ not empty userInfo.preferredUsername }">
<c:set var="shortName" value="${ userInfo.preferredUsername }" />
<c:set var="shortName" value="${ fn:escapeXml(userInfo.preferredUsername) }" />
</c:when>
<c:otherwise>
<c:set var="shortName" value="${ userInfo.sub }" />
<c:set var="shortName" value="${ fn:escapeXml(userInfo.sub) }" />
</c:otherwise>
</c:choose>
<c:choose>
<c:when test="${ not empty userInfo.name }">
<c:set var="longName" value="${ userInfo.name }" />
<c:set var="longName" value="${ fn:escapeXml(userInfo.name) }" />
</c:when>
<c:otherwise>
<c:choose>
<c:when test="${ not empty userInfo.givenName || not empty userInfo.familyName }">
<c:set var="longName" value="${ userInfo.givenName } ${ userInfo.familyName }" />
<c:set var="longName" value="${ fn:escapeXml(userInfo.givenName) } ${ fn:escapeXml(userInfo.familyName) }" />
</c:when>
<c:otherwise>
<c:set var="longName" value="${ shortName }" />
Expand Down Expand Up @@ -104,4 +105,4 @@
$('#logoutForm').submit();
});
});
</script>
</script>