|
| 1 | +import python |
| 2 | +import semmle.python.web.Http |
| 3 | + |
| 4 | + |
| 5 | +/** The falcon API class */ |
| 6 | +ClassObject theFalconAPIClass() { |
| 7 | + result = ModuleObject::named("falcon").getAttribute("API") |
| 8 | +} |
| 9 | + |
| 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 |
| 15 | + route_call.getArg(0) = route and |
| 16 | + route_call.getArg(1).refersTo(_, resource, _) |
| 17 | +} |
| 18 | + |
| 19 | +class FalconRoute extends ControlFlowNode { |
| 20 | + |
| 21 | + FalconRoute() { |
| 22 | + api_route(this, _, _) |
| 23 | + } |
| 24 | + |
| 25 | + string getUrl() { |
| 26 | + exists(StrConst url | |
| 27 | + api_route(this, url.getAFlowNode(), _) and |
| 28 | + result = url.getText() |
| 29 | + ) |
| 30 | + } |
| 31 | + |
| 32 | + ClassObject getResourceClass() { |
| 33 | + api_route(this, _, result) |
| 34 | + } |
| 35 | + |
| 36 | + FalconHandlerFunction getHandlerFunction() { |
| 37 | + result = this.getResourceClass().lookupAttribute(_).(FunctionObject).getFunction() |
| 38 | + } |
| 39 | + |
| 40 | + FalconHandlerFunction getHandlerFunction(string method) { |
| 41 | + result = this.getResourceClass().lookupAttribute("on_" + method).(FunctionObject).getFunction() |
| 42 | + } |
| 43 | + |
| 44 | +} |
| 45 | + |
| 46 | +class FalconHandlerFunction extends Function { |
| 47 | + |
| 48 | + string method; |
| 49 | + |
| 50 | + FalconHandlerFunction() { |
| 51 | + exists(ClassObject resource | |
| 52 | + resource.lookupAttribute("on_" + method).(FunctionObject).getFunction() = this |
| 53 | + ) |
| 54 | + } |
| 55 | + |
| 56 | + string getMethod() { |
| 57 | + result = method.toUpperCase() |
| 58 | + } |
| 59 | + |
| 60 | + Parameter getRequest() { |
| 61 | + result = this.getArg(1) |
| 62 | + } |
| 63 | + |
| 64 | + Parameter getResponse() { |
| 65 | + result = this.getArg(2) |
| 66 | + } |
| 67 | + |
| 68 | +} |
0 commit comments