mirror of
https://github.com/github/codeql.git
synced 2026-04-30 19:26:02 +02:00
Python : Add Flask sinks for path injection query
This commit is contained in:
committed by
Porcupiney Hairs
parent
0d161bec7a
commit
4fd3f212f8
@@ -519,4 +519,34 @@ module Flask {
|
||||
|
||||
override DataFlow::Node getValueArg() { none() }
|
||||
}
|
||||
|
||||
/**
|
||||
* A `send_from_directory` call considered a sink for file system access vulnerabilities.
|
||||
*
|
||||
* See https://flask.palletsprojects.com/en/1.1.x/api/#flask.send_from_directory
|
||||
*/
|
||||
class FlaskSendFromDirectory extends FileSystemAccess::Range, DataFlow::CallCfgNode {
|
||||
FlaskSendFromDirectory() {
|
||||
this = API::moduleImport("flask").getMember("send_from_directory").getACall()
|
||||
}
|
||||
|
||||
override DataFlow::Node getAPathArgument() {
|
||||
result in [this.getArg(_), this.getArgByName(["directory", "filename"])]
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A `send_file` call considered a sink for file system access vulnerabilities.
|
||||
*
|
||||
* See https://flask.palletsprojects.com/en/1.1.x/api/#flask.send_file
|
||||
*/
|
||||
class FlaskSendFile extends FileSystemAccess::Range, DataFlow::CallCfgNode {
|
||||
FlaskSendFile() {
|
||||
this = API::moduleImport("flask").getMember("send_file").getACall()
|
||||
}
|
||||
|
||||
override DataFlow::Node getAPathArgument() {
|
||||
result in [this.getArg(0), this.getArgByName("filename_or_fp")]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,17 @@
|
||||
from flask import Flask, request
|
||||
from flask import Flask, request, send_from_directory, send_file
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route("/save-uploaded-file") # $routeSetup="/save-uploaded-file"
|
||||
def test_taint(): # $requestHandler
|
||||
request.files['key'].save("path") # $ getAPathArgument="path"
|
||||
|
||||
|
||||
@app.route("/path-injection") # $routeSetup="/path-injection"
|
||||
def test_path(): # $requestHandler
|
||||
|
||||
flask.send_from_directory("filepath","file") # $ getAPathArgument="filepath" getAPathArgument="file"
|
||||
flask.send_file("file") # $ getAPathArgument="file"
|
||||
|
||||
flask.send_from_directory(directory="filepath","file") # $ getAPathArgument="filepath" getAPathArgument="file"
|
||||
flask.send_from_directory(filename="filepath","file") # $ getAPathArgument="filepath" getAPathArgument="file"
|
||||
flask.send_file(filename_or_fp="file") # $ getAPathArgument="file"
|
||||
Reference in New Issue
Block a user