fix(view): let the package iframe start downloads (allow-downloads) - #161
Merged
Merged
Conversation
Without allow-downloads the browser silently drops every download the package frame starts: <a download> links and the download-source-file iDevice's "Download .elpx" button, which rebuilds the package in the browser (exelearning/exelearning#2488). Same-origin package script can already download through the parent, so this grants no new capability.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #161 +/- ##
=========================================
Coverage 93.92% 93.92%
Complexity 810 810
=========================================
Files 46 46
Lines 3554 3554
=========================================
Hits 3338 3338
Misses 216 216
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 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.
Refs exelearning/exelearning#2488. Related: exelearning/exelearning#2489, exelearning/omeka-s-exelearning#63, exelearning/wp-exelearning#156.
Thanks to smorros for reporting the original issue and to @biyayo for forwarding it.
Problem
The package iframe in
view.phpis sandboxed withoutallow-downloads. Chrome (83+) and Firefox (82+) then silently drop every download the frame starts, with a console message like "Download is disallowed. The frame initiating or instantiating the download is sandboxed, but the flag 'allow-downloads' is not set". Two things are affected:<a download>links authored in the package..elpxin the browser (refetch + fflate), and the progress bar completes, but no file is ever saved.I reproduced the drop in Chrome on the Omeka S module, which has the same sandbox without
allow-downloads. There the rebuild finished and Chrome logged the message above.Why not intercept like Omeka and WordPress
In Omeka S and WordPress, the in-content button is routed to the original upload, because those embeds already offer that file publicly. I did not do that here. The original lives in the
packagefile area, andexelearning_pluginfile()limits it tomoodle/course:manageactivities("Only teachers can download the full ELPX package",lib.php:545-557). Serving it to students would change the permission model.The in-browser rebuild only packs what the learner can already see. Moodle sends no CSP for
pluginfile.php, so fflate'sblob:workers are not blocked here: the "Processing... 100%" hang from #2488 does not happen. The missing sandbox flag is the only thing stopping the download.Change
view.php: addallow-downloadsto the package iframe sandbox, with the rationale next to the code.allow-same-origin+allow-scripts, package script can already start a download through the parent (TRACKING threat 8).allow-top-navigationandallow-modalsstay blocked.tests/behat/mod_exelearning.feature: a server-rendered scenario (no@javascript) asserts that the sandbox containsallow-downloadsand still omitsallow-top-navigationandallow-modals.docs/TRACKING.md: documents the flag, fixes the staleview.phpline reference in threat 8, and notes that any futurecontentCSP (DEC-0-16 M3) must allowworker-src 'self' blob:.version.php: 2026092610 → 2026092900 (release = 'dev').Verification
vendor/bin/phpcs --standard=moodle view.php version.phpreports 0 errors and 0 warnings;php -l view.phpis clean.make check-version→ OK (development).make architecture-check→ OK.moodle-plugin-ci behat).Moodle Playground Preview
The changes in this pull request can be previewed and tested using a Moodle Playground instance.
ℹ️ The eXeLearning editor is fetched from the shared release and unpacked into the plugin when the playground boots, so the first load may take a few extra seconds. ELPX upload, viewer and preview work normally.