Skip to content

Commit

Permalink
Sanitize iframe src attribute's input
Browse files Browse the repository at this point in the history
  • Loading branch information
d3xter666 committed Nov 24, 2023
1 parent ff1dc29 commit fbc75aa
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions lib/middleware/testRunner/TestRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,24 @@

var oXHRQueue = new XHRQueue(50, 2);

function sanitizeUrl(potentialUrl) {
var validUrl;
try {
validUrl = new URL(potentialUrl);
return validUrl.href;
} catch (e) {/* It could be a relative URL and we'll give it another try with the current domain name */}

try {
var url = [window.location.origin, potentialUrl].join(
potentialUrl[0] === "/" ? "" : "/"
);
validUrl = new URL(url);
return validUrl.href;
} catch (error) {
return ""; // The potentialUrl so far didn't prove to be a valid url, so return an empty string.
}
}

/*
* Template for test results
*/
Expand Down Expand Up @@ -166,7 +184,7 @@
}.bind(this));
}
});
$frame.attr("src", sTestPage);
$frame.attr("src", sanitizeUrl(sTestPage));
$frame.appendTo(document.body);
} else {
resolve([sTestPage]);
Expand Down Expand Up @@ -358,7 +376,7 @@
width: "1280px"
});

$frame.attr("src", sTestPage);
$frame.attr("src", sanitizeUrl(sTestPage));
var $framediv = jQuery("<div>").css({
height: "400px",
width: "100%",
Expand Down

0 comments on commit fbc75aa

Please sign in to comment.