-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Uncaught EvalError: 'unsafe-eval' is not an allowed source of script in the following Content #713
Comments
hello @charutiwari04, did You fix it? Could you write some additional info? |
Hi @Siemienik, I am not able to solve it. This is what i have. the above error is content security policy error. |
@charutiwari04 have you any example code/repo/gist? |
@Siemienik Here it is. Below function is being called when button is clicked.
|
@charutiwari04 I've just tested your example, and I note, that the wrong data type pushed into
|
Does it work if you add It looks like the "dist" version of the lib does contain |
@papandreou Perfect Solution. It is working for me. Thank You. After I added
|
Following this bug that I had too The declare.js is required by extended.js required by fast-csv required by exceljs (something like that) Allow 'unsafe-eval' in CSP is not a solution we could afford as it reduces the CSP purpose ! The only solution I've found so far is to :
I'll submit a PR to declare.js in order to fix that. But, if it's never accepted, what do you think will be the best solution for exceljs ? One solution is to define an option to toggle the load of CSV capabilities (and therefor fast-csv) but not super practical as it means you can not use work on CSV with strong CSP. |
@pierre-aurele-martin did you ever submit a PR for this issue? I am like you and cannot allow unsafe-eval. |
The unsafe-eval problem has been existing so long. The cause is that regenerator library (regenerator-runtime) requires us to not be running on strict mode. As a quick fix, I modified sed -i "s/[\"|']use strict[\"|']/;/g" dist/exceljs.js I also confirmed tests pass. npm run build && sed -i "s/[\"|']use strict[\"|']/;/g" dist/exceljs*js && npm run test:jasmine Unfortunately I don't know much about grunt and browserify. So I can't immediately make a pull-request according to this. |
So it seems like fast-csv was actually an issue but has been fixed in the meanwhile and this should not cause errors anymore. @cashewnuts Are you sure that the regenerator library was the cause? It seems to be only a devDependency, so why would it cause an error at runtime? Or is it used by one of the dependencies? Edit: Okay it seems the regenerator-runtime is required here: https://cdn.jsdelivr.net/npm/[email protected]/dist/es5/exceljs.browser.js |
regenerator-runtime reports (here) the following comment:
This comment definitely confirms (if still needed) that the strict mode is the problem... Is there any chance to officially solve this issue? |
Is there any way we can get this bumped in priority? |
Since my project very much needs CSP to work and we are using this package, I spent some time investigating this one. It appears "use strict" is may be added by browserify process already, and it seems like the interplay with babel just makes it more difficult. There are many ways to disable babel from adding "use strict" definitions, but as they are not defined by babel at all, all the known ways seem to fail (I tried many). I haven't been played with ES transpilation lately, but I must ask if we even need Browserify anymore? Could the stack be simplified by using babel alone, and the "use strict" definitions would be easier to solve? |
I made a PR #1664 for a brute force replacement of "use strict". I believe it should have no shortcomings except that somebody could slip unstrict code into web builds. I believe most of us use ExcelJS bundled with Webpack or such, so I believe the builds are already strict by various other ways. Please let me know if this works for you and whether it is an acceptable fix to the problem. |
I've worked around this issue on my project by importing the bare version of |
@notclive How did you manage to do such an import? Would be nice to get it working in our webpack based build. |
We put the following in our webpack config
|
Thank you very much. I spend 4 hours finding a decision. Its really works. I just replace by step 2 the original file (exceljs.min.js). Greet day. |
Duplicate of #512 I still find |
manifest v3, it worked, thank you! |
The easiest workaround for us: Our build takes care of polyfills by itself anyway. Thanks @notclive. |
I managed to fix this by simply importing import 'regenerator-runtime';
import { Table, Workbook, Worksheet } from 'exceljs'; And as others have mentioned, adding Edit: maybe it's safer to first add |
this worked for me: |
Hi, https://github.com/Stuk/jszip/blob/2ceb998e29d4171b4f3f2ecab1a2195c696543c0/dist/jszip.js#L11404 The |
Since @Siemienik What do you think? I can give it a try, but I would appreciate some guidance if there's an interest in this. |
I think this issue has been fixed in the 4.4.0 release. https://www.unpkg.com/browse/[email protected]/dist/exceljs.bare.js |
Hi, I am getting following error from excel.min.js for using new Function(). I am not able to use exceljs. Please help
exceljs.min.js:9 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':
The text was updated successfully, but these errors were encountered: