arnaucube
arnaucube/commonroutesServerPublic Self-hosted repository
commonroutesServer/www/plugins/cordova-plugin-whitelist/doc/zh/README.md
www/plugins/cordova-plugin-whitelist/doc/zh/README.mdRaw
  1<!--
  2# license: Licensed to the Apache Software Foundation (ASF) under one
  3#         or more contributor license agreements.  See the NOTICE file
  4#         distributed with this work for additional information
  5#         regarding copyright ownership.  The ASF licenses this file
  6#         to you under the Apache License, Version 2.0 (the
  7#         "License"); you may not use this file except in compliance
  8#         with the License.  You may obtain a copy of the License at
  9#
 10#           http://www.apache.org/licenses/LICENSE-2.0
 11#
 12#         Unless required by applicable law or agreed to in writing,
 13#         software distributed under the License is distributed on an
 14#         "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15#         KIND, either express or implied.  See the License for the
 16#         specific language governing permissions and limitations
 17#         under the License.
 18-->
 19
 20# cordova-plugin-whitelist
 21
 22這個外掛程式實現一個用於導航在科爾多瓦 4.0 應用程式 web 視圖的白名單策略
 23
 24## 支援的科爾多瓦平臺
 25
 26  * Android 4.0.0 或以上
 27  * iOS 4.0.0 或以上
 28
 29## 導航白名單
 30
 31控制 web 視圖本身可以導航到的 Url。適用于頂級導航只。
 32
 33怪癖: 在 Android 上它也適用于 iframe 的非-結計畫。
 34
 35預設情況下,只有到`file://` Url 導航允許。若要允許其他其他 Url,必須將`<allow-navigation>`標籤添加到您的`config.xml`:
 36
 37    <!-- Allow links to example.com -->
 38    <allow-navigation href="http://example.com/*" />
 39    
 40    <!-- Wildcards are allowed for the protocol, as a prefix
 41         to the host, or as a suffix to the path -->
 42    <allow-navigation href="*://*.example.com/*" />
 43    
 44    <!-- A wildcard can be used to whitelist the entire network,
 45         over HTTP and HTTPS.
 46         *NOT RECOMMENDED* -->
 47    <allow-navigation href="*" />
 48    
 49    <!-- The above is equivalent to these three declarations -->
 50    <allow-navigation href="http://*/*" />
 51    <allow-navigation href="https://*/*" />
 52    <allow-navigation href="data:*" />
 53    
 54
 55## 科爾多瓦-外掛程式-白名單
 56
 57控制應用程式允許讓系統打開的 Url。 預設情況下,沒有外部 Url 允許。
 58
 59在 android 系統,這相當於發送類型 BROWSEABLE 的意圖。
 60
 61此白名單並不適用于只超連結和對`window.open ()`調用的外掛程式.
 62
 63在`config.xml`中添加`<allow-intent>`標籤,像這樣:
 64
 65    <!-- Allow links to web pages to open in a browser -->
 66    <allow-intent href="http://*/*" />
 67    <allow-intent href="https://*/*" />
 68    
 69    <!-- Allow links to example.com to open in a browser -->
 70    <allow-intent href="http://example.com/*" />
 71    
 72    <!-- Wildcards are allowed for the protocol, as a prefix
 73         to the host, or as a suffix to the path -->
 74    <allow-intent href="*://*.example.com/*" />
 75    
 76    <!-- Allow SMS links to open messaging app -->
 77    <allow-intent href="sms:*" />
 78    
 79    <!-- Allow tel: links to open the dialer -->
 80    <allow-intent href="tel:*" />
 81    
 82    <!-- Allow geo: links to open maps -->
 83    <allow-intent href="geo:*" />
 84    
 85    <!-- Allow all unrecognized URLs to open installed apps
 86         *NOT RECOMMENDED* -->
 87    <allow-intent href="*" />
 88    
 89
 90## 網路請求白名單
 91
 92網路請求的控制項 (圖像,XHRs 等) 允許 (通過科爾多瓦本機掛鉤)。
 93
 94注意: 我們建議你使用內容的安全性原則 (見下文),這是更安全。 此白名單大多是為 webviews 不支援 CSP 的歷史。
 95
 96在`config.xml`中添加`<access>`標記,像這樣:
 97
 98    <!-- Allow images, xhrs, etc. to google.com -->
 99    <access origin="http://google.com" />
100    <access origin="https://google.com" />
101    
102    <!-- Access to the subdomain maps.google.com -->
103    <access origin="http://maps.google.com" />
104    
105    <!-- Access to all the subdomains on google.com -->
106    <access origin="http://*.google.com" />
107    
108    <!-- Enable requests to content: URLs -->
109    <access origin="content:///*" />
110    
111    <!-- Don't block any requests -->
112    <access origin="*" />
113    
114
115沒有任何`<access>`標籤,只到`file://` Url 允許請求。 但是,預設的科爾多瓦應用程式包括`<access origin="*">` ,預設情況。
116
117怪癖: Android 還允許對 HTTPs://ssl.gstatic.com/accessibility/javascript/android/ 請求預設情況下,因為這是對講正常所需。
118
119### 內容安全政策
120
121網路請求的控制項 (圖像,XHRs 等) 允許 (通過 web 視圖直接)。
122
123對 Android 和 iOS,網路請求白名單 (見上文) 是不能夠過濾所有類型的請求 (例如`<video>` & Websocket 未被阻止)。 那麼,除了白名單中,你應使用[內容安全性原則](http://content-security-policy.com/) `< 元 >`標記您的所有頁面。
124
125在 android 系統,對 CSP 系統 web 視圖的支援開始奇巧 (但是是上使用 web 視圖人行橫道上的所有版本可用)。
126
127下面是一些示例 CSP 聲明為`.html`頁面:
128
129    <!-- Good default declaration:
130        * gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication
131        * https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly
132        * Disables use of eval() and inline scripts in order to mitigate risk of XSS vulnerabilities. To change this:
133            * Enable inline JS: add 'unsafe-inline' to default-src
134            * Enable eval(): add 'unsafe-eval' to default-src
135    -->
136    <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com; style-src 'self' 'unsafe-inline'; media-src *">
137    
138    <!-- Allow requests to foo.com -->
139    <meta http-equiv="Content-Security-Policy" content="default-src 'self' foo.com">
140    
141    <!-- Enable all requests, inline styles, and eval() -->
142    <meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">
143    
144    <!-- Allow XHRs via https only -->
145    <meta http-equiv="Content-Security-Policy" content="default-src 'self' https:">
146    
147    <!-- Allow iframe to https://cordova.apache.org/ -->
148    <meta http-equiv="Content-Security-Policy" content="default-src 'self'; frame-src 'self' https://cordova.apache.org">