|
| 1 | +import python |
| 2 | + |
| 3 | +import semmle.python.security.TaintTracking |
| 4 | + |
| 5 | +private ClassObject theTurboGearsControllerClass() { |
| 6 | + result = ModuleObject::named("tg").getAttribute("TGController") |
| 7 | +} |
| 8 | + |
| 9 | + |
| 10 | +ClassObject aTurboGearsControllerClass() { |
| 11 | + result.getASuperType() = theTurboGearsControllerClass() |
| 12 | +} |
| 13 | + |
| 14 | + |
| 15 | +class TurboGearsControllerMethod extends Function { |
| 16 | + |
| 17 | + ControlFlowNode decorator; |
| 18 | + |
| 19 | + TurboGearsControllerMethod() { |
| 20 | + aTurboGearsControllerClass().getPyClass() = this.getScope() and |
| 21 | + decorator = this.getADecorator().getAFlowNode() and |
| 22 | + /* Is decorated with @expose() or @expose(path) */ |
| 23 | + ( |
| 24 | + decorator.(CallNode).getFunction().(NameNode).getId() = "expose" |
| 25 | + or |
| 26 | + decorator.refersTo(_, ModuleObject::named("tg").getAttribute("expose"), _) |
| 27 | + ) |
| 28 | + } |
| 29 | + |
| 30 | + private ControlFlowNode templateName() { |
| 31 | + result = decorator.(CallNode).getArg(0) |
| 32 | + } |
| 33 | + |
| 34 | + predicate isTemplated() { |
| 35 | + exists(templateName()) |
| 36 | + } |
| 37 | + |
| 38 | + string getTemplateName() { |
| 39 | + exists(StringObject str | |
| 40 | + templateName().refersTo(str) and |
| 41 | + result = str.getText() |
| 42 | + ) |
| 43 | + } |
| 44 | + |
| 45 | + Dict getValidationDict() { |
| 46 | + exists(Call call, Object dict | |
| 47 | + call = this.getADecorator() and |
| 48 | + call.getFunc().(Name).getId() = "validate" and |
| 49 | + call.getArg(0).refersTo(dict) and |
| 50 | + result = dict.getOrigin() |
| 51 | + ) |
| 52 | + } |
| 53 | + |
| 54 | +} |
| 55 | + |
0 commit comments