|
| 1 | +import go |
| 2 | + |
| 3 | +class FastHttpFileSystemAccess extends FileSystemAccess::Range, DataFlow::CallNode { |
| 4 | + FastHttpFileSystemAccess() { |
| 5 | + exists(DataFlow::Method mcn | |
| 6 | + ( |
| 7 | + mcn.hasQualifiedName("github.com/valyala/fasthttp.RequestCtx", ["SendFileBytes", "SendFile"]) or |
| 8 | + mcn.hasQualifiedName("github.com/valyala/fasthttp.Response", ["SendFile"]) |
| 9 | + ) and |
| 10 | + this = mcn.getACall() |
| 11 | + ) |
| 12 | + or |
| 13 | + exists(DataFlow::Function f | |
| 14 | + f.hasQualifiedName("github.com/valyala/fasthttp", |
| 15 | + [ |
| 16 | + "ServeFile", "ServeFileUncompressed", "ServeFileBytes", "ServeFileBytesUncompressed", |
| 17 | + "SaveMultipartFile" |
| 18 | + ]) and |
| 19 | + this = f.getACall() |
| 20 | + ) |
| 21 | + } |
| 22 | + |
| 23 | + override DataFlow::Node getAPathArgument() { |
| 24 | + this.getTarget().getName() = |
| 25 | + [ |
| 26 | + "ServeFile", "ServeFileUncompressed", "ServeFileBytes", "ServeFileBytesUncompressed", |
| 27 | + "SaveMultipartFile" |
| 28 | + ] and |
| 29 | + result = this.getArgument(1) |
| 30 | + or |
| 31 | + this.getTarget().getName() = ["SendFile", "SendFileBytes"] and |
| 32 | + result = this.getArgument(0) |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +class HttpServeFile extends FileSystemAccess::Range, DataFlow::CallNode { |
| 37 | + HttpServeFile() { |
| 38 | + exists(DataFlow::Function mcn | |
| 39 | + mcn.hasQualifiedName("net/http", "ServeFile") and |
| 40 | + this = mcn.getACall() |
| 41 | + ) |
| 42 | + } |
| 43 | + |
| 44 | + override DataFlow::Node getAPathArgument() { result = this.getArgument(2) } |
| 45 | +} |
| 46 | + |
| 47 | +class BeegoFileSystemAccess extends FileSystemAccess::Range, DataFlow::CallNode { |
| 48 | + BeegoFileSystemAccess() { |
| 49 | + exists(DataFlow::Method mcn | |
| 50 | + ( |
| 51 | + mcn.hasQualifiedName("github.com/beego/beego/v2/server/web/context.BeegoOutput", "Download") or |
| 52 | + mcn.hasQualifiedName("github.com/beego/beego/v2/server/web.Controller", |
| 53 | + "SaveToFileWithBuffer") |
| 54 | + ) and |
| 55 | + this = mcn.getACall() |
| 56 | + ) |
| 57 | + } |
| 58 | + |
| 59 | + override DataFlow::Node getAPathArgument() { |
| 60 | + this.getTarget() |
| 61 | + .hasQualifiedName("github.com/beego/beego/v2/server/web/context.BeegoOutput", "Download") and |
| 62 | + result = this.getArgument(0) |
| 63 | + or |
| 64 | + this.getTarget() |
| 65 | + .hasQualifiedName("github.com/beego/beego/v2/server/web.Controller", "SaveToFileWithBuffer") and |
| 66 | + result = this.getArgument(1) |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +class EchoFileSystemAccess extends FileSystemAccess::Range, DataFlow::CallNode { |
| 71 | + EchoFileSystemAccess() { |
| 72 | + exists(DataFlow::Method mcn | |
| 73 | + mcn.hasQualifiedName("github.com/labstack/echo/v4.Context", ["Attachment", "File"]) and |
| 74 | + this = mcn.getACall() |
| 75 | + ) |
| 76 | + } |
| 77 | + |
| 78 | + override DataFlow::Node getAPathArgument() { result = this.getArgument(0) } |
| 79 | +} |
| 80 | + |
| 81 | +class GinFileSystemAccess extends FileSystemAccess::Range, DataFlow::CallNode { |
| 82 | + GinFileSystemAccess() { |
| 83 | + exists(DataFlow::Method mcn | |
| 84 | + mcn.hasQualifiedName("github.com/gin-gonic/gin.Context", |
| 85 | + ["File", "FileAttachment", "SaveUploadedFile"]) and |
| 86 | + this = mcn.getACall() |
| 87 | + ) |
| 88 | + } |
| 89 | + |
| 90 | + override DataFlow::Node getAPathArgument() { |
| 91 | + this.getTarget().getName() = ["File", "FileAttachment"] and result = this.getArgument(0) |
| 92 | + or |
| 93 | + this.getTarget().getName() = "SaveUploadedFile" and result = this.getArgument(1) |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +class IrisFileSystemAccess extends FileSystemAccess::Range, DataFlow::CallNode { |
| 98 | + IrisFileSystemAccess() { |
| 99 | + exists(DataFlow::Method mcn | |
| 100 | + mcn.hasQualifiedName("github.com/kataras/iris/v12/context.Context", |
| 101 | + ["SendFile", "ServeFile", "SendFileWithRate", "ServeFileWithRate", "UploadFormFiles"]) and |
| 102 | + this = mcn.getACall() |
| 103 | + or |
| 104 | + mcn.hasQualifiedName("github.com/kataras/iris/v12/context.Context", "SaveFormFile") and |
| 105 | + this = mcn.getACall() |
| 106 | + ) |
| 107 | + } |
| 108 | + |
| 109 | + override DataFlow::Node getAPathArgument() { |
| 110 | + this.getTarget().getName() = |
| 111 | + ["SendFile", "ServeFile", "SendFileWithRate", "ServeFileWithRate", "UploadFormFiles"] and |
| 112 | + result = this.getArgument(0) |
| 113 | + or |
| 114 | + this.getTarget().getName() = "SaveFormFile" and result = this.getArgument(1) |
| 115 | + } |
| 116 | +} |
| 117 | + |
| 118 | +class FiberSystemAccess extends FileSystemAccess::Range, DataFlow::CallNode { |
| 119 | + FiberSystemAccess() { |
| 120 | + exists(DataFlow::Method mcn | |
| 121 | + mcn.hasQualifiedName("github.com/gofiber/fiber/v2.Ctx", ["Attachment", "SendFile"]) and |
| 122 | + this = mcn.getACall() |
| 123 | + or |
| 124 | + mcn.hasQualifiedName("github.com/gofiber/fiber/v2.Ctx", "SaveFile") and |
| 125 | + this = mcn.getACall() |
| 126 | + ) |
| 127 | + } |
| 128 | + |
| 129 | + override DataFlow::Node getAPathArgument() { |
| 130 | + this.getTarget().getName() = ["Attachment", "SendFile"] and result = this.getArgument(0) |
| 131 | + or |
| 132 | + this.getTarget().getName() = "SaveFile" and result = this.getArgument(1) |
| 133 | + } |
| 134 | +} |
| 135 | + |
| 136 | +class AferoSystemAccess extends FileSystemAccess::Range, DataFlow::CallNode { |
| 137 | + AferoSystemAccess() { |
| 138 | + exists(DataFlow::Function mcn | |
| 139 | + mcn.hasQualifiedName("github.com/spf13/afero", |
| 140 | + ["WriteReader", "SafeWriteReader", "WriteFile", "ReadFile", "ReadDir"]) and |
| 141 | + this = mcn.getACall() |
| 142 | + or |
| 143 | + mcn.hasQualifiedName("github.com/spf13/afero", "Open") and |
| 144 | + this = mcn.getACall() |
| 145 | + ) |
| 146 | + or |
| 147 | + exists(DataFlow::Function mcn | |
| 148 | + mcn.hasQualifiedName("github.com/spf13/afero", |
| 149 | + ["WriteReader", "SafeWriteReader", "WriteFile", "ReadFile", "ReadDir"]) and |
| 150 | + this = mcn.getACall() |
| 151 | + or |
| 152 | + mcn.hasQualifiedName("github.com/spf13/afero", "Open") and |
| 153 | + this = mcn.getACall() |
| 154 | + ) |
| 155 | + or |
| 156 | + exists(DataFlow::Method mcn | |
| 157 | + mcn.hasQualifiedName("github.com/spf13/afero.Afero", |
| 158 | + ["ReadFile", "ReadDir", "WriteReader", "WriteFile", "SafeWriteReader"]) and |
| 159 | + this = mcn.getACall() |
| 160 | + or |
| 161 | + mcn.hasQualifiedName("github.com/spf13/afero.HttpFs", ["Open", "OpenFile", "Create"]) and |
| 162 | + this = mcn.getACall() |
| 163 | + or |
| 164 | + mcn.hasQualifiedName("github.com/spf13/afero.RegexpFs", |
| 165 | + ["Create", "Open", "Remove", "OpenFile"]) and |
| 166 | + this = mcn.getACall() |
| 167 | + or |
| 168 | + mcn.hasQualifiedName("github.com/spf13/afero.ReadOnlyFs", |
| 169 | + ["Create", "Open", "Remove", "OpenFile", "ReadDir", "ReadlinkIfPossible"]) and |
| 170 | + this = mcn.getACall() |
| 171 | + or |
| 172 | + mcn.hasQualifiedName("github.com/spf13/afero.OsFs", |
| 173 | + ["Create", "Open", "Remove", "RemoveAll", "OpenFile", "ReadDir", "ReadlinkIfPossible"]) and |
| 174 | + this = mcn.getACall() |
| 175 | + or |
| 176 | + mcn.hasQualifiedName("github.com/spf13/afero.OsFs", |
| 177 | + ["Create", "Open", "Remove", "RemoveAll", "OpenFile", "ReadDir", "ReadlinkIfPossible"]) and |
| 178 | + this = mcn.getACall() |
| 179 | + or |
| 180 | + mcn.hasQualifiedName("github.com/spf13/afero.MemMapFs", |
| 181 | + ["Create", "Open", "OpenFile", "Remove", "RemoveAll"]) and |
| 182 | + this = mcn.getACall() |
| 183 | + or |
| 184 | + mcn.hasQualifiedName("github.com/spf13/afero.BasePathFs", |
| 185 | + ["Create", "Open", "OpenFile", "Remove", "RemoveAll", "ReadlinkIfPossible"]) and |
| 186 | + this = mcn.getACall() |
| 187 | + ) |
| 188 | + } |
| 189 | + |
| 190 | + override DataFlow::Node getAPathArgument() { |
| 191 | + if |
| 192 | + this.getTarget() |
| 193 | + .hasQualifiedName("github.com/spf13/afero", |
| 194 | + ["WriteReader", "SafeWriteReader", "WriteFile", "ReadFile", "ReadDir"]) or |
| 195 | + this.getTarget() |
| 196 | + .hasQualifiedName("github.com/spf13/afero", |
| 197 | + ["WriteReader", "SafeWriteReader", "WriteFile", "ReadFile", "ReadDir"]) |
| 198 | + then result = this.getArgument(1) |
| 199 | + else result = this.getArgument(0) |
| 200 | + } |
| 201 | +} |
0 commit comments