Skip to content

Commit 2226b84

Browse files
committed
Prevent arbitrary file read via path traversal
1 parent 0160172 commit 2226b84

File tree

5 files changed

+9
-12
lines changed

5 files changed

+9
-12
lines changed

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "teleop"
7-
version = "0.1.3"
7+
version = "0.1.4"
88
description = "Turns your phone into a robot arm teleoperation device by leveraging the WebXR API"
99
readme = { file = "README.md", content-type = "text/markdown" }
1010
license = { file = "LICENSE" }
@@ -31,4 +31,4 @@ utils = ["pin"]
3131
include = ["teleop*"]
3232

3333
[tool.setuptools.package-data]
34-
teleop = ["cert.pem", "key.pem", "index.html", "teleop-ui.js", "utils/lite6.urdf"]
34+
teleop = ["cert.pem", "key.pem", "index.html", "assets/*", "utils/lite6.urdf"]

teleop/__init__.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import uvicorn
77
from fastapi import FastAPI, WebSocket, WebSocketDisconnect
88
from fastapi.responses import FileResponse
9+
from fastapi.staticfiles import StaticFiles
910
import transforms3d as t3d
1011
import numpy as np
1112
import json
@@ -278,19 +279,15 @@ def __update(self, message):
278279
self.__notify_subscribers(self.__pose, message)
279280

280281
def __setup_routes(self):
282+
# Mount static files directory
283+
assets_dir = os.path.join(THIS_DIR, "assets")
284+
self.__app.mount("/assets", StaticFiles(directory=assets_dir), name="assets")
285+
281286
@self.__app.get("/")
282287
async def index():
283288
self.__logger.debug("Serving the index.html file")
284289
return FileResponse(os.path.join(THIS_DIR, "index.html"))
285290

286-
@self.__app.get("/{filename:path}")
287-
async def serve_file(filename: str):
288-
self.__logger.debug(f"Serving the {filename} file")
289-
file_path = os.path.join(THIS_DIR, filename)
290-
if os.path.exists(file_path):
291-
return FileResponse(file_path)
292-
return {"error": "File not found"}
293-
294291
@self.__app.websocket("/ws")
295292
async def websocket_endpoint(websocket: WebSocket):
296293
await self.__manager.connect(websocket)

teleop/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<meta charset="UTF-8">
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
77
<title>Teleop</title>
8-
<script src="teleop-ui.js"></script>
8+
<script src="/assets/teleop-ui.js"></script>
99

1010
<style>
1111
* {

teleop/test-teleop-ui.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<meta charset="UTF-8">
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
77
<title>Teleop</title>
8-
<script src="teleop-ui.js"></script>
8+
<script src="/assets/teleop-ui.js"></script>
99
<style>
1010
* {
1111
margin: 0;

0 commit comments

Comments
 (0)