@@ -27,6 +27,13 @@ module XssThroughDom {
2727 result = [ "name" , "value" , "title" , "alt" ]
2828 }
2929
30+ /**
31+ * Gets a DOM property name that could store user-controlled data.
32+ */
33+ string unsafeDomPropertyName ( ) {
34+ result = [ "innerText" , "textContent" , "value" , "name" ]
35+ }
36+
3037 /**
3138 * A source for text from the DOM from a JQuery method call.
3239 */
@@ -51,14 +58,32 @@ module XssThroughDom {
5158 }
5259 }
5360
61+ /**
62+ * A source for text from the DOM from a `d3` method call.
63+ */
64+ class D3TextSource extends Source {
65+ D3TextSource ( ) {
66+ exists ( DataFlow:: MethodCallNode call , string methodName , string argValue |
67+ this = call and
68+ call = D3:: d3Selection ( ) .getMember ( methodName ) .getACall ( ) and
69+ call .getNumArgument ( ) = 1 and
70+ call .getArgument ( 0 ) .mayHaveStringValue ( argValue )
71+ |
72+ methodName = "attr" and argValue = unsafeAttributeName ( )
73+ or
74+ methodName = "property" and argValue = unsafeDomPropertyName ( )
75+ )
76+ }
77+ }
78+
5479 /**
5580 * A source for text from the DOM from a DOM property read or call to `getAttribute()`.
5681 */
5782 class DOMTextSource extends Source {
5883 DOMTextSource ( ) {
5984 exists ( DataFlow:: PropRead read | read = this |
6085 read .getBase ( ) .getALocalSource ( ) = DOM:: domValueRef ( ) and
61- read .mayHavePropertyName ( [ "innerText" , "textContent" , "value" , "name" ] )
86+ read .mayHavePropertyName ( unsafeDomPropertyName ( ) )
6287 )
6388 or
6489 exists ( DataFlow:: MethodCallNode mcn | mcn = this |
0 commit comments