2016-05-18 38 views
19

我使用的頁面加載驗證碼的加載,但正是因爲一些安全原因阻止內容安全策略:該頁面的設置攔截資源

我面臨的問題:

 
    Content Security Policy: The page's settings blocked the loading 
    of a resource at 
    http://www.google.com/recaptcha/api.js?onload=myCallBack&render=explicit 
    ("script-src http://test.com:8080 'unsafe-inline' 'unsafe-eval'"). 

我有使用以下js和元標記:

<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'"> 
<script src="http://www.google.com/recaptcha/api.js?onload=myCallBack&render=explicit" async defer></script> 
+0

如果我是你,我會嘗試使用服務器端代碼,而不是JavaScript。 JS對CORS和類似的東西不太好。谷歌確實有這個選項.. – Gogol

回答

15

你說你只能從你自己的網站(自我)加載腳本。然後您嘗試從另一個網站(www.google.com)加載腳本,並且因爲您限制了這一點,所以您不能。這就是內容安全策略(CSP)的重點。

您可以在第一行更改爲:

<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval' http://www.google.com"> 

,或者,如果你不明白CSP它可能是值得去除線完全,直到你找到更多關於它。