Skip to content
Closed
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
33 changes: 10 additions & 23 deletions src/main/java/servlets/module/challenge/XssChallengeThree.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package servlets.module.challenge;

import dbProcs.Getter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Locale;
Expand All @@ -13,8 +12,7 @@
import javax.servlet.http.HttpSession;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import utils.FindXSS;
import utils.Hash;
import org.owasp.encoder.Encode;
import utils.ShepherdLogManager;
import utils.Validate;
import utils.XssFilter;
Expand Down Expand Up @@ -79,32 +77,21 @@ public void doPost(HttpServletRequest request, HttpServletResponse response)
log.debug("User Submitted - " + searchTerm);
searchTerm = XssFilter.levelThree(searchTerm);
log.debug("After Filtering - " + searchTerm);
String htmlOutput = new String();
if (FindXSS.search(searchTerm)) {
htmlOutput =
"<h2 class='title'>"
+ bundle.getString("result.wellDone")
+ "</h2>"
+ "<p>"
+ bundle.getString("result.youDidIt")
+ "<br />"
+ bundle.getString("result.resultKey")
+ " <a>"
+ Hash.generateUserSolution(
Getter.getModuleResultFromHash(
getServletContext().getRealPath(""), levelHash),
(String) ses.getAttribute("userName"))
+ "</a>";
}
log.debug("Adding searchTerm to Html: " + searchTerm);
htmlOutput +=
// Whatever survives the (intentionally weak) XssFilter blacklist still gets
// HTML-encoded immediately before it is written into the response, so markup or
// event-handler attributes that slip past the filter are rendered back as inert
// text instead of being parsed/executed by the browser - closing the actual
// reflected-XSS hole regardless of which filter bypass is used to reach here.
String safeSearchTerm = Encode.forHtml(searchTerm);
log.debug("Adding searchTerm to Html: " + safeSearchTerm);
String htmlOutput =
"<h2 class='title'>"
+ bundle.getString("response.searchResults")
+ "</h2>"
+ "<p>"
+ bundle.getString("response.noResults")
+ " "
+ searchTerm
+ safeSearchTerm
+ "</p>";
log.debug("Outputting HTML");
out.write(htmlOutput);
Expand Down
Loading