File tree 2 files changed +4
-6
lines changed
src/main/java/com/github/bgalek/security/svg
2 files changed +4
-6
lines changed Original file line number Diff line number Diff line change 7
7
import javax .xml .parsers .DocumentBuilder ;
8
8
import java .io .ByteArrayInputStream ;
9
9
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 .*;
15
11
import java .util .regex .Pattern ;
16
12
17
13
/**
25
21
public class SvgSecurityValidator implements XssDetector {
26
22
27
23
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 );
28
25
29
26
private final String [] svgElements ;
30
27
private final String [] svgAttributes ;
@@ -81,6 +78,7 @@ private void validateXMLSchema(String input) {
81
78
82
79
private Set <String > getOffendingElements (String xml ) {
83
80
if (JAVASCRIPT_PROTOCOL_IN_CSS_URL .matcher (xml ).find ()) return Collections .singleton ("style" );
81
+ if (SCRIPT_TAG .matcher (xml ).find ()) return Collections .singleton ("script" );
84
82
PolicyFactory policy = new HtmlPolicyBuilder ()
85
83
.allowElements (this .svgElements )
86
84
.allowAttributes (this .svgAttributes ).globally ()
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ public interface ValidationResult {
12
12
boolean hasViolations ();
13
13
14
14
/**
15
- * @return list of invalid elements or attributes found in SVG content
15
+ * @return set of invalid elements or attributes found in SVG content
16
16
*/
17
17
Set <String > getOffendingElements ();
18
18
}
You can’t perform that action at this time.
0 commit comments