|
| 1 | +/** |
| 2 | + * Provides classes modeling security-relevant aspects of the I/O write or read operations |
| 3 | + */ |
| 4 | + |
| 5 | +private import python |
| 6 | +private import semmle.python.dataflow.new.DataFlow |
| 7 | +private import semmle.python.dataflow.new.RemoteFlowSources |
| 8 | +private import semmle.python.dataflow.new.TaintTracking |
| 9 | +private import semmle.python.Concepts |
| 10 | +private import semmle.python.ApiGraphs |
| 11 | + |
| 12 | +/** |
| 13 | + * Provides models for the `aiofile` PyPI package. |
| 14 | + * See https://github.com/agronholm/anyio. |
| 15 | + */ |
| 16 | +private module Aiofile { |
| 17 | + /** |
| 18 | + * A call to the `async_open` function or `AIOFile` constructor from `aiofile` as a sink for Filesystem access. |
| 19 | + */ |
| 20 | + class FileResponseCall extends FileSystemAccess::Range, API::CallNode { |
| 21 | + string methodName; |
| 22 | + |
| 23 | + FileResponseCall() { |
| 24 | + this = API::moduleImport("aiofile").getMember("async_open").getACall() and |
| 25 | + methodName = "async_open" |
| 26 | + or |
| 27 | + this = API::moduleImport("aiofile").getMember("AIOFile").getACall() and |
| 28 | + methodName = "AIOFile" |
| 29 | + } |
| 30 | + |
| 31 | + override DataFlow::Node getAPathArgument() { |
| 32 | + result = this.getParameter(0, "file_specifier").asSink() and |
| 33 | + methodName = "async_open" |
| 34 | + or |
| 35 | + result = this.getParameter(0, "filename").asSink() and |
| 36 | + methodName = "AIOFile" |
| 37 | + } |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +/** |
| 42 | + * Provides models for the `aiofiles` PyPI package. |
| 43 | + * See https://github.com/Tinche/aiofiles. |
| 44 | + */ |
| 45 | +private module Aiofiles { |
| 46 | + /** |
| 47 | + * A call to the `open` function from `aiofiles` as a sink for Filesystem access. |
| 48 | + */ |
| 49 | + class FileResponseCall extends FileSystemAccess::Range, API::CallNode { |
| 50 | + FileResponseCall() { this = API::moduleImport("aiofiles").getMember("open").getACall() } |
| 51 | + |
| 52 | + override DataFlow::Node getAPathArgument() { result = this.getParameter(0, "file").asSink() } |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +/** |
| 57 | + * Provides models for the `anyio` PyPI package. |
| 58 | + * See https://github.com/agronholm/anyio. |
| 59 | + */ |
| 60 | +private module Anyio { |
| 61 | + /** |
| 62 | + * A call to the `from_path` function from `FileReadStream` or `FileWriteStream` constructors of `anyio.streams.file` as a sink for Filesystem access. |
| 63 | + */ |
| 64 | + class FileStreamCall extends FileSystemAccess::Range, API::CallNode { |
| 65 | + FileStreamCall() { |
| 66 | + this = |
| 67 | + API::moduleImport("anyio") |
| 68 | + .getMember("streams") |
| 69 | + .getMember("file") |
| 70 | + .getMember(["FileReadStream", "FileWriteStream"]) |
| 71 | + .getMember("from_path") |
| 72 | + .getACall() |
| 73 | + } |
| 74 | + |
| 75 | + override DataFlow::Node getAPathArgument() { result = this.getParameter(0, "path").asSink() } |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * A call to the `Path` constructor from `anyio` as a sink for Filesystem access. |
| 80 | + */ |
| 81 | + class PathCall extends FileSystemAccess::Range, API::CallNode { |
| 82 | + PathCall() { this = API::moduleImport("anyio").getMember("Path").getACall() } |
| 83 | + |
| 84 | + override DataFlow::Node getAPathArgument() { result = this.getParameter(0).asSink() } |
| 85 | + } |
| 86 | + |
| 87 | + /** |
| 88 | + * A call to the `open_file` function from `anyio` as a sink for Filesystem access. |
| 89 | + */ |
| 90 | + class OpenFileCall extends FileSystemAccess::Range, API::CallNode { |
| 91 | + OpenFileCall() { this = API::moduleImport("anyio").getMember("open_file").getACall() } |
| 92 | + |
| 93 | + override DataFlow::Node getAPathArgument() { result = this.getParameter(0, "file").asSink() } |
| 94 | + } |
| 95 | +} |
0 commit comments