1+ /**
2+ * Provides classes for finding functionality that is loaded from untrusted sources and used in script or frame elements.
3+ */
4+
15import javascript
26
37/** A location that adds a reference to an untrusted source. */
@@ -9,6 +13,7 @@ abstract class AddsUntrustedUrl extends Locatable {
913 abstract string getUrl ( ) ;
1014}
1115
16+ /** Looks for static creation of an element and source. */
1217module StaticCreation {
1318 /** Holds if `host` is an alias of localhost. */
1419 bindingset [ host]
@@ -78,13 +83,15 @@ module StaticCreation {
7883 }
7984}
8085
86+ /** Looks for dyanmic creation of an element and source. */
8187module DynamicCreation {
8288 /** Holds if `call` creates a tag of kind `name`. */
8389 predicate isCreateElementNode ( DataFlow:: CallNode call , string name ) {
8490 call = DataFlow:: globalVarRef ( "document" ) .getAMethodCall ( "createElement" ) and
8591 call .getArgument ( 0 ) .getStringValue ( ) .toLowerCase ( ) = name
8692 }
8793
94+ /** Get the right-hand side of an assignment to a named attribute. */
8895 DataFlow:: Node getAttributeAssignmentRhs ( DataFlow:: CallNode createCall , string name ) {
8996 result = createCall .getAPropertyWrite ( name ) .getRhs ( )
9097 or
@@ -103,6 +110,7 @@ module DynamicCreation {
103110 not exists ( getAttributeAssignmentRhs ( createCall , "integrity" ) )
104111 }
105112
113+ /** Holds if `t` tracks a URL that is loaded from an untrusted source. */
106114 DataFlow:: Node urlTrackedFromUnsafeSourceLiteral ( DataFlow:: TypeTracker t ) {
107115 t .start ( ) and result .getStringValue ( ) .regexpMatch ( "(?i)http:.*" )
108116 or
@@ -126,6 +134,7 @@ module DynamicCreation {
126134 )
127135 }
128136
137+ /** Holds a dataflow node is traked from an untrusted source. */
129138 DataFlow:: Node urlTrackedFromUnsafeSourceLiteral ( ) {
130139 result = urlTrackedFromUnsafeSourceLiteral ( DataFlow:: TypeTracker:: end ( ) )
131140 }
@@ -144,6 +153,7 @@ module DynamicCreation {
144153 )
145154 }
146155
156+ /** A script or iframe element that refers to untrusted content. */
147157 class IframeOrScriptSrcAssignment extends AddsUntrustedUrl {
148158 string name ;
149159
0 commit comments