Skip to content

Commit ecb34a5

Browse files
author
sachin-maheshwari
authored
Merge pull request #256 from topcoder-platform/dev
VULNERABILITY XSS fixes
2 parents 117712b + ad539af commit ecb34a5

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

web-assets/js/setupAuth0WithRedirect.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ const authSetup = function () {
9494
} else if (!isLoggedIn() && returnAppUrl) {
9595
login();
9696
} else if (qs['error'] && qs['state']) {
97-
logger("Error in executing callback(): ", qs['error_description']);
98-
showLoginError(qs['error_description'], appUrl);
97+
var error_description = encode(qs['error_description']);
98+
logger("Error in executing callback(): ", error_description);
99+
showLoginError(error_description, appUrl);
99100
} else {
100101
logger("User already logged in", true);
101102
postLogin();
@@ -383,6 +384,12 @@ const authSetup = function () {
383384
}
384385
// end token.js
385386

387+
// XSS rules
388+
const encode = function(str) {
389+
return str.replace(/[\x26\x0A\<>'"]/g,function(str){return"&#"+str.charCodeAt(0)+";"})
390+
}
391+
// end XSS rules
392+
386393
function getHostDomain() {
387394
let hostDomain = "";
388395
if (location.hostname !== 'localhost') {
@@ -594,8 +601,10 @@ const authSetup = function () {
594601

595602
function showLoginError(message, linkUrl) {
596603
try {
597-
document.getElementById("page-title-heading").innerHTML = "Alert";
598-
document.getElementById("loading_message_p").innerHTML = message + " <a href=" + linkUrl + ">click here</a>";
604+
document.getElementById("page-title-heading").innerText = "Alert";
605+
var messageElement = document.createElement("span");
606+
messageElement.appendChild(document.createTextNode(message));
607+
document.getElementById("loading_message_p").innerHTML = messageElement.innerText + " <a href=" + linkUrl + ">click here</a>";
599608
} catch (err) {
600609
logger("Error in changing loading message: ", err.message)
601610
}

0 commit comments

Comments
 (0)