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
11 changes: 8 additions & 3 deletions src/main/java/utils/XssFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,18 @@ public static String anotherBadUrlValidate(String input) {
input = input.toLowerCase();
if (input.startsWith("http")) {
try {
// Every occurrence of an attribute-breakout character must be neutralised, not just the
// first one - a second, un-escaped '<' / '>' / '"' / '\'' later in the string still lets
// an attacker close the surrounding href="" attribute and inject a fresh HTML attribute
// (e.g. onmouseover=alert(1)) or a whole new tag.
URL theUrl =
new URL(
input
.replaceAll("#", "&#x23;")
.replaceFirst("<", "&#x3c;")
.replaceFirst(">", "&#x3e;")
.replaceFirst("\"", "&quot;"));
.replaceAll("<", "&#x3c;")
.replaceAll(">", "&#x3e;")
.replaceAll("\"", "&quot;")
.replaceAll("'", "&#x27;"));
input = theUrl.toString();
} catch (MalformedURLException e) {
log.debug("Could not Cast URL from input: " + e.toString());
Expand Down
Loading