11import python
22import semmle.python.web.Http
33
4-
54/** The falcon API class */
6- ClassObject theFalconAPIClass ( ) {
7- result = ModuleObject:: named ( "falcon" ) .attr ( "API" )
8- }
5+ ClassValue theFalconAPIClass ( ) { result = Value:: named ( "falcon.API" ) }
96
10-
11- /** Holds if `route` is routed to `resource`
12- */
13- private predicate api_route ( CallNode route_call , ControlFlowNode route , ClassObject resource ) {
14- route_call .getFunction ( ) .( AttrNode ) .getObject ( "add_route" ) .refersTo ( _, theFalconAPIClass ( ) , _) and
7+ /** Holds if `route` is routed to `resource` */
8+ private predicate api_route ( CallNode route_call , ControlFlowNode route , ClassValue resource ) {
9+ route_call .getFunction ( ) .( AttrNode ) .getObject ( "add_route" ) .pointsTo ( ) .getClass ( ) = theFalconAPIClass ( ) and
1510 route_call .getArg ( 0 ) = route and
16- route_call .getArg ( 1 ) .refersTo ( _ , resource , _ )
11+ route_call .getArg ( 1 ) .pointsTo ( ) . getClass ( ) = resource
1712}
1813
1914private predicate route ( FalconRoute route , Function target , string funcname ) {
20- route .getResourceClass ( ) .lookupAttribute ( "on_" + funcname ) .( FunctionObject ) . getFunction ( ) = target
15+ route .getResourceClass ( ) .lookup ( "on_" + funcname ) .( FunctionValue ) . getScope ( ) = target
2116}
2217
2318class FalconRoute extends ControlFlowNode {
24-
25- FalconRoute ( ) {
26- api_route ( this , _, _)
27- }
19+ FalconRoute ( ) { api_route ( this , _, _) }
2820
2921 string getUrl ( ) {
3022 exists ( StrConst url |
@@ -33,36 +25,19 @@ class FalconRoute extends ControlFlowNode {
3325 )
3426 }
3527
36- ClassObject getResourceClass ( ) {
37- api_route ( this , _, result )
38- }
39-
40- FalconHandlerFunction getHandlerFunction ( string method ) {
41- route ( this , result , method )
42- }
28+ ClassValue getResourceClass ( ) { api_route ( this , _, result ) }
4329
30+ FalconHandlerFunction getHandlerFunction ( string method ) { route ( this , result , method ) }
4431}
4532
4633class FalconHandlerFunction extends Function {
34+ FalconHandlerFunction ( ) { route ( _, this , _) }
4735
48- FalconHandlerFunction ( ) {
49- route ( _, this , _)
50- }
51-
52- private string methodName ( ) {
53- route ( _, this , result )
54- }
36+ private string methodName ( ) { route ( _, this , result ) }
5537
56- string getMethod ( ) {
57- result = this .methodName ( ) .toUpperCase ( )
58- }
38+ string getMethod ( ) { result = this .methodName ( ) .toUpperCase ( ) }
5939
60- Parameter getRequest ( ) {
61- result = this .getArg ( 1 )
62- }
63-
64- Parameter getResponse ( ) {
65- result = this .getArg ( 2 )
66- }
40+ Parameter getRequest ( ) { result = this .getArg ( 1 ) }
6741
42+ Parameter getResponse ( ) { result = this .getArg ( 2 ) }
6843}
0 commit comments