-
Notifications
You must be signed in to change notification settings - Fork 56
fix(security): backport DoS caps + log hygiene lost in the refactor #591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
48e69f2
fix(security): bound upload size to prevent disk/memory exhaustion
andyne13 ce5842c
fix(security): bound parser fan-out/page counts; fix DOCX memory bomb
andyne13 eca396d
fix(security): default logs to INFO and drop user query from web-sear…
andyne13 bcd79fc
fix(security): resolve upload-size cap at call time so .env is honored
Ahmath-Gadji 697aabe
fix(security): surface upload-rejection status instead of masking as 500
Ahmath-Gadji File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
tests/unit/api/routers/admin/test_indexing_upload_errors.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| """The add-file route must surface upload-rejection status codes. | ||
|
|
||
| ``save_file_to_disk`` raises ``ValidationError`` (e.g. 413 for an oversize | ||
| upload) which is an ``OpenRAGError``. Regression guard: the route's broad | ||
| ``except Exception`` must not mask that as a 500 — the OpenRAGError handler | ||
| should map it to its real status. | ||
| """ | ||
|
|
||
| import io | ||
| from types import SimpleNamespace | ||
|
|
||
| import httpx | ||
| import pytest | ||
| from api.dependencies.auth import check_user_file_quota, require_partition_editor | ||
| from api.dependencies.files import validate_file_format, validate_file_id, validate_metadata | ||
| from api.error_handlers import register_error_handlers | ||
| from api.routers.admin.indexing import router as indexer_router | ||
| from di.providers import get_config, get_indexing_service | ||
| from fastapi import FastAPI, UploadFile | ||
|
|
||
|
|
||
| class _FakeIndexingService: | ||
| async def file_exists(self, file_id: str, partition: str) -> bool: | ||
| return False | ||
|
|
||
|
|
||
| def _empty_metadata() -> dict: | ||
| return {} | ||
|
|
||
|
|
||
| def _build_app(tmp_path, monkeypatch, content: bytes) -> FastAPI: | ||
| # Cap at ~8 bytes so a small upload trips the limit. | ||
| monkeypatch.setattr("api.dependencies.files._max_upload_size_bytes", lambda: 8) | ||
|
|
||
| app = FastAPI() | ||
| register_error_handlers(app) | ||
| app.include_router(indexer_router, prefix="/indexer") | ||
|
|
||
| cfg = SimpleNamespace(paths=SimpleNamespace(data_dir=str(tmp_path / "data"))) | ||
|
|
||
| app.dependency_overrides[validate_file_id] = lambda: "f1" | ||
| app.dependency_overrides[validate_file_format] = lambda: UploadFile(file=io.BytesIO(content), filename="big.bin") | ||
| app.dependency_overrides[validate_metadata] = _empty_metadata | ||
| app.dependency_overrides[require_partition_editor] = lambda: {"id": 1, "is_admin": True} | ||
| app.dependency_overrides[check_user_file_quota] = lambda: None | ||
| app.dependency_overrides[get_config] = lambda: cfg | ||
| app.dependency_overrides[get_indexing_service] = lambda: _FakeIndexingService() | ||
| return app | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_add_file_oversize_returns_413_not_500(tmp_path, monkeypatch): | ||
| app = _build_app(tmp_path, monkeypatch, content=b"x" * 100) | ||
| transport = httpx.ASGITransport(app=app) | ||
| async with httpx.AsyncClient(transport=transport, base_url="http://testserver") as client: | ||
| resp = await client.post("/indexer/partition/p1/file/f1", data={"_": "1"}) | ||
|
|
||
| assert resp.status_code == 413 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.