fix(response): harden download_backup
Made use of util `check_path_safety` to ensure sandboxing.
This commit is contained in:
parent
7c9ce26469
commit
0c660477ee
1 changed files with 8 additions and 0 deletions
|
|
@ -26,6 +26,7 @@ import frappe.sessions
|
|||
import frappe.utils
|
||||
from frappe import _
|
||||
from frappe.core.doctype.access_log.access_log import make_access_log
|
||||
from frappe.core.doctype.file.utils import check_path_safety
|
||||
from frappe.utils import format_timedelta, orjson_dumps
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
|
@ -280,6 +281,13 @@ def download_backup(path):
|
|||
_("You need to be logged in and have System Manager Role to be able to access backups.")
|
||||
)
|
||||
|
||||
filename = path.split("/backups/", 1)[1]
|
||||
backup_path = frappe.get_site_path("private", "backups")
|
||||
requested_path = frappe.get_site_path("private", "backups", filename)
|
||||
is_safe = check_path_safety(base_path=backup_path, requested_path=requested_path)
|
||||
if not is_safe:
|
||||
frappe.throw(_("Invalid backup path"), frappe.PermissionError)
|
||||
|
||||
return send_private_file(path)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue