4

我試圖加載谷歌地圖和firebaseio的許多方面都沒有成功: 這是我現在有:phonegap + ionic使用Content-Security-Policy加載maps.googleapis.com,如何?

<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com; 
    script-src 'self' https://maps.googleapis.com/* 'unsafe-inline' 'unsafe-eval'; 
    style-src 'self' 'unsafe-inline';"> 

,我也得到:

Refused to load the script 'https://maps.googleapis.com/maps/api/js?libraries=places' because it violates the following Content Security Policy directive: "script-src 'self' https://maps.googleapis.com/* 'unsafe-inline' 'unsafe-eval'". 

Refused to load the script 'https://test.firebaseio.com/.lp?start=t&ser=79549912&cb=1&v=5' because it violates the following Content Security Policy directive: "script-src 'self' https://maps.googleapis.com/* 'unsafe-inline' 'unsafe-eval'". 

任何想法我做錯了什麼?

+0

試圖'的「https://maps.googleapis。 com/*''而不是'https:// maps.googleapis.com/*' – Sushant

+0

@Sushant,nope。我得到'內容安全策略指令'script-src'的源列表包含一個無效的來源:''https://maps.googleapis.com/*''。它會被忽略。 ' – Patrioticcow

+0

fwiw scheme:// host/*不是有效的CSP模式。 'https:// maps.googleapis.com'是你想要完成的。 – oreoshake

回答

19

這並獲得成功:)

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

和谷歌的腳本<script src="https://maps-api-ssl.google.com/maps/api/js?libraries=places"></script>

1

發展不受任何限制地使用:

<meta http-equiv="Content-Security-Policy" 
     content="default-src * 'unsafe-eval' 'unsafe-inline'"> 
+0

您的解決方案僅適用於開發**,不適用於生產。 XSS不是一個玩笑。 – TPAKTOPA

相關問題