Skip to content

fix(security): forbid /file when no static roots are configured - #547

Open
zoechen281 wants to merge 2 commits into
OpenBMB:mainfrom
zoechen281:codex/file-empty-static-roots
Open

zoechen281 wants to merge 2 commits into
OpenBMB:mainfrom
zoechen281:codex/file-empty-static-roots

Conversation

@zoechen281

Copy link
Copy Markdown

Fixes #526.

Problem

GET /file in script/case_study.py intends to serve only files under
STATE.static_roots. When that list is empty — the default whenever
--static-root is 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

  • Return 403 Forbidden when STATE.static_roots is empty, matching the
    "no static roots configured" state reported at startup.
  • Non-empty whitelist behavior is unchanged.
  • No dependencies added.

Tests

pytest --noconftest -p no:cacheprovider -q tests/ultrarag/test_case_study_file_endpoint.py

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 /file while running with no configured or
auto-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-root explicitly.

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 xhd0728 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@zoechen281

Copy link
Copy Markdown
Author

Thanks for verifying the fix. I added FastAPI to the dev dependency group and updated uv.lock in eab9cfd. All 382 locked package versions and sources are unchanged.

uv lock --check --offline passes, and the default frozen requirements export now includes fastapi==0.141.1. The four endpoint tests also pass in a fresh Windows/Python 3.12 environment using the exact locked FastAPI/TestClient dependencies (22 binary wheels).

I have not run the complete default development environment or the full CI suite locally. This push should let upstream CI verify the default uv sync and test steps; I will address any further failures.

@zoechen281

Copy link
Copy Markdown
Author

Hi @xhd0728 — I've pushed eab9cfd adding FastAPI to the dev dependency group with the regenerated uv.lock. The CI run on that commit is currently action_required, waiting for maintainer approval to run. Could you approve the workflow when you get a chance? Thanks!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

【Security Vulnerability Report】CWE-22 /file endpoint unauthenticated arbitrary file read (CVSS 7.5)

2 participants