[英]Content Security Policy in AWS
我遇到一個奇怪的錯誤,我無法弄清楚。 嘗試將小項目部署到AWS Elastic Beanstalk實例時,我遇到許多CSP錯誤。 即使我的項目中除了一個小型的Node.js后端來處理某些路由之外,不含任何JavaScript,但似乎仍在執行內聯腳本。 我得到的錯誤是這樣的:
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 http-equiv="Content-Security-Policy" content="default-src * 'unsafe-inline' 'unsafe-eval' data: blob:;">
有人可以幫我弄清楚我要去哪里錯嗎?
謝謝
希望對您有幫助。
我在Beanstalk上使用Laravel遇到了相同的錯誤,這是由於我的php應用程序內部錯誤,而不是“內容安全策略”。
因此,您的應用程序中顯示頁面的任何錯誤都可能產生該錯誤。 您可以在EC2的“ / var / log / containers / YourContainerName”中查看日志文件並解決問題。 對我來說,這是“ laravel存儲文件夾”的錯誤權限。
另外,如果負載均衡,亞馬遜上也會有類似的問題,這可能會有所幫助。 https://forums.aws.amazon.com/thread.jspa?messageID=783941
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.