Repository navigation
Conversation
Previously, archiveFile checked the Content-Length response header against MAX_BODY_LENGTH, defaulting to 0 when the header was missing (such as with chunked transfer-encoding) or trusting a spoofed low Content-Length. This allowed oversized payloads to bypass the limit and be written to disk. Verify both the Content-Length header and the actual response body length against MAX_BODY_LENGTH before writing the file. Reported-by: BS.ehlas.cz Assisted-by: Antigravity:gemini-3.8-flash
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.
Problem
When archiving non-HTML bookmark content in
CrawlService::archiveFile(), the service checked theContent-Lengthheader againstMAX_BODY_LENGTH(90 MB):If a remote server returns chunked transfer-encoding (omitting the
Content-Lengthheader entirely) or provides a falsified low header value (e.g.,Content-Length: 10),$contentLengthevaluated to0or a small integer. As a result, the condition evaluated totrue, and the entire unbounded response body could be written to user storage.Solution
Content-Lengthearly; return immediately if reported as >=MAX_BODY_LENGTH.strlen($body)) before creating a file and writing it to user storage.MAX_BODY_LENGTH.Tests
tests/CrawlServiceTest.php:testArchiveFileRejectsMissingContentLengthWhenBodyOversized: verifies that chunked responses with missingContent-LengthexceedingMAX_BODY_LENGTHare not saved.testArchiveFileRejectsSpoofedContentLengthWhenBodyOversized: verifies that responses with a spoofed smallContent-LengthexceedingMAX_BODY_LENGTHare not saved.testArchiveFileSavesValidBodyWithinLimit: verifies that legitimate files within the limit continue to be archived correctly.composer cs:check) passes without issues.