|
| 1 | +/** |
| 2 | + * Provides classes modeling security-relevant aspects of the `Flask-Admin` PyPI package |
| 3 | + * (imported as `flask_admin`). |
| 4 | + * |
| 5 | + * See |
| 6 | + * - https://flask-admin.readthedocs.io/en/latest/ |
| 7 | + * - https://pypi.org/project/Flask-Admin/ |
| 8 | + */ |
| 9 | + |
| 10 | +private import python |
| 11 | +private import semmle.python.dataflow.new.DataFlow |
| 12 | +private import semmle.python.dataflow.new.RemoteFlowSources |
| 13 | +private import semmle.python.dataflow.new.TaintTracking |
| 14 | +private import semmle.python.Concepts |
| 15 | +private import semmle.python.frameworks.Flask |
| 16 | +private import semmle.python.ApiGraphs |
| 17 | + |
| 18 | +/** |
| 19 | + * Provides models for the `Flask-Admin` PyPI package (imported as `flask_admin`). |
| 20 | + * |
| 21 | + * See |
| 22 | + * - https://flask-admin.readthedocs.io/en/latest/ |
| 23 | + * - https://pypi.org/project/Flask-Admin/ |
| 24 | + */ |
| 25 | +private module FlaskAdmin { |
| 26 | + /** |
| 27 | + * A call to `flask_admin.expose`, which is used as a decorator to make the |
| 28 | + * function exposed in the admin interface (and make it a request handler) |
| 29 | + * |
| 30 | + * See https://flask-admin.readthedocs.io/en/latest/api/mod_base/#flask_admin.base.expose |
| 31 | + */ |
| 32 | + private class FlaskAdminExposeCall extends Flask::FlaskRouteSetup, DataFlow::CallCfgNode { |
| 33 | + FlaskAdminExposeCall() { |
| 34 | + this = API::moduleImport("flask_admin").getMember("expose").getACall() |
| 35 | + } |
| 36 | + |
| 37 | + override DataFlow::Node getUrlPatternArg() { |
| 38 | + result in [this.getArg(0), this.getArgByName("url")] |
| 39 | + } |
| 40 | + |
| 41 | + override Function getARequestHandler() { result.getADecorator().getAFlowNode() = node } |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * A call to `flask_admin.expose_plugview`, which is used as a decorator to make the |
| 46 | + * class (which we expect to be a flask View class) exposed in the admin interface. |
| 47 | + * |
| 48 | + * See https://flask-admin.readthedocs.io/en/latest/api/mod_base/#flask_admin.base.expose_plugview |
| 49 | + */ |
| 50 | + private class FlaskAdminExposePlugviewCall extends Flask::FlaskRouteSetup, DataFlow::CallCfgNode { |
| 51 | + FlaskAdminExposePlugviewCall() { |
| 52 | + this = API::moduleImport("flask_admin").getMember("expose_plugview").getACall() |
| 53 | + } |
| 54 | + |
| 55 | + override DataFlow::Node getUrlPatternArg() { |
| 56 | + result in [this.getArg(0), this.getArgByName("url")] |
| 57 | + } |
| 58 | + |
| 59 | + override Parameter getARoutedParameter() { |
| 60 | + result = super.getARoutedParameter() and |
| 61 | + ( |
| 62 | + exists(this.getUrlPattern()) |
| 63 | + or |
| 64 | + // the first argument is `self`, and the second argument `cls` will receive the |
| 65 | + // containing flask_admin View class -- this is only relevant if the URL pattern |
| 66 | + // is not known |
| 67 | + not exists(this.getUrlPattern()) and |
| 68 | + not result = this.getARequestHandler().getArg([0, 1]) |
| 69 | + ) |
| 70 | + } |
| 71 | + |
| 72 | + override Function getARequestHandler() { |
| 73 | + exists(Flask::FlaskViewClass cls | |
| 74 | + cls.getADecorator().getAFlowNode() = node and |
| 75 | + result = cls.getARequestHandler() |
| 76 | + ) |
| 77 | + } |
| 78 | + } |
| 79 | +} |
0 commit comments