Skip to content

Commit

Permalink
Merge pull request from GHSA-8p25-3q46-8q2p
Browse files Browse the repository at this point in the history
  • Loading branch information
jesserockz authored Feb 22, 2024
1 parent 58c0d8c commit a748610
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions esphome/dashboard/web_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,8 +808,16 @@ class EditRequestHandler(BaseHandler):
@bind_config
async def get(self, configuration: str | None = None) -> None:
"""Get the content of a file."""
loop = asyncio.get_running_loop()
if not configuration.endswith((".yaml", ".yml")):
self.send_error(404)
return

filename = settings.rel_path(configuration)
if Path(filename).resolve().parent != settings.absolute_config_dir:
self.send_error(404)
return

loop = asyncio.get_running_loop()
content = await loop.run_in_executor(
None, self._read_file, filename, configuration
)
Expand All @@ -835,14 +843,20 @@ def _write_file(self, filename: str, content: bytes) -> None:
@bind_config
async def post(self, configuration: str | None = None) -> None:
"""Write the content of a file."""
if not configuration.endswith((".yaml", ".yml")):
self.send_error(404)
return

filename = settings.rel_path(configuration)
if Path(filename).resolve().parent != settings.absolute_config_dir:
self.send_error(404)
return

loop = asyncio.get_running_loop()
config_file = settings.rel_path(configuration)
await loop.run_in_executor(
None, self._write_file, config_file, self.request.body
)
await loop.run_in_executor(None, self._write_file, filename, self.request.body)
# Ensure the StorageJSON is updated as well
await async_run_system_command(
[*DASHBOARD_COMMAND, "compile", "--only-generate", config_file]
[*DASHBOARD_COMMAND, "compile", "--only-generate", filename]
)
self.set_status(200)

Expand Down

0 comments on commit a748610

Please sign in to comment.