Skip to content

Commit a700aa4

Browse files
authored
Merge pull request #15110 from rvermeulen/rvermeulen/xml-attr-data-flow-node
JavaScript: Add support for XML attributes in the data flow graph
2 parents e838562 + 133a243 commit a700aa4

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

javascript/ql/lib/semmle/javascript/PrintAst.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ private newtype TPrintAstNode =
8383
shouldPrint(term, _) and
8484
term.isUsedAsRegExp() and
8585
any(RegExpLiteral lit).getRoot() = term.getRootTerm()
86-
}
86+
} or
87+
TXmlAttributeNode(XmlAttribute attr) { shouldPrint(attr, _) and not isNotNeeded(attr) }
8788

8889
/**
8990
* A node in the output tree.

javascript/ql/lib/semmle/javascript/dataflow/DataFlow.qll

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,28 @@ module DataFlow {
972972
override File getFile() { result = attr.getFile() }
973973
}
974974

975+
/**
976+
* A data flow node representing an XML attribute.
977+
*/
978+
class XmlAttributeNode extends DataFlow::Node, TXmlAttributeNode {
979+
XmlAttribute attr;
980+
981+
XmlAttributeNode() { this = TXmlAttributeNode(attr) }
982+
983+
override string toString() { result = attr.toString() }
984+
985+
override predicate hasLocationInfo(
986+
string filepath, int startline, int startcolumn, int endline, int endcolumn
987+
) {
988+
attr.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
989+
}
990+
991+
/** Gets the attribute corresponding to this data flow node. */
992+
XmlAttribute getAttribute() { result = attr }
993+
994+
override File getFile() { result = attr.getLocation().getFile() }
995+
}
996+
975997
/**
976998
* A data flow node representing the exceptions thrown by a function.
977999
*/

javascript/ql/lib/semmle/javascript/dataflow/internal/DataFlowNode.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ newtype TNode =
2727
exists(decl.getASpecifier().getImportedName())
2828
} or
2929
THtmlAttributeNode(HTML::Attribute attr) or
30+
TXmlAttributeNode(XmlAttribute attr) or
3031
TFunctionReturnNode(Function f) or
3132
TExceptionalFunctionReturnNode(Function f) or
3233
TExceptionalInvocationReturnNode(InvokeExpr e) or

0 commit comments

Comments
 (0)