简体   繁体   English

Angular:拒绝将字符串评估为 JavaScript,因为“不安全评估”

[英]Angular: Refused to evaluate a string as JavaScript because 'unsafe-eval'

In my application a blob fetched by means of a API-call is passed on to a custom npm-package that will show the blob on the screen (it's an image).在我的应用程序中,通过 API 调用获取的 blob 被传递到自定义 npm 包,该包将在屏幕上显示 blob(它是图像)。 Locally it works.在本地它有效。 Only not on the development server.只是不在开发服务器上。

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' 'unsafe-inline' https://www.example.com 'unsafe-inline' https://www.anotherexample.com".

A plane application has be made that fetches the blob and uses the same custom npm-package.已经制作了一个平面应用程序来获取 blob 并使用相同的自定义 npm 包。 The problem seem to be with Angular or better said with my settings.问题似乎与 Angular 或我的设置有关。 The settings locally are the same and its not clear what the problem is.本地的设置是一样的,不清楚是什么问题。

The error is not originated in Angular, the problem is your Content-Security-Policy (CSP).该错误并非源自 Angular,问题在于您的 Content-Security-Policy (CSP)。 Your CSP is either defined in the index.html file as a meta tag in the header section, or set as a header on your server.您的 CSP 在index.html文件中定义为header部分中的meta标记,或者在您的服务器上设置为 header。

You could simply add 'unsafe-eval' to the CSP, but this is very risky in terms of security.您可以简单地将“unsafe-eval”添加到 CSP,但这在安全性方面是非常危险的。 To me, it seems like the library you are using here uses eval at some place, which is bad and should be avoided.对我来说,您在这里使用的库似乎在某个地方使用了eval ,这很糟糕,应该避免。

With development server, do you mean it is actually deployed, or the local server that starts with ng serve ?使用开发服务器,您的意思是它实际上已部署,还是以ng serve开头的本地服务器?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 拒绝将字符串评估为 JavaScript,因为“unsafe-eval”不是允许的来源 - Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source Chrome 扩展程序“拒绝将字符串评估为 JavaScript,因为 'unsafe-eval' - Chrome extension "Refused to evaluate a string as JavaScript because 'unsafe-eval' Chrome 扩展程序拒绝将字符串评估为 JavaScript,因为 emscripten 生成的文件中的“unsafe-eval” - Chrome extension refused to evaluate a string as JavaScript because 'unsafe-eval' in emscripten generated file (带有服务器的电子)未捕获的 EvalError:拒绝将字符串评估为 JavaScript,因为“unsafe-eval”不是允许的脚本源 - (electron with server) Uncaught EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script 拒绝将字符串评估为 JavaScript,因为“unsafe-eval”不是脚本内容安全策略指令的允许来源:default-src self - Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script Content Security Policy directive:default-src self Chrome 扩展中的 Javascript Tensorflow 由于“不安全评估”而无法正常工作 - Javascript Tensorflow in Chrome Extension not working due to 'unsafe-eval' chrome 扩展上的“不安全评估” - 'unsafe-eval' on chrome extension Google Charts unsafe-eval - Google Charts unsafe-eval 内容安全政策'unsafe-eval':如何避免在JavaScript jquery.timer.js中使用eval()? - Content Security Policy 'unsafe-eval': How to avoid using eval() in javascript jquery.timer.js? 'unsafe-eval' 不是允许的脚本来源 - 'unsafe-eval' is not an allowed source of script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM