Skip to content

Commit db791bc

Browse files
Merge pull request #197 from microsoft/sfi-issue-fix
fix: SFI issue fix
2 parents 6d322c6 + f18e98e commit db791bc

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/frontend/frontend_server.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
BUILD_DIR = os.path.join(os.path.dirname(__file__), "dist")
2424
INDEX_HTML = os.path.join(BUILD_DIR, "index.html")
2525

26+
2627
# Serve static files from build directory
2728
app.mount(
2829
"/assets", StaticFiles(directory=os.path.join(BUILD_DIR, "assets")), name="assets"
@@ -57,11 +58,13 @@ async def get_config():
5758

5859
@app.get("/{full_path:path}")
5960
async def serve_app(full_path: str):
60-
# First check if file exists in build directory
61-
file_path = os.path.join(BUILD_DIR, full_path)
62-
if os.path.exists(file_path):
61+
# Remediation: normalize and check containment before serving
62+
file_path = os.path.normpath(os.path.join(BUILD_DIR, full_path))
63+
# Block traversal and dotfiles
64+
if not file_path.startswith(BUILD_DIR) or ".." in full_path or "/." in full_path or "\\." in full_path:
65+
return FileResponse(INDEX_HTML)
66+
if os.path.isfile(file_path):
6367
return FileResponse(file_path)
64-
# Otherwise serve index.html for client-side routing
6568
return FileResponse(INDEX_HTML)
6669

6770

0 commit comments

Comments
 (0)