-
Notifications
You must be signed in to change notification settings - Fork 188
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
PDF fails to load with script-src 'self' CSP directive #687
Comments
Holy moly! OK, back to square one, once again... I've done quite a bit of research before implementing the At the moment, I'm out of clues. Maybe you can help it. Everything could be easy if Angular allowed me to use a simple JavaScript file. But I didn't find a way to include a JavaScript file, apart from uploading a library to npm, which feels like overkill to me. Basically, all I need is to excecute the Any suggestions? |
In terms of loading a JS file into Angular, I'm aware of two ways to do that. One would be to load it dynamically, whereas the other would be to apply it to the scripts block in your angular-cli.json file. Something else to play with is to see what can be run using |
Awesome, thanks! The approach using |
Hitting this too! |
I noticed you've pushed some changes for this? Any chance we could get a package released with the fix or are you still testing it. Thanks! |
Sorry for the late answer - the last couple of week have been busy. The bugfix has landed with the current 9.0.0-alpha versions. |
@stephanrauh I get the same issue, using
|
Hum I'm not sure why it is loading the es5 version, I'm on Chrome and a very tight browserlist:
|
ah ok I've got it, I'll raise a separate issue |
Describe the bug
When applying content security policy
script-src 'self'
to your website, the viewer fails to load the PDF. The browser console includes an error that reads:Uncaught EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'self'".
Version info
Desktop
To Reproduce
^8.2.0
<meta http-equiv="Content-Security-Policy" content="script-src 'self'">
Screenshots
Additional context
In investigating this issue, I was led to ngx-extended-pdf-viewer.component.ts and its routine for checking for whether or not to use the ES5 library. Part of this check involves evaluating the JavaScript expression
null?.size()
. However, it uses theeval
function to verify this, which is prohibited by the CSP. This is what generates the error and ultimately results in a false positive that incorrectly sets theneedsES5
flag to true. Below is the offending line of code.ngx-extended-pdf-viewer/projects/ngx-extended-pdf-viewer/src/lib/ngx-extended-pdf-viewer.component.ts
Line 600 in a3965cb
An interesting historical tidbit, the original complaint that led to there being two builds of the PDF.js library was an incompatibility with a CSP policy.
mozilla/pdf.js#11036
Let me know if you have any further questions. Thank you in advance for your help!
The text was updated successfully, but these errors were encountered: