|
| 1 | +import python |
| 2 | +private import semmle.python.ApiGraphs |
| 3 | +private import semmle.python.dataflow.new.RemoteFlowSources |
| 4 | +private import semmle.python.frameworks.internal.InstanceTaintStepsHelper |
| 5 | + |
| 6 | +module Connexion { |
| 7 | + API::Node request() { result = API::moduleImport("connexion").getMember("request") } |
| 8 | + |
| 9 | + private class ConnexionRequestSource extends RemoteFlowSource::Range { |
| 10 | + ConnexionRequestSource() { |
| 11 | + this = request().getAUse() and |
| 12 | + not any(Import imp).contains(this.asExpr()) and |
| 13 | + not exists(ControlFlowNode def | this.asVar().getSourceVariable().hasDefiningNode(def) | |
| 14 | + any(Import imp).contains(def.getNode()) |
| 15 | + ) |
| 16 | + } |
| 17 | + |
| 18 | + override string getSourceType() { result = "connexion.request" } |
| 19 | + } |
| 20 | + |
| 21 | + private class InstanceTaintSteps extends InstanceTaintStepsHelper { |
| 22 | + InstanceTaintSteps() { this = "connexion.Request" } |
| 23 | + |
| 24 | + override DataFlow::Node getInstance() { result = request().getAUse() } |
| 25 | + |
| 26 | + override string getAttributeName() { |
| 27 | + result in [ |
| 28 | + // str |
| 29 | + "path", "full_path", "base_url", "url", "access_control_request_method", |
| 30 | + "content_encoding", "content_md5", "content_type", "data", "method", "mimetype", "origin", |
| 31 | + "query_string", "referrer", "remote_addr", "remote_user", "user_agent", |
| 32 | + // dict |
| 33 | + "environ", "cookies", "mimetype_params", "view_args", |
| 34 | + // json |
| 35 | + "json", |
| 36 | + // List[str] |
| 37 | + "access_route", |
| 38 | + // file-like |
| 39 | + "stream", "input_stream", |
| 40 | + // MultiDict[str, str] |
| 41 | + // https://werkzeug.palletsprojects.com/en/1.0.x/datastructures/#werkzeug.datastructures.MultiDict |
| 42 | + "args", "values", "form", |
| 43 | + // MultiDict[str, FileStorage] |
| 44 | + // https://werkzeug.palletsprojects.com/en/1.0.x/datastructures/#werkzeug.datastructures.FileStorage |
| 45 | + // TODO: FileStorage needs extra taint steps |
| 46 | + "files", |
| 47 | + // https://werkzeug.palletsprojects.com/en/1.0.x/datastructures/#werkzeug.datastructures.HeaderSet |
| 48 | + "access_control_request_headers", "pragma", |
| 49 | + // https://werkzeug.palletsprojects.com/en/1.0.x/datastructures/#werkzeug.datastructures.Accept |
| 50 | + // TODO: Kinda badly modeled for now -- has type List[Tuple[value, quality]], and some extra methods |
| 51 | + "accept_charsets", "accept_encodings", "accept_languages", "accept_mimetypes", |
| 52 | + // https://werkzeug.palletsprojects.com/en/1.0.x/datastructures/#werkzeug.datastructures.Authorization |
| 53 | + // TODO: dict subclass with extra attributes like `username` and `password` |
| 54 | + "authorization", |
| 55 | + // https://werkzeug.palletsprojects.com/en/1.0.x/datastructures/#werkzeug.datastructures.RequestCacheControl |
| 56 | + // TODO: has attributes like `no_cache`, and `to_header` method (actually, many of these models do) |
| 57 | + "cache_control", |
| 58 | + // https://werkzeug.palletsprojects.com/en/1.0.x/datastructures/#werkzeug.datastructures.Headers |
| 59 | + // TODO: dict-like with wsgiref.headers.Header compatibility methods |
| 60 | + "headers" |
| 61 | + ] |
| 62 | + } |
| 63 | + |
| 64 | + override string getMethodName() { result in ["get_data", "get_json"] } |
| 65 | + |
| 66 | + override string getAsyncMethodName() { none() } |
| 67 | + } |
| 68 | +} |
0 commit comments