Repository navigation
Fix stored XSS through the admin raw media route - #673
Open
parenthesis0407 wants to merge 1 commit into
Open
parenthesis0407 wants to merge 1 commit into
parenthesis0407 wants to merge 1 commit into
Conversation
must_be_escaped() marks image/svg and text/htm as content types that must not
be rendered inline. The guard was applied in getRaw() but not in
getRawById(), which backs GET /upload/{id}/raw. As a result a user-supplied
SVG or HTML file was returned with its original MIME type and an inline
disposition, so the browser rendered it and executed the embedded script in
the application origin.
Apply the same guard to getRawById() and add tests that fail without the fix:
- it_does_not_serve_svg_inline_through_the_admin_raw_route
- it_does_not_serve_html_inline_through_the_admin_raw_route
- it_still_serves_images_with_their_own_content_type_through_the_admin_raw_route
(guards against over-fixing)
This branch has not been deployed
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
must_be_escaped()(app/helpers.php:499) marksimage/svgandtext/htmas content types that must not be rendered inline by the browser. The guard is applied inMediaController::getRaw(), but not inMediaController::getRawById().getRawById()backsGET /upload/{id}/raw(app/routes.php:68), which the admin UI uses to preview uploads. Because the guard is missing, the stored file is returned with its original MIME type and an inline disposition, so a user-supplied SVG is rendered as an SVG document and its embedded script executes in the application origin.Uploads are not content-validated, so any authenticated user — including a regular, non-administrative account — can store the payload.
getRawById()also does not verify that the upload belongs to the caller, so an attacker can point an administrator at any upload id.Reproduction (on 3.8.2)
GET /systemreturns403.onload="...".N.GET /upload/N/raw.Content-Type: image/svg+xml, script executes.After this patch:
Content-Type: text/plain, script does not execute.Control: the same file served through
GET /{userCode}/{mediaCode}/raw.svgalready returnstext/plain, which confirms this is a missing call rather than intended behaviour.Fix
Mirror the existing guard from
getRaw():A possible follow-up (not included here, to keep the change minimal) is to move the downgrade into
streamMedia()so future call sites cannot miss it —show()also callsstreamMedia()without the guard for bot user agents.Tests
tests/Feature/MediaControllerTest.php:it_does_not_serve_svg_inline_through_the_admin_raw_routeimage/svg+xml(fail)text/plain(pass)it_does_not_serve_html_inline_through_the_admin_raw_routetext/html(fail)text/plain(pass)it_still_serves_images_with_their_own_content_type_through_the_admin_raw_routeimage/png(pass)image/png(pass)Verified on PHP 8.0.30:
Severity
Suggested CVSS 3.1:
CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:L/I:L/A:N— 5.7 (Medium).Attacker needs a regular account; the admin must open the link.
Note on CI
.github/workflows/test_suite.ymlonly triggers onpush/pull_requesttargetingmaster, so GitHub Actions does not run for pull requests against3.x. The suite was therefore run locally on PHP 8.0.30 against this branch:The new tests fail without the patch and pass with it:
Happy to extend the workflow trigger to
3.xas a separate change if you would like CI to run on this branch.