Skip to content

Commit

Permalink
Fix Uncontrolled data used in path expression
Browse files Browse the repository at this point in the history
  • Loading branch information
cavenel committed Dec 4, 2023
1 parent 30cb4ff commit 36cf0e4
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion tissuumaps/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,11 @@ def tmapFile(filename):
@app.route("/<path:completePath>.csv")
@requires_auth
def csvFile(completePath):
completePath = os.path.join(app.basedir, completePath + ".csv")
completePath = os.path.normpath(os.path.join(app.basedir, completePath + ".csv"))
if not completePath.startswith(app.basedir):
# Directory traversal
abort(404)
return
directory = os.path.dirname(completePath)
filename = os.path.basename(completePath)
if os.path.isfile(completePath):
Expand Down Expand Up @@ -708,6 +712,15 @@ def dzi_asso(path):

@app.route("/<path:path>_files/<int:level>/<int:col>_<int:row>.<format>")
def tile(path, level, col, row, format):
# check that level, col and row are integers
if not isinstance(level, int) or not isinstance(col, int) or not isinstance(
row, int
):
abort(404)
return
if not format in ["jpeg", "png"]:
abort(404)
return
completePath = os.path.normpath(os.path.join(app.basedir, path))
if not completePath.startswith(app.basedir):
# Directory traversal
Expand Down Expand Up @@ -1052,6 +1065,8 @@ def runPlugin(pluginName):
for directory in [app.config["PLUGIN_FOLDER_USER"], app.config["PLUGIN_FOLDER"]]:
filename = pluginName + ".js"
completePath = os.path.normpath(os.path.join(directory, pluginName + ".js"))
if not completePath.startswith(directory):
continue
directory = os.path.dirname(completePath)
filename = os.path.basename(completePath)
if os.path.isfile(completePath):
Expand All @@ -1064,6 +1079,9 @@ def runPlugin(pluginName):

@app.route("/plugins/<path:pluginName>/<path:method>", methods=["GET", "POST"])
def pluginJS(pluginName, method):
pluginName = secure_filename(pluginName)
method = secure_filename(method)

pluginModule = load_plugin(pluginName)
pluginInstance = pluginModule.Plugin(app)
pluginMethod = getattr(pluginInstance, method)
Expand Down

0 comments on commit 36cf0e4

Please sign in to comment.