-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
CSP violations for unsafe-inline in pdfjst-dist@2.2.228 #11036
Comments
That's not actually code originating anywhere within the PDF.js library itself, but it rather comes from a Babel polyfill needed to support |
Yes, I think this should be reported upstream instead. |
@timvandermeij Code in pdf.js could be written so that the polyfill is not needed. |
Looked deeper into it. No chance :-( |
Here is the issue regenerator-runtime/runtime.js. |
Same issue here. @Snuffleupagus it's possible to distribute 2 separate files one for the older browser a 2nd for the evergreen browsers? |
Is there any issue upstream to track? Facing the same issue currently |
You can report the issue to https://github.com/facebook/regenerator. It looks like they fixed some CSP violations there before, so perhaps they are willing to fix this one too. If they fix it upstream, we can update the version we use to fix it on our side too. |
It looks like the authors of pdf.js fixed this issue here but due issues on babel they had to rollback it It looks like we have a deadlock here. I see three solutions here:
Anyway the CSP violation the well documented here
It means, if you have an CSP violation you should not run this in strict mode. Since this is a known behavior in regenerator-runtime, pdf.js need should turn off the strict-mode. @timvandermeij Can you re-read the comment please if there is a task todo for pdf.js or not? |
I don't really see what PDF.js could do differently here. Even though the comment is clear, we intentionally run PDF.js with strict mode to prevent errors and allow for optimizations. Given that this didn't happen before and we don't even use |
Thanks for figure it out. What about a babel free version of pdf.js ? Modern browsern should not need regenerator-runtime polyfill. |
@jkroepke Ideally we wouldn't use Babel at all, but unfortunately it's required for now for PDF.js to work in all browsers that we support, so getting rid of it is not something we can consider right now. Of course you can build PDF.js yourself and disable Babel transpiling. |
I am experiencing the same issue with 2.3.200. Any workaround or fixes? Thanks. |
At the end, I see that pdf.js is doing it wrong since it use the strict mode which is not supported when using regenerator-runtime/babel. So it's not an upstream problem anymore because the limitations are well documented. I see 4 alternatives to resolve this issues:
|
Pinning a dependency to an old version is never a good idea, since it for one may cause issues if there's any security bugs in older Babel versions. Furthermore, using older versions of one dependency may prevent, delay, and/or complicate updating of other dependencies thus causing other problems. Just to clarify: Please note that the PDF.js library isn't (currently) using any generator functions, however
This seems like the most realistic option out of the suggestions above, but how/when that will happen isn't clear at this point in time (note the discussion/problems in PR #11241).
|
Would you respect to use only functions/technologies supported by the lastest 2 major browser versions? A version with super bleeding edge language proposals functions which not supported by newer browser would not help us. |
That would require producing three different types of builds, which doesn't seem like a great idea. For one, users would probably be even more confused as to which build to use (since I imagine users being unsure even with just two types of builds). Furthermore, attempting to provide multiple builds will also put more of a strain, e.g. related to both support and maintenance, on the few regular PDF.js contributors. Basically, the desirable situation in this case as far as I'm concerned would be that a library user either:
Historically speaking I don't think that we've ever started to use functionality immediately when it became available in e.g. Firefox Nightly, hence I cannot foresee this actually being much of a problem in practice. |
Hi, I ran into the same issue, the solution i used was to load regenerator-runtime thought my polyfill directly. This way i didn't change pdfjs-dist. It allowed me to resolve my CSP issues without having to recompile pdfjs :) |
@makidelille Do you use angular? |
we use angularjs (still). To be exact, we have build a custom viewer on top of pdf.js that is used throught a angularjs directive edit: the custom viewer is build with typescript angularjs, that's why we have polyfills. |
I am getting another unsafe-inline error for the CSS, from this line of code:
|
Do you (or anyone else) know how this solution would translate to angular 2+ ? Is it possible to fix this? I am using this library and running into the same CSP problem (if you'd like you can see my ticket in that projects issues list), but these sorts of problems with packages/npm/dependency type stuff is not something I grasp all that well. Unfortunately the old version of pdfjs that did not have this problem (2.1.266, as mentioned above) does not seem to be compatible with this angular 2+ wrapper library, and it does not appear to have a version that used that version of pdfjs internally. edit: For anyone in a similar situation as me, there is another angular pdfjs wrapper library that worked for me with no CSP issues. See here. |
I believe that this issue can be closed now, since the upcoming release will feature two kinds of builds:
|
Sounds good! Thanks @Snuffleupagus and everyone worked on this 🥇 |
This is necessary to remove `unsafe-eval` from manifest.json CSP See mozilla/pdf.js#11036
For those wondering how to disable strict mode, this is an attempt if you're building yourself: 226106d You can then simply run |
Attach (recommended) or Link to PDF file here:
Configuration:
v2.2.228
Steps to reproduce the problem:
We have a content security policy that prevents
unsafe-inline
.The policy is violated by this line in
v2.2.228
Function("r", "regeneratorRuntime = r")(runtime);Additional info:
Similar issue #10229
The text was updated successfully, but these errors were encountered: