Skip to content

Fix(findrive): reject empty/whitespace filenames before DB write in upload_file#436

Open
Jean-Regis-M wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Jean-Regis-M:patch-37
Open

Fix(findrive): reject empty/whitespace filenames before DB write in upload_file#436
Jean-Regis-M wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Jean-Regis-M:patch-37

Conversation

@Jean-Regis-M
Copy link
Copy Markdown
Contributor

Summary

Fixes #366

Adds missing filename presence validation to upload_file, preventing
ghost records from being created with empty or whitespace-only filenames.

Problem

upload_file(filename='', content='data') bypassed all validation and
called repo.create_file(filename='', ...), persisting an unresolvable
record in the file index.

Root Cause

upload_file validated content size but had no guard on filename,
allowing empty strings to reach the repository layer unconditionally.

Solution

Added a two-condition guard (not filename or not filename.strip()) as
the first check in upload_file, returning {"error": "Filename must not be empty"} before any DB interaction occurs.

Impact

  • No breaking changes
  • Minimal diff (+2 lines, 0 removed)
  • Deterministic early return on invalid input
  • Zero regression risk to valid upload paths

Testing

pytest tests/unit/mcp/test_findrive.py::TestUploadFile::test_fd_upload_007_empty_filename_accepted_without_validation -v
pytest tests/unit/mcp/test_findrive.py::TestUploadFile::test_fd_upload_001_upload_returns_file_id_and_metadata -v

Root cause:
upload_file had no presence check on filename, allowing repo.create_file()
to persist unresolvable ghost records with empty filenames.

Solution:
Added `if not filename or not filename.strip()` guard before DB write,
returning a structured error consistent with existing tool error responses.

Impact:
No breaking changes. Deterministic early return. Zero DB side effects on
invalid input.

Signed-off-by: JEAN REGIS <240509606@firat.edu.tr>
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.

Bug_157_MUST_FIX: FD-UPLOAD-007 — Empty filename accepted; ghost record created in file index

1 participant