Skip to content

Commit ba906c1

Browse files
Avoid malicious user path input (#1855)
Co-authored-by: jan iversen <[email protected]>
1 parent 927fa4d commit ba906c1

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

pymodbus/server/simulator/http_server.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,9 @@ async def handle_html_static(self, request):
259259
"""Handle static html."""
260260
if not (page := request.path[1:]):
261261
page = "index.html"
262-
file = os.path.join(self.web_path, page)
262+
file = os.path.normpath(os.path.join(self.web_path, page))
263+
if not file.startswith(self.web_path):
264+
raise ValueError(f"File access outside {self.web_path} not permitted.")
263265
try:
264266
with open(file, encoding="utf-8"):
265267
return web.FileResponse(file)

0 commit comments

Comments
 (0)