Skip to content

Commit e9c0f17

Browse files
committed
JS: Restrict names of extracted HTML attributes
1 parent d490bea commit e9c0f17

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

javascript/extractor/src/com/semmle/js/extractor/HTMLExtractor.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,18 @@ public void handleElement(Element elt, HtmlPopulator.Context context) {
143143
}
144144
}
145145
}
146+
147+
@Override
148+
public boolean shouldExtractAttributes(Element element) {
149+
Attributes attributes = element.getAttributes();
150+
if (attributes == null) return false;
151+
for (Attribute attr : attributes) {
152+
if (!VALID_ATTRIBUTE_NAME.matcher(attr.getName()).matches()) {
153+
return false;
154+
}
155+
}
156+
return true;
157+
}
146158
}
147159

148160
private boolean isAngularTemplateAttributeName(String name) {
@@ -153,6 +165,8 @@ private boolean isAngularTemplateAttributeName(String name) {
153165

154166
private static final Pattern ANGULAR_FOR_LOOP_DECL = Pattern.compile("^ *let +(\\w+) +of(?: +|(?!\\w))(.*)");
155167

168+
private static final Pattern VALID_ATTRIBUTE_NAME = Pattern.compile("\\*?\\[?\\(?[\\w:_\\-]+\\]?\\)?");
169+
156170
/** List of HTML attributes whose value is interpreted as JavaScript. */
157171
private static final Pattern JS_ATTRIBUTE =
158172
Pattern.compile(

0 commit comments

Comments
 (0)