@@ -18,6 +18,10 @@ abstract class ExternalStringKind extends StringKind {
1818 json_load ( fromnode , tonode ) and result .( ExternalJsonKind ) .getValue ( ) = this
1919 or
2020 tonode .( DictNode ) .getAValue ( ) = fromnode and result .( ExternalStringDictKind ) .getValue ( ) = this
21+ or
22+ urlsplit ( fromnode , tonode ) and result .( ExternalUrlSplitResult ) .getItem ( ) = this
23+ or
24+ urlparse ( fromnode , tonode ) and result .( ExternalUrlParseResult ) .getItem ( ) = this
2125 }
2226}
2327
@@ -65,6 +69,65 @@ class ExternalStringSequenceDictKind extends DictKind {
6569 ExternalStringSequenceDictKind ( ) { this .getValue ( ) instanceof ExternalStringSequenceKind }
6670}
6771
72+ /** TaintKind for the result of `urlsplit(tainted_string)` */
73+ class ExternalUrlSplitResult extends ExternalStringSequenceKind {
74+ // https://docs.python.org/3/library/urllib.parse.html#urllib.parse.urlsplit
75+ override TaintKind getTaintOfAttribute ( string name ) {
76+ result = super .getTaintOfAttribute ( name )
77+ or
78+ (
79+ // namedtuple field names
80+ name = "scheme" or
81+ name = "netloc" or
82+ name = "path" or
83+ name = "query" or
84+ name = "fragment" or
85+ // class methods
86+ name = "username" or
87+ name = "password" or
88+ name = "hostname"
89+ ) and
90+ result instanceof ExternalStringKind
91+ }
92+
93+ override TaintKind getTaintOfMethodResult ( string name ) {
94+ result = super .getTaintOfMethodResult ( name )
95+ or
96+ name = "geturl" and
97+ result instanceof ExternalStringKind
98+ }
99+ }
100+
101+ /** TaintKind for the result of `urlparse(tainted_string)` */
102+ class ExternalUrlParseResult extends ExternalStringSequenceKind {
103+ // https://docs.python.org/3/library/urllib.parse.html#urllib.parse.urlparse
104+ override TaintKind getTaintOfAttribute ( string name ) {
105+ result = super .getTaintOfAttribute ( name )
106+ or
107+ (
108+ // namedtuple field names
109+ name = "scheme" or
110+ name = "netloc" or
111+ name = "path" or
112+ name = "params" or
113+ name = "query" or
114+ name = "fragment" or
115+ // class methods
116+ name = "username" or
117+ name = "password" or
118+ name = "hostname"
119+ ) and
120+ result instanceof ExternalStringKind
121+ }
122+
123+ override TaintKind getTaintOfMethodResult ( string name ) {
124+ result = super .getTaintOfMethodResult ( name )
125+ or
126+ name = "geturl" and
127+ result instanceof ExternalStringKind
128+ }
129+ }
130+
68131/* Helper for getTaintForStep() */
69132pragma [ noinline]
70133private predicate json_subscript_taint (
@@ -83,6 +146,44 @@ private predicate json_load(ControlFlowNode fromnode, CallNode tonode) {
83146 )
84147}
85148
149+ private predicate urlsplit ( ControlFlowNode fromnode , CallNode tonode ) {
150+ // This could be implemented as `exists(FunctionValue` without the explicit six part,
151+ // but then our tests will need to import +100 modules, so for now this slightly
152+ // altered version gets to live on.
153+ exists ( Value urlsplit |
154+ (
155+ urlsplit = Value:: named ( "six.moves.urllib.parse.urlsplit" )
156+ or
157+ // Python 2
158+ urlsplit = Value:: named ( "urlparse.urlsplit" )
159+ or
160+ // Python 3
161+ urlsplit = Value:: named ( "urllib.parse.urlsplit" )
162+ ) and
163+ tonode = urlsplit .getACall ( ) and
164+ tonode .getArg ( 0 ) = fromnode
165+ )
166+ }
167+
168+ private predicate urlparse ( ControlFlowNode fromnode , CallNode tonode ) {
169+ // This could be implemented as `exists(FunctionValue` without the explicit six part,
170+ // but then our tests will need to import +100 modules, so for now this slightly
171+ // altered version gets to live on.
172+ exists ( Value urlparse |
173+ (
174+ urlparse = Value:: named ( "six.moves.urllib.parse.urlparse" )
175+ or
176+ // Python 2
177+ urlparse = Value:: named ( "urlparse.urlparse" )
178+ or
179+ // Python 3
180+ urlparse = Value:: named ( "urllib.parse.urlparse" )
181+ ) and
182+ tonode = urlparse .getACall ( ) and
183+ tonode .getArg ( 0 ) = fromnode
184+ )
185+ }
186+
86187/** A kind of "taint", representing an open file-like object from an external source. */
87188class ExternalFileObject extends TaintKind {
88189 ExternalFileObject ( ) { this = "file[" + any ( ExternalStringKind key ) + "]" }
0 commit comments