Skip to content

Commit

Permalink
KEYCLOAK-16890: Stored XSS attack on new acct console (#7867)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssilvert committed Mar 22, 2021
1 parent 3b80eee commit 717d951
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Expand Up @@ -250,4 +250,22 @@ public void updateProfileWithAttributePresent() {

ApiUtil.removeUserByUsername(testRealm, "keycloak-15634");
}

@Test
// https://issues.redhat.com/browse/KEYCLOAK-16890
// Stored personal info triggers attack via the display of user name in header.
// If user name is left unsanitized, this test will fail with
// org.openqa.selenium.UnhandledAlertException: unexpected alert open: {Alert text : XSS}
public void storedXSSAttack() {
personalInfoPage.navigateTo();
testUser.setFirstName("<img src=x onerror=\"alert('XSS');\">");
personalInfoPage.setValues(testUser, false);
personalInfoPage.clickSave();

personalInfoPage.header().clickLogoutBtn();
accountWelcomeScreen.header().clickLoginBtn();
loginPage.form().login(testUser);
personalInfoPage.navigateTo();
}

}
Expand Up @@ -55,7 +55,13 @@ function loggedInUserName() {
userName = (givenName || familyName) || preferredUsername || userName;
}
}
return userName;
return sanitize(userName);
}

function sanitize(dirtyString) {
let element = document.createElement("span");
element.textContent = dirtyString;
return element.innerHTML;
}

var toggleMobileDropdown = function () {
Expand Down

0 comments on commit 717d951

Please sign in to comment.