2017-08-04 210 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