Skip to content

Commit 1fe565a

Browse files
committed
cherrypy framework file system access Sinks are added
1 parent ad26312 commit 1fe565a

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Provides classes modeling security-relevant aspects of the `cherrypy` PyPI package.
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 `cherrypy` PyPI package.
14+
* See https://cherrypy.dev/.
15+
*/
16+
private module Cherrypy {
17+
/**
18+
* Holds for an instance of `cherrypy.lib.static`
19+
*/
20+
API::Node libStatic() {
21+
result = API::moduleImport("cherrypy").getMember("lib").getMember("static")
22+
}
23+
24+
/**
25+
* A call to the `serve_file` or `serve_download`or `staticfile` functions of `cherrypy.lib.static` as a sink for Filesystem access.
26+
*/
27+
class FileResponseCall extends FileSystemAccess::Range, API::CallNode {
28+
string funcName;
29+
30+
FileResponseCall() {
31+
this = libStatic().getMember("staticfile").getACall() and
32+
funcName = "staticfile"
33+
or
34+
this = libStatic().getMember("serve_file").getACall() and
35+
funcName = "serve_file"
36+
or
37+
this = libStatic().getMember("serve_download").getACall() and
38+
funcName = "serve_download"
39+
}
40+
41+
override DataFlow::Node getAPathArgument() {
42+
result = this.getParameter(0, "path").asSink() and funcName = ["serve_download", "serve_file"]
43+
or
44+
result = this.getParameter(0, "filename").asSink() and
45+
funcName = "staticfile"
46+
}
47+
}
48+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import cherrypy
2+
from cherrypy.lib.static import serve_file, serve_download, staticfile
3+
4+
serve_file("file") # $ getAPathArgument="file"
5+
serve_download("file") # $ getAPathArgument="file"
6+
staticfile("file") # $ getAPathArgument="file"
7+
# root won't make this safe
8+
staticfile("file", root="/path/to/safe/dir") # $ getAPathArgument="file"

0 commit comments

Comments
 (0)