|
| 1 | +/** |
| 2 | + * Provides classes modeling security-relevant aspects of the `pyramid` PyPI package. |
| 3 | + * See https://docs.pylonsproject.org/projects/pyramid/. |
| 4 | + */ |
| 5 | + |
| 6 | +private import python |
| 7 | +private import semmle.python.dataflow.new.DataFlow |
| 8 | +private import semmle.python.dataflow.new.RemoteFlowSources |
| 9 | +private import semmle.python.dataflow.new.TaintTracking |
| 10 | +private import semmle.python.Concepts |
| 11 | +private import semmle.python.ApiGraphs |
| 12 | +private import semmle.python.dataflow.new.FlowSummary |
| 13 | +private import semmle.python.frameworks.internal.PoorMansFunctionResolution |
| 14 | +private import semmle.python.frameworks.data.ModelsAsData |
| 15 | + |
| 16 | +/** |
| 17 | + * Provides models for the `pyramid` PyPI package. |
| 18 | + * See https://docs.pylonsproject.org/projects/pyramid/. |
| 19 | + */ |
| 20 | +module Pyramid { |
| 21 | + // TODO: qldoc |
| 22 | + module View { |
| 23 | + /** |
| 24 | + * A callable that could be used as a pyramid view callable. |
| 25 | + */ |
| 26 | + private class PotentialViewCallable extends Function { |
| 27 | + PotentialViewCallable() { |
| 28 | + this.getPositionalParameterCount() = 1 and |
| 29 | + this.getArgName(0) = "request" |
| 30 | + or |
| 31 | + this.getPositionalParameterCount() = 2 and |
| 32 | + this.getArgName(0) = "context" and |
| 33 | + this.getArgName(1) = "request" |
| 34 | + } |
| 35 | + |
| 36 | + /** Gets the `request` parameter of this view callable. */ |
| 37 | + Parameter getRequestParameter() { result = this.getArgByName("request") } |
| 38 | + } |
| 39 | + |
| 40 | + abstract class ViewCallable extends PotentialViewCallable, Http::Server::RequestHandler::Range { |
| 41 | + override Parameter getARoutedParameter() { result = this.getRequestParameter() } |
| 42 | + |
| 43 | + override string getFramework() { result = "Pyramid" } |
| 44 | + } |
| 45 | + |
| 46 | + private class ViewCallableFromDecorator extends ViewCallable { |
| 47 | + ViewCallableFromDecorator() { |
| 48 | + this.getADecorator() = |
| 49 | + API::moduleImport("pyramid") |
| 50 | + .getMember("view") |
| 51 | + .getMember("view_config") |
| 52 | + .getACall() |
| 53 | + .asExpr() |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + private class ViewCallableFromConfigurator extends ViewCallable { |
| 58 | + ViewCallableFromConfigurator() { |
| 59 | + any(Configurator::AddViewCall c).getViewArg() = poorMansFunctionTracker(this) |
| 60 | + } |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + module Configurator { |
| 65 | + /** Gets a reference to the class `pyramid.config.Configurator`. */ |
| 66 | + API::Node classRef() { |
| 67 | + result = API::moduleImport("pyramid").getMember("config").getMember("Configurator") |
| 68 | + } |
| 69 | + |
| 70 | + /** Gets a reference to an instance of `pyramid.config.Configurator`. */ |
| 71 | + private DataFlow::TypeTrackingNode instance(DataFlow::TypeTracker t) { |
| 72 | + t.start() and |
| 73 | + result = classRef().getACall() |
| 74 | + or |
| 75 | + exists(DataFlow::TypeTracker t2 | result = instance(t2).track(t2, t)) |
| 76 | + } |
| 77 | + |
| 78 | + /** Gets a reference to an instance of `pyramid.config.Configurator`. */ |
| 79 | + DataFlow::Node instance() { instance(DataFlow::TypeTracker::end()).flowsTo(result) } |
| 80 | + |
| 81 | + class AddViewCall extends DataFlow::MethodCallNode { |
| 82 | + AddViewCall() { this.calls(instance(), "add_view") } |
| 83 | + |
| 84 | + DataFlow::Node getViewArg() { result = [this.getArg(0), this.getArgByName("view")] } |
| 85 | + } |
| 86 | + } |
| 87 | +} |
0 commit comments