Skip to content

Fix(findrive): resolve path traversal validation gap in upload_file#435

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

Fix(findrive): resolve path traversal validation gap in upload_file#435
Jean-Regis-M wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Jean-Regis-M:patch-36

Conversation

@Jean-Regis-M
Copy link
Copy Markdown
Contributor

Summary

Fixes #359
Rejects filenames containing .. or a leading / before any database write occurs.

Problem

upload_file accepted filenames such as ../../../etc/passwd without validation,
passing them directly to repo.create_file(). If filenames are used in filesystem
operations downstream, this enables directory escape and arbitrary file read/write.

Root Cause

No path traversal check existed between parameter ingestion and repo.create_file().
The size check was the only guard; filename content was entirely trusted.

Solution

Added two-condition guard immediately after the size check:

if ".." in filename or filename.startswith("/"):
    return {"error": "filename contains invalid path traversal sequences"}

Consistent with existing early-return error style. No other lines changed.

Impact

  • No breaking changes
  • Minimal diff (2 lines added)
  • Deterministic rejection behavior
  • Zero regression risk

Testing

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

Root cause:
upload_file passed filename directly to repo.create_file() without
validating for ".." components or absolute paths, allowing traversal
sequences to be stored unchecked.

Solution:
Added early-return guard checking for ".." in filename or leading "/"
immediately after the existing size check, before any DB interaction.

Impact:
No breaking changes. Valid filenames unaffected. Deterministic rejection
of traversal inputs. Zero regression risk.

Signed-off-by: JEAN REGIS <240509606@firat.edu.tr>
@Jean-Regis-M Jean-Regis-M marked this pull request as ready for review March 30, 2026 19:22
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_150_MUST_FIX: FD-FNAME-002 — Path traversal in filename accepted; ../../../etc/passwd stored without validation

1 participant