Skip to content

Commit

Permalink
Avoid malicious user path input (#1855)
Browse files Browse the repository at this point in the history
Co-authored-by: jan iversen <[email protected]>
  • Loading branch information
alexrudd2 and janiversen authored Oct 26, 2023
1 parent 927fa4d commit ba906c1
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pymodbus/server/simulator/http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,9 @@ async def handle_html_static(self, request):
"""Handle static html."""
if not (page := request.path[1:]):
page = "index.html"
file = os.path.join(self.web_path, page)
file = os.path.normpath(os.path.join(self.web_path, page))
if not file.startswith(self.web_path):
raise ValueError(f"File access outside {self.web_path} not permitted.")
try:
with open(file, encoding="utf-8"):
return web.FileResponse(file)
Expand Down

0 comments on commit ba906c1

Please sign in to comment.