Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable23] disable scripting in pdfviewer #893

Merged
merged 2 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ files_pdfviewer
This application integrates the [PDF.js](https://mozilla.github.io/pdf.js/) library into Nextcloud's Viewer.
You can view PDF files as well as Adobe Illustrator files (.ai)

### Enable Javascript execution in PDF files

To allow Javascript embedded in PDF-files to be executed inside the PDF-viewer inside your browser, enable it with:

`php occ config:app:set files_pdfviewer enable_scripting --value=yes`

Disable:

`php occ config:app:delete files_pdfviewer enable_scripting`

## 🏗 Development setup

1. ☁ Clone this app into the `apps` folder of your Nextcloud: `git clone https://github.com/nextcloud/files_pdfviewer.git`
Expand Down
4 changes: 2 additions & 2 deletions js/files_pdfviewer-workersrc.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/files_pdfviewer-workersrc.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/workersrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @author Daniel Calviño Sánchez <[email protected]>
* @author John Molakvoæ <[email protected]>
*
* @license GNU AGPL version 3 or any later version

Check warning on line 8 in src/workersrc.js

View workflow job for this annotation

GitHub Actions / node

Invalid JSDoc @license: "GNU AGPL version 3 or any later version"; expected SPDX expression: https://spdx.org/licenses/

Check warning on line 8 in src/workersrc.js

View workflow job for this annotation

GitHub Actions / eslint

Invalid JSDoc @license: "GNU AGPL version 3 or any later version"; expected SPDX expression: https://spdx.org/licenses/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand Down Expand Up @@ -41,7 +41,7 @@
// listening to the "webviewerloaded" event, which is emitted after
// "PDFViewerApplication" and "PDFViewerApplicationOptions" are globally set and
// before "PDFViewerApplication.initialize" is executed.
function initializeCustomPDFViewerApplication() {

Check warning on line 44 in src/workersrc.js

View workflow job for this annotation

GitHub Actions / node

Missing JSDoc comment

Check warning on line 44 in src/workersrc.js

View workflow job for this annotation

GitHub Actions / eslint

Missing JSDoc comment
// Preferences override options, so they must be disabled for
// "externalLinkTarget" to take effect.
PDFViewerApplicationOptions.set('disablePreferences', true)
Expand All @@ -50,6 +50,8 @@
PDFViewerApplicationOptions.set('workerSrc', document.getElementsByTagName('head')[0].getAttribute('data-workersrc'))
PDFViewerApplicationOptions.set('cMapUrl', document.getElementsByTagName('head')[0].getAttribute('data-cmapurl'))
PDFViewerApplicationOptions.set('enablePermissions', true)
PDFViewerApplicationOptions.set('sandboxBundleSrc', document.getElementsByTagName('head')[0].getAttribute('data-sandbox'))
PDFViewerApplicationOptions.set('enableScripting', document.getElementsByTagName('head')[0].getAttribute('data-enableScripting') === true)

if (canDownload === '0') {
const pdfViewer = window.document.querySelector('.pdfViewer')
Expand Down
6 changes: 6 additions & 0 deletions templates/viewer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
/** @var OCP\IURLGenerator $urlGenerator */
$urlGenerator = $_['urlGenerator'];
$version = \OC::$server->getAppManager()->getAppVersion('files_pdfviewer');
$enableScripting = false;
if (\OC::$server->getConfig()->getAppValue('files_pdfviewer', 'enable_scripting', 'no') === 'yes') {
$enableScripting = true;
}
?>

<!DOCTYPE html>
Expand All @@ -29,6 +33,8 @@
-->
<html dir="ltr" mozdisallowselectionprint>
<head data-workersrc="<?php p($urlGenerator->linkTo('files_pdfviewer', 'js/pdfjs/build/pdf.worker.js')) ?>?v=<?php p($version) ?>"
data-enableScripting="<?php p($enableScripting ? true : false) ?>"
data-sandbox="<?php p($urlGenerator->linkTo('files_pdfviewer', 'js/pdfjs/build/pdf.sandbox.js'))?>"
data-cmapurl="<?php p($urlGenerator->linkTo('files_pdfviewer', 'js/pdfjs/web/cmaps/')) ?>">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
Expand Down
Loading