Repository navigation
fix(security): forbid /file when no static roots are configured - #547
zoechen281 wants to merge 2 commits into
Conversation
An empty STATE.static_roots skipped the whitelist check entirely and let the endpoint return any file readable by the process. Return 403 when no roots are configured instead.
xhd0728
left a comment
There was a problem hiding this comment.
Thanks for the focused security fix. I reproduced the empty-root file access bypass on main and verified the fix on Python 3.12; all four endpoint regression tests pass locally.
CI is currently blocked during collection of the newly added test:
ModuleNotFoundError: No module named 'fastapi'
The failing step is uv run pytest tests/ultrarag -q in Sayhello Build and Run. CI uses the default uv sync, while FastAPI is currently only declared in the optional retriever extra. My local environment already had FastAPI installed, which is why the local run passed.
Please add FastAPI to the development dependency group in pyproject.toml, regenerate uv.lock, and rerun CI so these endpoint tests execute in the default development environment. The security change looks correct, but we should wait for CI to pass before merging.
|
Thanks for verifying the fix. I added FastAPI to the
I have not run the complete default development environment or the full CI suite locally. This push should let upstream CI verify the default |
Fixes #526.
Problem
GET /fileinscript/case_study.pyintends to serve only files underSTATE.static_roots. When that list is empty — the default whenever--static-rootis not given and the loaded data contains no image paths —if STATE.static_roots:is false, the whitelist check is skipped entirely,and the endpoint returns any file readable by the server process
(CWE-22, unauthenticated arbitrary file read).
Change
403 ForbiddenwhenSTATE.static_rootsis empty, matching the"no static roots configured" state reported at startup.
Tests
New tests drive the real app via FastAPI
TestClient: empty roots → 403,file under a root → 200, file outside the root → 403, missing file → 404.
Before the fix, the empty-roots case returned 200 with the file contents;
after, all 4 pass. Ruff clean. Not tested: real uvicorn deployment, Python
versions other than 3.13, non-Windows hosts.
Compatibility
Deployments that relied on
/filewhile running with no configured orauto-detected roots will now receive 403. Serving files in that state was
already unsupported ("No static roots detected; image paths will be shown
as text" at startup). To restore serving, pass
--static-rootexplicitly.