Skip to content

fix: reject PDF template uploads larger than 10MB (#460) - #722

Merged
marcvergees merged 3 commits into
fireform-core:developmentfrom
1sakshm:460-limit-template-upload-size
Oct 17, 2026
Merged

marcvergees merged 3 commits into
fireform-core:developmentfrom
1sakshm:460-limit-template-upload-size

Conversation

@1sakshm

@1sakshm 1sakshm commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Description

POST /templates/upload read the entire uploaded file into memory without checking its size, so a very large upload could exhaust server memory.

This adds a 10 MB limit (_MAX_TEMPLATE_BYTES) and reuses the same 413 pattern the voice input route already uses (app/api/routes/input.py):

  • fast path: reject based on the declared file.size before reading
  • fallback: reject based on len(content) after reading
  • error: AppError with status_code=413, error_code="FILE_TOO_LARGE" and detail={"max_size_bytes", "received_size_bytes"}

Fixes #460

Note: POST /forms/transcribe (app/api/routes/forms.py) also calls audio.file.read() with no limit. I left it out to keep this PR scoped, but I'm happy to add it here or in a follow-up.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Added test_upload_oversize_pdf_rejected in tests/test_api.py (monkeypatches the limit to 5 bytes and checks for 413 / FILE_TOO_LARGE / detail values)
  • Full suite: PYTHONPATH=. python -m pytest tests/ → 174 passed
  • ruff check app/ → all checks passed

Test Configuration:

  • Python version: 3.11
  • Docker/Compose version: N/A (tests run locally)
  • OS: Windows 11

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • The Lint workflow check passes on this PR ✅
  • The Tests workflow check passes on this PR ✅

POST /templates/upload read the whole file into memory with no size check. Reuse the 413 FILE_TOO_LARGE pattern from the voice input route: check the declared size before reading, then the actual length after.
@1sakshm
1sakshm marked this pull request as ready for review October 14, 2026 18:15
@marcvergees

Copy link
Copy Markdown
Member

Hi @1sakshm, sorry for the delay responding.

Your PR looks good, but we cannot merge it unless it has a frontend implementation too.

We should have a message error in the frontend that says so.

You can create an issue in the frontend for that and submit your PR.

We'll. be able to merge it when we have both things.

Lmk if you have problems with anything. You can tag other maintainers too.

Marc

@1sakshm

1sakshm commented Oct 17, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @marcvergees! I'll do that right away: I'll open an issue in fireform-frontend for showing the file-too-large error and send a PR for it, then link both here.

@1sakshm

1sakshm commented Oct 17, 2026

Copy link
Copy Markdown
Contributor Author

@marcvergees the frontend part is up:

Studio now checks the file size when a PDF is selected and shows the size and the 10 MB limit instead of uploading it. If the backend still returns 413, its message is shown as well.

@marcvergees
marcvergees merged commit f86744c into fireform-core:development Oct 17, 2026
2 checks passed
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]: No file size limit on PDF template upload — potential DoS

2 participants