fix(security): refuse top-level asset loads and cap screenshot reads - #128
Merged
Merged
Conversation
The server asset fallback served package HTML under the Nextcloud origin with no sandbox, so a crafted shared .elpx opened directly at /apps/exelearning/asset/<id>/index.html ran its scripts as the victim. Refuse requests whose Sec-Fetch-Dest is 'document'; the viewer iframe sends 'iframe' and keeps working. screenshot.png reads were only bounded by the 500 MB package limit, and getFromName() reserves the declared size up front, so one package could fatal every thumbnail run. Cap that read at 10 MB and map an oversized screenshot to 404 in ThumbnailController.
Contributor
Preview this PR in the Nextcloud PlaygroundA fresh Nextcloud boots in your browser with this branch's eXeLearning editor: |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #128 +/- ##
============================================
+ Coverage 93.75% 93.79% +0.03%
- Complexity 150 152 +2
============================================
Files 22 22
Lines 657 661 +4
Branches 54 54
============================================
+ Hits 616 620 +4
Misses 34 34
Partials 7 7 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Stack 1/5. Stacked PRs from a code-modernization pass (security first).
What
AssetController::fetchserved package HTML on the Nextcloud origin with no sandbox. A shared.elpxwhose/asset/<id>/index.htmlwas opened as a top-level page would run its scripts with the viewer's session. The route now answers 403 whenSec-Fetch-Dest: document. The viewer iframe sendsiframe, so the fallback keeps working. Browsers without Fetch Metadata still pass, so this is a stopgap until the opaque-origin work in Secure opaque-origin viewer and editor preview #68 lands.screenshot.pngreads were only capped by the 500 MB package limit.getFromName()reserves the declared size up front, so one crafted package could fatal every thumbnail run (cron, Files grid).ZipEntryService::readEntrytakes an optional per-read cap. The preview provider andThumbnailControllerpass 10 MB, and the thumbnail route maps an oversized screenshot to 404 instead of a 500.Not in scope
The same-origin iframe sandbox (
allow-scripts+allow-same-origin) is covered by #68.Verification