fix(static_page): ensure that requested files are within app/www
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
This commit is contained in:
parent
395af8aa04
commit
a5ed4cf3e7
1 changed files with 10 additions and 3 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import mimetypes
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from werkzeug.wrappers import Response
|
||||
from werkzeug.wsgi import wrap_file
|
||||
|
|
@ -34,9 +35,15 @@ class StaticPage(BaseRenderer):
|
|||
if not self.is_valid_file_path():
|
||||
return
|
||||
for app in frappe.get_installed_apps():
|
||||
file_path = frappe.get_app_path(app, "www") + "/" + self.path
|
||||
if os.path.isfile(file_path) and is_binary_file(file_path):
|
||||
self.file_path = file_path
|
||||
app_path = Path(frappe.get_app_path(app, "www"))
|
||||
requested_path = (app_path / self.path).resolve()
|
||||
if (
|
||||
requested_path.is_relative_to(app_path)
|
||||
and requested_path.is_file()
|
||||
and is_binary_file(requested_path)
|
||||
):
|
||||
self.file_path = requested_path
|
||||
break
|
||||
|
||||
def can_render(self):
|
||||
return self.is_valid_file_path() and self.file_path
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue