-
Notifications
You must be signed in to change notification settings - Fork 0
fix(api): align PDF upload transport budget with Naruon #682
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
Open
seonghobae
wants to merge
7
commits into
develop
Choose a base branch
from
fix/align-pdf-upload-budget-64m-20260821
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
71671c6
fix(api): align PDF upload transport budget
seonghobae 7147df8
docs(adr): normalize upload decision formatting
seonghobae 547998a
test(parse): accept exact upload boundary
seonghobae 03ec64c
docs(adr): complete record index
seonghobae b06b844
docs(api): document 64 MiB parse upload limit
seonghobae 93383e9
test(parse): prove first-byte-over-limit rejection
seonghobae 585bb4e
docs(api): clarify PDF file upload ceiling
seonghobae 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # ADR-0003: Bounded PDF upload transport | ||
|
|
||
| **Status:** Accepted | ||
| **Date:** 2026-08-21 | ||
| **Decision owner:** NewsDOM maintainers | ||
| **Scope:** Authenticated `POST /parse` upload boundary | ||
| **Figma File ID:** N/A — sidecar API contract; no visual surface. | ||
|
|
||
| ## Context | ||
|
|
||
| Naruon's direct PDF DOM upload contract is bounded at 64 MiB, but the owning | ||
| NewsDOM sidecar still rejected the same customer PDF above 20 MiB. That | ||
| cross-service mismatch made the equivalent email and manual workflows behave | ||
| differently and caused a customer-visible failure after the request crossed a | ||
| service boundary. | ||
|
|
||
| ## Decision | ||
|
|
||
| Set `MAX_PARSE_UPLOAD_BYTES` to 64 MiB. Keep bearer authentication before | ||
| multipart body parsing, the streaming first-byte-over-limit check, PDF | ||
| signature validation, temporary-file cleanup, and the `413 Payload Too Large` | ||
| response unchanged. | ||
|
|
||
| Naruon remains the consumer-side owner of its signed persistence boundary. This | ||
| ADR only changes the sidecar's transport ceiling; parser runtime, concurrency, | ||
| storage quotas, and deployment capacity remain separate controls. | ||
|
|
||
| ## Consequences | ||
|
|
||
| - Customers can use the same bounded 64 MiB expectation for direct and sidecar | ||
| PDF DOM ingestion. | ||
| - A larger valid upload can reach the parser, so deployment capacity and parser | ||
| timeout controls remain mandatory. | ||
| - No unbounded body read is introduced; the endpoint continues to stop on the | ||
| first byte above the limit. | ||
|
|
||
| ## References (APA 7th) | ||
|
|
||
| Internet Engineering Task Force. (2022). *HTTP semantics (RFC 9110).* RFC | ||
| Editor. https://www.rfc-editor.org/rfc/rfc9110 | ||
|
|
||
| National Institute of Standards and Technology. (2025). *Secure software | ||
| development framework (SSDF) version 1.2* (NIST Special Publication 800-218 | ||
| Rev. 1, Initial Public Draft). https://doi.org/10.6028/NIST.SP.800-218r1.ipd |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # Doctoring record: bounded PDF upload transport | ||
|
|
||
| **Observed gap:** The live NewsDOM sidecar accepted only 20 MiB while the | ||
| Naruon direct PDF DOM contract allowed 64 MiB, so equivalent customer workflows | ||
| were inconsistent. | ||
|
|
||
| **Correction:** `MAX_PARSE_UPLOAD_BYTES` and its boundary tests now use 64 MiB. | ||
| Authentication remains checked before multipart parsing, and streaming input | ||
| still fails closed at the first byte over the bound. | ||
|
|
||
| **Evidence:** `tests/test_parse_endpoint.py` covers the 64 MiB contract and the | ||
| unknown-size streaming over-limit path. Full coverage and exact-head hosted | ||
| checks remain required before merge. | ||
|
|
||
| **References (APA 7th):** | ||
|
|
||
| - Internet Engineering Task Force. (2022). *HTTP semantics (RFC 9110).* RFC | ||
| Editor. https://www.rfc-editor.org/rfc/rfc9110 | ||
| - National Institute of Standards and Technology. (2025). *Secure software | ||
| development framework (SSDF) version 1.2* (NIST Special Publication 800-218 | ||
| Rev. 1, Initial Public Draft). https://doi.org/10.6028/NIST.SP.800-218r1.ipd |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| """Exact streaming-boundary regressions for the public PDF upload budget.""" | ||
|
|
||
| import pytest | ||
| from fastapi import HTTPException | ||
|
|
||
| from newsdom_api.main import MAX_PARSE_UPLOAD_BYTES, parse | ||
|
|
||
|
|
||
| class _VirtualPdfUpload: | ||
| """Stream a bounded synthetic PDF without allocating the full payload.""" | ||
|
|
||
| content_type = "application/pdf" | ||
| filename = "fixture.pdf" | ||
| size = None | ||
|
|
||
| def __init__(self, total_bytes: int) -> None: | ||
| self.total_bytes = total_bytes | ||
| self.bytes_returned = 0 | ||
|
|
||
| async def read(self, size: int = -1) -> bytes: | ||
| """Return at most ``size`` bytes while preserving a valid PDF prefix.""" | ||
| remaining = self.total_bytes - self.bytes_returned | ||
| if remaining <= 0: | ||
| return b"" | ||
| count = remaining if size < 0 else min(size, remaining) | ||
| prefix = b"%PDF-" | ||
| start = self.bytes_returned | ||
| chunk = b"" | ||
| if start < len(prefix): | ||
| prefix_count = min(count, len(prefix) - start) | ||
| chunk = prefix[start : start + prefix_count] | ||
| count -= prefix_count | ||
| if count: | ||
| chunk += b"x" * count | ||
| self.bytes_returned += len(chunk) | ||
| return chunk | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_streaming_upload_rejects_exact_first_byte_over_budget() -> None: | ||
| """Reject after consuming exactly the first byte beyond the 64 MiB ceiling.""" | ||
| upload = _VirtualPdfUpload(MAX_PARSE_UPLOAD_BYTES + 1) | ||
|
|
||
| with pytest.raises(HTTPException) as exc_info: | ||
| await parse(upload) | ||
|
|
||
| assert exc_info.value.status_code == 413 | ||
| assert exc_info.value.detail == "Payload Too Large" | ||
| assert upload.bytes_returned == MAX_PARSE_UPLOAD_BYTES + 1 |
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.