|
| 1 | +/** |
| 2 | + * Provides classes modeling security-relevant aspects of the `httpx` PyPI package. |
| 3 | + * |
| 4 | + * See |
| 5 | + * - https://pypi.org/project/httpx/ |
| 6 | + * - https://www.python-httpx.org/ |
| 7 | + */ |
| 8 | + |
| 9 | +private import python |
| 10 | +private import semmle.python.Concepts |
| 11 | +private import semmle.python.ApiGraphs |
| 12 | + |
| 13 | +/** |
| 14 | + * Provides models for the `httpx` PyPI package. |
| 15 | + * |
| 16 | + * See |
| 17 | + * - https://pypi.org/project/httpx/ |
| 18 | + * - https://www.python-httpx.org/ |
| 19 | + */ |
| 20 | +private module HttpxModel { |
| 21 | + private class RequestCall extends HTTP::Client::Request::Range, DataFlow::CallCfgNode { |
| 22 | + string methodName; |
| 23 | + |
| 24 | + RequestCall() { |
| 25 | + methodName in [HTTP::httpVerbLower(), "request", "stream"] and |
| 26 | + this = API::moduleImport("httpx").getMember(methodName).getACall() |
| 27 | + } |
| 28 | + |
| 29 | + override DataFlow::Node getAUrlPart() { |
| 30 | + result = this.getArgByName("url") |
| 31 | + or |
| 32 | + if methodName in ["request", "stream"] |
| 33 | + then result = this.getArg(1) |
| 34 | + else result = this.getArg(0) |
| 35 | + } |
| 36 | + |
| 37 | + override string getFramework() { result = "httpx" } |
| 38 | + |
| 39 | + override predicate disablesCertificateValidation( |
| 40 | + DataFlow::Node disablingNode, DataFlow::Node argumentOrigin |
| 41 | + ) { |
| 42 | + // TODO: Look into disabling certificate validation |
| 43 | + none() |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * Provides models for the `httpx.[Async]Client` class |
| 49 | + * |
| 50 | + * See https://www.python-httpx.org/async/ |
| 51 | + */ |
| 52 | + module Client { |
| 53 | + /** Get a reference to the `httpx.Client` or `httpx.AsyncClient` class. */ |
| 54 | + private API::Node classRef() { |
| 55 | + result = API::moduleImport("httpx").getMember(["Client", "AsyncClient"]) |
| 56 | + } |
| 57 | + |
| 58 | + /** Get a reference to an `httpx.Client` or `httpx.AsyncClient` instance. */ |
| 59 | + private API::Node instance() { result = classRef().getReturn() } |
| 60 | + |
| 61 | + /** A method call on a Client that sends off a request */ |
| 62 | + private class OutgoingRequestCall extends HTTP::Client::Request::Range, DataFlow::CallCfgNode { |
| 63 | + string methodName; |
| 64 | + |
| 65 | + OutgoingRequestCall() { |
| 66 | + methodName in [HTTP::httpVerbLower(), "request", "stream"] and |
| 67 | + this = instance().getMember(methodName).getACall() |
| 68 | + } |
| 69 | + |
| 70 | + override DataFlow::Node getAUrlPart() { |
| 71 | + result = this.getArgByName("url") |
| 72 | + or |
| 73 | + if methodName in ["request", "stream"] |
| 74 | + then result = this.getArg(1) |
| 75 | + else result = this.getArg(0) |
| 76 | + } |
| 77 | + |
| 78 | + override string getFramework() { result = "httpx.[Async]Client" } |
| 79 | + |
| 80 | + override predicate disablesCertificateValidation( |
| 81 | + DataFlow::Node disablingNode, DataFlow::Node argumentOrigin |
| 82 | + ) { |
| 83 | + // TODO: Look into disabling certificate validation |
| 84 | + none() |
| 85 | + } |
| 86 | + } |
| 87 | + } |
| 88 | +} |
0 commit comments