2017-08-04 192 views
0

我正面临着一个奇怪的错误,我无法弄清楚。当试图将一个小型项目部署到AWS Elastic Beanstalk实例时,我遇到了一些CSP错误。它似乎在抱怨执行内联脚本,尽管我的项目不包含JavaScript,除了一个小的Node.js后端来处理一些路由。我得到的错误是这样的:AWS内容安全策略

Refused to execute inline script because it violates the following 
Content Security Policy directive: "script-src 
https://d2aafqm3hbgbf6.cloudfront.net 
https://d2q66yyjeovezo.cloudfront.net 
https://d1idiovbex4hy4.cloudfront.net 
https://d3e2aud6m9sl41.cloudfront.net https://phd.aws.amazon.com 
https://resources.console.aws.amazon.com https://signin.aws.amazon.com 
*.signin.aws.amazon.com https://d36cz9buwru1tt.cloudfront.net 
https://media.amazonwebservices.com 'self'". Either the 'unsafe-inline' 
keyword, a hash ('sha256- 
WkLxG82JrIV0IxhYdEMt3pgYi6ZRYB9ZAj35iFKh8N8='), or a nonce 
('nonce-...') is required to enable inline execution. 

我试图CSP头添加到我的两个Node.js的后端和HTML文件它所服务的所有请求。

app.use(function(req, res, next){ 
    res.header("Content-Security-Policy", "default-src * 'unsafe-inline' 
    'unsafe-eval' data: blob:;"); 
    next(); 
}) 

Meta标记:

<meta http-equiv="Content-Security-Policy" content="default-src * 'unsafe-inline' 'unsafe-eval' data: blob:;"> 

有人可以请帮我找出我要去的地方错了吗?

谢谢

回答

0

我希望它可以帮助你。

我在Beanstalk上遇到了与Laravel完全相同的错误,经过大量时间后,我意识到错误与我的应用的“内容安全策略”无关。

即使你在一个index.php文件中做了一个简单的phpinfo(),但是有一个错字,你会在浏览器中看到“Content Security Policy”错误。

因此,在您的应用中发生的任何显示您的着陆页的错误都可能产生错误。解决方案是在EC2的“/ var/log/containers/YourContainerName”中查看日志文件并解决问题。对我来说,由于Laravel需要对该目录进行适当的许可,所以这只是“laravel storage folder”的错误许可。

另外,根据亚马逊上的这个类似问题,如果你做负载均衡,复制负载平衡器的公共DNS名称并粘贴到你的url中,将解决这个问题。我还没有尝试过。 https://forums.aws.amazon.com/thread.jspa?messageID=783941