Skip to content
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
1 change: 1 addition & 0 deletions src/main/resources/i18n/text.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ generic.text.scoreboard = Scoreboard
generic.text.searchModules = Search Modules
generic.text.shepherdVersion = Security Shepherd Version: 3.0
generic.text.sorryError = Sorry but there was an error
generic.text.invalidModuleAddress = invalid module address
generic.text.submitResult = Submit Result Key Here
generic.text.submit = Submit
generic.text.username = Username
Expand Down
1 change: 1 addition & 0 deletions src/main/webapp/css/theCss.css
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ a:hover {
word-wrap: break-word;
width: 100%;
height: 2056px;
border: 0;
}

.levelList {
Expand Down
18 changes: 13 additions & 5 deletions src/main/webapp/getStarted.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,20 @@ else
var theRefreshError = "Could not Refresh Menu";

$('#getStarted').slideDown("slow");
$('#cantSee').html("<iframe class='levelIframe' frameborder='no' id='theStart' src='readyToPlay.jsp'></iframe>");
$('#cantSee').html(function(){
$("#theStart").load(function(){
$("#contentDiv").slideDown("slow");
});
$("#cantSee").empty();
var startFrame = document.createElement("iframe");
startFrame.setAttribute("id", "theStart");
startFrame.setAttribute("class", "levelIframe");
startFrame.setAttribute("title", "Security Shepherd getting started");
// no loading="lazy" here: the frame sits in a hidden div until it fires load
// itself, so lazy loading never triggers and the welcome view stays blank
startFrame.setAttribute("referrerpolicy", "same-origin");
startFrame.setAttribute("sandbox", "allow-same-origin allow-scripts allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-downloads");
startFrame.setAttribute("src", "readyToPlay.jsp");
$(startFrame).on("load", function(){
$("#contentDiv").slideDown("slow");
});
$("#cantSee").append(startFrame);
<% if (isAdmin) { %>
$("#allApplication").click(function(){
if ($('#unsafeLevels').is(":checked"))
Expand Down
69 changes: 60 additions & 9 deletions src/main/webapp/index.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,36 @@ if (request.getSession() != null)
%>

<script>
var SHEPHERD_FRAME_SANDBOX = "allow-same-origin allow-scripts allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-downloads";
function isSafeModuleSrc(src) {
if (!src || typeof src !== "string") {
return false;
}
var trimmed = src.replace(/^\s+|\s+$/g, "");
if (trimmed === "") {
return false;
}
var lower = trimmed.toLowerCase();
if (lower.indexOf("javascript:") === 0 || lower.indexOf("data:") === 0 || lower.indexOf("vbscript:") === 0) {
return false;
}
if (trimmed.indexOf("://") !== -1 || trimmed.indexOf("//") === 0) {
return false;
}
return true;
}
function createModuleFrame(frameId, src, title) {
var frame = document.createElement("iframe");
frame.setAttribute("id", frameId);
frame.setAttribute("class", "levelIframe");
frame.setAttribute("title", title);
// no loading="lazy" here: these frames start hidden and lazy loading never
// triggers for a hidden element, so the lesson never loads (issue 914 review)
frame.setAttribute("referrerpolicy", "same-origin");
frame.setAttribute("sandbox", SHEPHERD_FRAME_SANDBOX);
frame.setAttribute("src", src);
return frame;
}
function applyMenuButtonActionsOpenOrTourney(theCsrfToken, theErrorMessage){
console.log("Applying Menu Actions For Open/Tourney");

Expand All @@ -791,8 +821,13 @@ if (request.getSession() != null)
if(ajaxCall.status == 200)
{
theActualFile = ajaxCall.responseText;
$('#contentDiv').html("<iframe frameborder='no' class='levelIframe' id='theChallenge' src='" + theActualFile + "'></iframe>");
$("#theChallenge").load(function(){
if (!isSafeModuleSrc(theActualFile)) {
$('#contentDiv').html("<p> <fmt:message key="generic.text.sorryError" />: <fmt:message key="generic.text.invalidModuleAddress" /></p>");
$("#contentDiv").slideDown("slow");
} else {
$("#contentDiv").empty();
var challengeFrame = createModuleFrame("theChallenge", theActualFile, "Security Shepherd challenge module");
$(challengeFrame).on("load", function(){
<%if (showCheatSheet) {%>
$("#submitResult").slideDown("fast", function(){
$("#cheatSheetButton").slideDown("fast", function(){
Expand All @@ -818,8 +853,10 @@ if (request.getSession() != null)
});
});
<%}%>
}).appendTo('#contentDiv');
});
$("#contentDiv").append(challengeFrame);
$("#theSidebarWrapper").height($("#contentDiv").height());
}
}
else
{
Expand Down Expand Up @@ -847,8 +884,13 @@ if (request.getSession() != null)
if(ajaxCall.status == 200)
{
theActualFile = ajaxCall.responseText;
$('#contentDiv').html("<iframe frameborder='no' class='levelIframe' id='theLesson' src='" + theActualFile + "'></iframe>");
$("#theLesson").load(function(){
if (!isSafeModuleSrc(theActualFile)) {
$('#contentDiv').html("<p> <fmt:message key="generic.text.sorryError" />: <fmt:message key="generic.text.invalidModuleAddress" /></p>");
$("#contentDiv").slideDown("slow");
} else {
$("#contentDiv").empty();
var lessonFrame = createModuleFrame("theLesson", theActualFile, "Security Shepherd lesson module");
$(lessonFrame).on("load", function(){
<%if (showCheatSheet) {%>
$("#submitResult").slideDown("fast", function(){
$("#cheatSheetButton").slideDown("fast", function(){
Expand All @@ -874,8 +916,10 @@ if (request.getSession() != null)
});
});
<%}%>
}).appendTo('#contentDiv');
});
$("#contentDiv").append(lessonFrame);
$("#theSidebarWrapper").height($("#contentDiv").height());
}
}
else
{
Expand Down Expand Up @@ -918,8 +962,13 @@ if (request.getSession() != null)
});
if(ajaxCall.status == 200) {
theActualFile = ajaxCall.responseText;
$('#contentDiv').html("<iframe frameborder='no' class='levelIframe' id='theLesson' src='" + theActualFile + "'></iframe>");
$("#theLesson").load(function(){
if (!isSafeModuleSrc(theActualFile)) {
$('#contentDiv').html("<p> " + theErrorMessage + ": <fmt:message key="generic.text.invalidModuleAddress" /></p>");
$("#contentDiv").slideDown("slow");
} else {
$("#contentDiv").empty();
var ctfLessonFrame = createModuleFrame("theLesson", theActualFile, "Security Shepherd lesson module");
$(ctfLessonFrame).on("load", function(){
<%if (showCheatSheet) {%>
$("#submitResult").slideDown("fast", function(){
$("#cheatSheetButton").slideDown("fast", function(){
Expand All @@ -945,7 +994,9 @@ if (request.getSession() != null)
});
});
<%}%>
}).appendTo('#contentDiv');
});
$("#contentDiv").append(ctfLessonFrame);
}
} else {
$('#contentDiv').html("<p> " + theErrorMessage + ": " + ajaxCall.status + " " + ajaxCall.statusText + "</p>");
$("#contentDiv").slideDown("slow");
Expand Down
Loading