mirror of
https://github.com/esphome/esphome.git
synced 2026-10-05 18:41:32 +00:00
Reject empty file names and fix FlashImage.path endswith call
- Return 400 for empty or whitespace-only file_name to prevent the idedata fallback from matching everything via empty-string suffix. - Use image.path.as_posix().endswith() since FlashImage.path is a Path object which does not have a string endswith method. - Add parametrized test for empty/whitespace file name values.
This commit is contained in:
@@ -1054,7 +1054,7 @@ class DownloadBinaryRequestHandler(BaseHandler):
|
||||
# fallback to type=, but prioritize file=
|
||||
file_name = self.get_argument("type", None)
|
||||
file_name = self.get_argument("file", file_name)
|
||||
if file_name is None:
|
||||
if file_name is None or not file_name.strip():
|
||||
self.send_error(400)
|
||||
return
|
||||
# get requested download name, or build it based on filename
|
||||
@@ -1087,7 +1087,7 @@ class DownloadBinaryRequestHandler(BaseHandler):
|
||||
|
||||
found = False
|
||||
for image in idedata.extra_flash_images:
|
||||
if image.path.endswith(file_name):
|
||||
if image.path.as_posix().endswith(file_name):
|
||||
path = image.path
|
||||
download_name = file_name
|
||||
found = True
|
||||
|
||||
Reference in New Issue
Block a user