Skip to content

fix(Generator): save uploads under a server-generated filename - #677

Open
harshita-singh12 wants to merge 5 commits into
AOSSIE-Org:mainfrom
harshita-singh12:fix-upload-path-hardening
Open

harshita-singh12 wants to merge 5 commits into
AOSSIE-Org:mainfrom
harshita-singh12:fix-upload-path-hardening

Conversation

@harshita-singh12

@harshita-singh12 harshita-singh12 commented Aug 27, 2026 •

Copy link
Copy Markdown

Fixes #676

Problem

FileProcessor.process_file() built the on-disk path by joining the client-controlled file.filename with the upload folder. A crafted filename such as ../../app.py escapes uploads/, so file.save() can overwrite any process-writable file and the subsequent os.remove() can delete it.

Fix

  • The storage filename is now generated server-side (uuid.uuid4().hex), so the on-disk path can never escape the upload folder regardless of what the client sends.
  • Only the extension is preserved from the client name, and only when it is one of the three types the extraction dispatch actually handles (.txt, .pdf, .docx). Anything else returns "" before anything is written to disk, which matches the previous outcome for unsupported types (/upload responds 400).
  • Extension-based dispatch now keys off the validated extension instead of re-reading file.filename.

Testing

Validated the process_file logic directly (module import stubbed for heavy ML deps):

  • normal .txt upload round-trips and the saved path is inside the upload folder with a uuid name;
  • filenames ../../evil.txt and ../server.docx are saved inside the upload folder (no file created outside it);
  • unsupported extension (.md) saves nothing and returns "" (same /upload 400 response as before).

Summary by CodeRabbit

  • Bug Fixes
    • Improved file upload handling with unique server-generated filenames while preserving file extensions.
    • Restricted uploads to supported TXT, PDF, and DOCX formats.
    • Improved text extraction by consistently recognizing validated file types.
    • Unsupported file formats are now rejected consistently, helping prevent upload and processing issues.
    • Improved document processing descriptions for supported PDF and DOCX files.

The upload path was built by joining the client-supplied filename with
the upload folder, so a crafted name like ../../app.py could escape
uploads/ and let file.save() overwrite arbitrary process-writable files
(and os.remove() delete them afterwards).

Derive the on-disk name from uuid4() on the server and keep only the
extension, which already drives the text-extraction dispatch. File
extensions outside the supported .txt/.pdf/.docx set are rejected before
anything touches the disk, matching the previous behavior of returning
empty content for unsupported types.
@coderabbitai

coderabbitai Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 2762dae6-0842-449e-acd1-f4fdc210d6ee

📥 Commits

Reviewing files that changed from the base of the PR and between 9c68fcd and 3759c92.

📒 Files selected for processing (1)
  • backend/Generator/main.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • backend/Generator/main.py

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

FileProcessor.process_file now accepts only .txt, .pdf, and .docx files. It saves accepted files with server-generated UUID filenames and uses the validated extension for extraction. Extraction methods now include documentation.

Changes

Secure upload processing

Layer / File(s) Summary
Validated UUID upload handling
backend/Generator/main.py
FileProcessor.process_file rejects unsupported extensions, saves accepted files with UUID-based names, preserves the extension, and selects extraction logic from the validated extension. PDF and DOCX extraction methods now include docstrings.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 3759c

No actionable merge-blocking risk remains in the upload-path handling change.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: saving uploads with server-generated filenames.
Linked Issues check ✅ Passed The PR meets the coding requirements in issue #676. FileProcessor.process_file() now uses server-generated UUID filenames, so client path components do not control the upload path. The implementatio…
Out of Scope Changes check ✅ Passed The changes stay within issue #676. The UUID filename handling, extension allowlist, extraction dispatch, tests, and related docstrings support the upload-path security fix. No unrelated change is ide…
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 1 files.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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: FileProcessor.process_file uses client-controlled filename as on-disk path

1 participant