Skip to content

Commit 79837a6

Browse files
authored
Merge branch 'main' into script-tag-in-style
2 parents a5314ce + 00546f7 commit 79837a6

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

src/main/java/com/github/bgalek/security/svg/SvgSecurityValidator.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@
77
import javax.xml.parsers.DocumentBuilder;
88
import java.io.ByteArrayInputStream;
99
import java.nio.charset.StandardCharsets;
10-
import java.util.Arrays;
11-
import java.util.Collections;
12-
import java.util.HashSet;
13-
import java.util.Objects;
14-
import java.util.Set;
10+
import java.util.*;
1511
import java.util.regex.Pattern;
1612

1713
/**
@@ -25,6 +21,7 @@
2521
public class SvgSecurityValidator implements XssDetector {
2622

2723
private static final Pattern JAVASCRIPT_PROTOCOL_IN_CSS_URL = Pattern.compile("url\\(.?javascript");
24+
private static final Pattern SCRIPT_TAG = Pattern.compile("</?\\s*(?)script\\s*[a-zA-Z=/\"]*\\s*>", Pattern.CASE_INSENSITIVE);
2825

2926
private final String[] svgElements;
3027
private final String[] svgAttributes;
@@ -81,6 +78,7 @@ private void validateXMLSchema(String input) {
8178

8279
private Set<String> getOffendingElements(String xml) {
8380
if (JAVASCRIPT_PROTOCOL_IN_CSS_URL.matcher(xml).find()) return Collections.singleton("style");
81+
if (SCRIPT_TAG.matcher(xml).find()) return Collections.singleton("script");
8482
PolicyFactory policy = new HtmlPolicyBuilder()
8583
.allowElements(this.svgElements)
8684
.allowAttributes(this.svgAttributes).globally()

src/main/java/com/github/bgalek/security/svg/ValidationResult.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public interface ValidationResult {
1212
boolean hasViolations();
1313

1414
/**
15-
* @return list of invalid elements or attributes found in SVG content
15+
* @return set of invalid elements or attributes found in SVG content
1616
*/
1717
Set<String> getOffendingElements();
1818
}

0 commit comments

Comments
 (0)