1
1
/**
2
- * @name Unsafe expansion of shorthand HTML tag
3
- * @description Using regular expressions to expand shorthand HTML
2
+ * @name Unsafe expansion of self-closing HTML tag
3
+ * @description Using regular expressions to expand self-closing HTML
4
4
* tags may lead to cross-site scripting vulnerabilities.
5
5
* @kind problem
6
6
* @problem.severity warning
15
15
import javascript
16
16
17
17
/**
18
- * A regular expression that captures the name and content of a shorthand HTML tag such as `<div id='foo'/>`.
18
+ * A regular expression that captures the name and content of a
19
+ * self-closing HTML tag such as `<div id='foo'/>`.
19
20
*/
20
- class ShorthandTagRecognizer extends RegExpLiteral {
21
- ShorthandTagRecognizer ( ) {
21
+ class SelfClosingTagRecognizer extends DataFlow :: RegExpCreationNode {
22
+ SelfClosingTagRecognizer ( ) {
22
23
exists ( RegExpSequence seq , RegExpGroup name , RegExpGroup content |
23
24
// `/.../g`
24
- this .isGlobal ( ) and
25
- this = seq .getLiteral ( ) and
25
+ RegExp :: isGlobal ( this .getFlags ( ) ) and
26
+ this . getRoot ( ) = seq .getRootTerm ( ) and
26
27
// `/<.../`
27
28
seq .getChild ( 0 ) .getConstantValue ( ) = "<" and
28
29
// `/...\/>/`
@@ -46,22 +47,12 @@ class ShorthandTagRecognizer extends RegExpLiteral {
46
47
)
47
48
)
48
49
}
49
-
50
- /**
51
- * Gets a data flow node that may refer to this regular expression.
52
- */
53
- DataFlow:: SourceNode ref ( DataFlow:: TypeTracker t ) {
54
- t .start ( ) and
55
- result = this .flow ( )
56
- or
57
- exists ( DataFlow:: TypeTracker t2 | result = ref ( t2 ) .track ( t2 , t ) )
58
- }
59
50
}
60
51
61
- from ShorthandTagRecognizer regexp , StringReplaceCall replace
52
+ from SelfClosingTagRecognizer regexp , StringReplaceCall replace
62
53
where
63
- regexp .ref ( DataFlow :: TypeTracker :: end ( ) ) .flowsTo ( replace .getArgument ( 0 ) ) and
54
+ regexp .getAReference ( ) .flowsTo ( replace .getArgument ( 0 ) ) and
64
55
replace .getRawReplacement ( ) .mayHaveStringValue ( "<$1></$2>" )
65
56
select replace ,
66
- "This HTML tag expansion may disable earlier sanitizations as $@ may match unintended strings ." ,
57
+ "This self-closing HTML tag expansion invalidates prior sanitization as $@ may match part of an attribute value ." ,
67
58
regexp , "this regular expression"
0 commit comments