Skip to content

fix: harden PDF.js for strict CSP - #115

Merged
vitormattos merged 9 commits into
mainfrom
fix/pdfjs-strict-csp
Sep 18, 2026
Merged

vitormattos merged 9 commits into
mainfrom
fix/pdfjs-strict-csp

Conversation

@vitormattos

Copy link
Copy Markdown
Member

What changed

  • disable PDF.js eval-based execution with isEvalSupported: false
  • disable embedded PDF scripting with enableScripting: false
  • prevent callers from overriding these two safety defaults
  • add unit coverage for the PDF.js options
  • add a Playwright scenario that renders a PDF under a CSP without unsafe-eval

Why

pdf-elements is embedded by applications such as LibreSign that run with a restrictive Content Security Policy. PDF rendering does not need dynamic evaluation or embedded PDF JavaScript for our use case, so these features should stay disabled by default.

This change was prepared while investigating CSP errors in LibreSign on Nextcloud. It does not assume that pdf-elements is the cause of that separate rendering issue.

Tests

The unit tests verify that safe PDF.js options are always passed to getDocument(), including when a caller attempts to enable them.

The Playwright test loads the demo with a CSP that does not allow unsafe-eval, renders a PDF, and checks for eval-related CSP/page errors.

@vitormattos
vitormattos requested a review from a team as a code owner September 18, 2026 15:45
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
@vitormattos
vitormattos merged commit bb28515 into main Sep 18, 2026
5 checks passed
@vitormattos
vitormattos deleted the fix/pdfjs-strict-csp branch September 18, 2026 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant