Security audit follow-up: bound PDF split work to the page limit, document trust model - #2
Merged
Merged
Conversation
DownloadDocumentAsPDF's split step used pdfcpu.SplitFile on the full original PDF and only used the first pagesToProcess outputs afterward, so an oversized document cost the same split work (CPU/disk) no matter what OCR_LIMIT_PAGES was set to. Trim the source down to the limited page range first (pdfcpu's TrimFile) when a limit actually applies, and split that instead.
…mption Full security audit turned up two behaviors worth calling out explicitly rather than changing: the app has no built-in auth and binds all interfaces by default (this is an accepted trust model for a self-hosted tool, but wasn't documented anywhere), and OCR_LIMIT_PAGES intentionally has no effect in whole_pdf mode.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
PR #1 got merged while this branch still had two more commits from the full security-audit pass queued up. This PR carries just those two:
fix(pdf): trim to page limit before splitting, not after—DownloadDocumentAsPDF's split step used to split every page of the source PDF via pdfcpu and only use the firstOCR_LIMIT_PAGESoutputs afterward, so an oversized document cost the same split work regardless of the configured limit. Now trims the source down to the limited page range first when a limit applies, then splits that instead. AddedTestDownloadDocumentAsPDF_SplitWithPageLimitasserting only the limited number of split files gets created on disk.docs: document the no-auth trust model and whole_pdf's page-limit exemption— the audit's other actionable finding was that paperless-gpt has no built-in authentication and binds all interfaces by default, which wasn't documented anywhere; added a### Securitysection spelling this out plus the guidance to run it behind a reverse proxy/VPN. Also documented thatOCR_LIMIT_PAGESdoesn't apply towhole_pdfmode (by design — that mode always processes the whole document).Test plan
go build ./... && go test ./...green (Docker Go 1.25.5 toolchain)OCR_LIMIT_PAGES=2