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

[stable27] disable scripting in pdfviewer #889

Merged
merged 2 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ You can view PDF files as well as Adobe Illustrator files (.ai)

![PDF Logo](https://user-images.githubusercontent.com/59488153/189176433-2f6d97a1-b151-4099-84f4-d1446a007b8a.png)

### 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

Expand Down
2 changes: 2 additions & 0 deletions src/workersrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
const urlParams = new URLSearchParams(queryString)
const canDownload = urlParams.get('canDownload')

function initializeCustomPDFViewerApplication() {

Check warning on line 37 in src/workersrc.js

View workflow job for this annotation

GitHub Actions / eslint

Missing JSDoc comment
const head = document.getElementsByTagName('head')[0]

// Preferences override options, so they must be disabled for
Expand All @@ -45,8 +45,10 @@
PDFViewerApplicationOptions.set('isEvalSupported', false)
PDFViewerApplicationOptions.set('workerSrc', head.getAttribute('data-workersrc'))
PDFViewerApplicationOptions.set('cMapUrl', head.getAttribute('data-cmapurl'))
PDFViewerApplicationOptions.set('sandboxBundleSrc', head.getAttribute('data-sandbox'))
PDFViewerApplicationOptions.set('enablePermissions', true)
PDFViewerApplicationOptions.set('imageResourcesPath', './js/pdfjs/web/images/')
PDFViewerApplicationOptions.set('enableScripting', head.getAttribute('data-enableScripting') === true)
// AnnotationMode.ENABLE value is 1 in PDF.js, which shows forms, but does
// not allow to interact with them
PDFViewerApplicationOptions.set('annotationMode', 1)
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