@@ -142,6 +142,14 @@ private module Tornado {
142
142
class RequestHandlerClass extends Class {
143
143
RequestHandlerClass ( ) { this .getParent ( ) = subclassRef ( ) .asExpr ( ) }
144
144
145
+ /** Gets a function that could handle incoming requests, if any. */
146
+ Function getARequestHandler ( ) {
147
+ // TODO: This doesn't handle attribute assignment. Should be OK, but analysis is not as complete as with
148
+ // points-to and `.lookup`, which would handle `post = my_post_handler` inside class def
149
+ result = this .getAMethod ( ) and
150
+ result .getName ( ) = HTTP:: httpVerbLower ( )
151
+ }
152
+
145
153
/** Gets a reference to this class. */
146
154
private DataFlow:: Node getARef ( DataFlow:: TypeTracker t ) {
147
155
t .start ( ) and
@@ -489,9 +497,7 @@ private module Tornado {
489
497
override Function getARequestHandler ( ) {
490
498
exists ( tornado:: web:: RequestHandler:: RequestHandlerClass cls |
491
499
cls .getARef ( ) .asCfgNode ( ) = node .getElement ( 1 ) and
492
- // TODO: Proper MRO
493
- result = cls .getAMethod ( ) and
494
- result .getName ( ) = HTTP:: httpVerbLower ( )
500
+ result = cls .getARequestHandler ( )
495
501
)
496
502
}
497
503
@@ -516,4 +522,22 @@ private module Tornado {
516
522
)
517
523
}
518
524
}
525
+
526
+ /** A request handler defined in a tornado RequestHandler class, that has no known route. */
527
+ private class TornadoRequestHandlerWithoutKnownRoute extends HTTP:: Server:: RequestHandler:: Range {
528
+ TornadoRequestHandlerWithoutKnownRoute ( ) {
529
+ exists ( tornado:: web:: RequestHandler:: RequestHandlerClass cls |
530
+ cls .getARequestHandler ( ) = this
531
+ ) and
532
+ not exists ( TornadoRouteSetup setup | setup .getARequestHandler ( ) = this )
533
+ }
534
+
535
+ override Parameter getARoutedParameter ( ) {
536
+ // Since we don't know the URL pattern, we simply mark all parameters as a routed
537
+ // parameter. This should give us more RemoteFlowSources but could also lead to
538
+ // more FPs. If this turns out to be the wrong tradeoff, we can always change our mind.
539
+ result in [ this .getArg ( _) , this .getArgByName ( _) ] and
540
+ not result = this .getArg ( 0 )
541
+ }
542
+ }
519
543
}
0 commit comments