🐛 URL encode all uploaded file names
Otherwise a # in the URL might be treated as a fragment and lead to resource mismatches. Closes #4267
This commit is contained in:
1 parent
87d04544dc
commit
e71546d382
2 files changed
+27
-16
No files matched your search
@@ -37,6 +37,11 @@ from octoprint.server.util.flask import (
|
||||
from octoprint.settings import settings, valid_boolean_trues
|
||||
from octoprint.util import sv, time_this
|
||||
|
||||
try:
|
||||
from urllib.parse import quote as urlquote
|
||||
except ImportError:
|
||||
from urllib import quote as urlquote # noqa: F401
|
||||
|
||||
# ~~ GCODE file handling
|
||||
|
||||
_file_cache = {}
|
||||
@@ -325,7 +330,7 @@ def _getFileList(
|
||||
"resource": url_for(
|
||||
".readGcodeFile",
|
||||
target=FileDestinations.SDCARD,
|
||||
filename=f["name"],
|
||||
filename=urlquote(f["name"]),
|
||||
_external=True,
|
||||
)
|
||||
},
|
||||
@@ -387,7 +392,7 @@ def _getFileList(
|
||||
"resource": url_for(
|
||||
".readGcodeFile",
|
||||
target=FileDestinations.LOCAL,
|
||||
filename=path + file_or_folder["name"],
|
||||
filename=urlquote(path + file_or_folder["name"]),
|
||||
_external=True,
|
||||
)
|
||||
}
|
||||
@@ -441,14 +446,14 @@ def _getFileList(
|
||||
"resource": url_for(
|
||||
".readGcodeFile",
|
||||
target=FileDestinations.LOCAL,
|
||||
filename=file_or_folder["path"],
|
||||
filename=urlquote(file_or_folder["path"]),
|
||||
_external=True,
|
||||
),
|
||||
"download": url_for("index", _external=True)
|
||||
+ "downloads/files/"
|
||||
+ FileDestinations.LOCAL
|
||||
+ "/"
|
||||
+ file_or_folder["path"],
|
||||
+ urlquote(file_or_folder["path"]),
|
||||
}
|
||||
|
||||
result.append(file_or_folder)
|
||||
@@ -687,7 +692,7 @@ def uploadGcodeFile(target):
|
||||
location = url_for(
|
||||
".readGcodeFile",
|
||||
target=FileDestinations.LOCAL,
|
||||
filename=filename,
|
||||
filename=urlquote(filename),
|
||||
_external=True,
|
||||
)
|
||||
files.update(
|
||||
@@ -702,7 +707,7 @@ def uploadGcodeFile(target):
|
||||
+ "downloads/files/"
|
||||
+ FileDestinations.LOCAL
|
||||
+ "/"
|
||||
+ filename,
|
||||
+ urlquote(filename),
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -712,7 +717,7 @@ def uploadGcodeFile(target):
|
||||
location = url_for(
|
||||
".readGcodeFile",
|
||||
target=FileDestinations.SDCARD,
|
||||
filename=sdFilename,
|
||||
filename=urlquote(sdFilename),
|
||||
_external=True,
|
||||
)
|
||||
files.update(
|
||||
@@ -764,7 +769,7 @@ def uploadGcodeFile(target):
|
||||
location = url_for(
|
||||
".readGcodeFile",
|
||||
target=FileDestinations.LOCAL,
|
||||
filename=added_folder,
|
||||
filename=urlquote(added_folder),
|
||||
_external=True,
|
||||
)
|
||||
folder = {
|
||||
@@ -1034,7 +1039,10 @@ def gcodeFileCommand(filename, target):
|
||||
abort(404, description="Unknown profile")
|
||||
|
||||
location = url_for(
|
||||
".readGcodeFile", target=target, filename=full_path, _external=True
|
||||
".readGcodeFile",
|
||||
target=target,
|
||||
filename=urlquote(full_path),
|
||||
_external=True,
|
||||
)
|
||||
result = {
|
||||
"name": destination,
|
||||
@@ -1047,7 +1055,7 @@ def gcodeFileCommand(filename, target):
|
||||
+ "downloads/files/"
|
||||
+ target
|
||||
+ "/"
|
||||
+ full_path,
|
||||
+ urlquote(full_path),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1154,7 +1162,10 @@ def gcodeFileCommand(filename, target):
|
||||
fileManager.move_folder(target, filename, destination)
|
||||
|
||||
location = url_for(
|
||||
".readGcodeFile", target=target, filename=destination, _external=True
|
||||
".readGcodeFile",
|
||||
target=target,
|
||||
filename=urlquote(destination),
|
||||
_external=True,
|
||||
)
|
||||
result = {
|
||||
"name": name,
|
||||
@@ -1168,7 +1179,7 @@ def gcodeFileCommand(filename, target):
|
||||
+ "downloads/files/"
|
||||
+ target
|
||||
+ "/"
|
||||
+ destination
|
||||
+ urlquote(destination)
|
||||
)
|
||||
|
||||
r = make_response(jsonify(result), 201)
|
||||
|
||||
@@ -14,19 +14,19 @@
|
||||
};
|
||||
|
||||
var resourceForLocation = function (location) {
|
||||
return url + "/" + location;
|
||||
return url + "/" + encodeURIComponent(location);
|
||||
};
|
||||
|
||||
var downloadForLocation = function (location) {
|
||||
return downloadUrl + "/" + location;
|
||||
return downloadUrl + "/" + encodeURIComponent(location);
|
||||
};
|
||||
|
||||
var downloadForEntry = function (location, filename) {
|
||||
return downloadForLocation(location) + "/" + filename;
|
||||
return downloadForLocation(location) + "/" + encodeURIComponent(filename);
|
||||
};
|
||||
|
||||
var resourceForEntry = function (location, filename) {
|
||||
return resourceForLocation(location) + "/" + filename;
|
||||
return resourceForLocation(location) + "/" + encodeURIComponent(filename);
|
||||
};
|
||||
|
||||
var preProcessList = function (response) {
|
||||
|
||||
Reference in new issue
Block a user