cordova-plugin-whitelist
Этот плагин реализует политику белого списка для навигации по веб-вью приложения в Cordova 4.0
:warning: Сообщите о проблемах в трекере проблем Apache Cordova
Установка
Вы можете установить плагин whitelist с помощью Cordova CLI, из npm:
$ cordova plugin add cordova-plugin-whitelist $ cordova prepare
Поддерживаемые платформы Cordova
- Android 4.0.0 или выше
Белый список навигации
Управляет тем, к каким URL-адресам WebView может переходить. Применяется только к переходам верхнего уровня.
Особенности: в Android также применяется к iframe для схем, отличных от http(s).
По умолчанию разрешены переходы только к file:// URL-адресам. Чтобы разрешить другие URL-адреса, необходимо добавить <allow-navigation> теги в ваши config.xml:
<!-- Allow links to example.com -->
<allow-navigation href="http://example.com/*" />
<!-- Wildcards are allowed for the protocol, as a prefix
to the host, or as a suffix to the path -->
<allow-navigation href="*://*.example.com/*" />
<!-- A wildcard can be used to whitelist the entire network,
over HTTP and HTTPS.
*NOT RECOMMENDED* -->
<allow-navigation href="*" />
<!-- The above is equivalent to these three declarations -->
<allow-navigation href="http://*/*" />
<allow-navigation href="https://*/*" />
<allow-navigation href="data:*" />
Белый список намерений
Управляет тем, какие URL-адреса приложение может запросить для открытия системой. По умолчанию внешние URL-адреса не разрешены.
В Android это эквивалентно отправке намерения типа BROWSEABLE.
Этот белый список не применяется к плагинам, только к гиперссылкам и вызовам window.open().
В config.xml, добавьте <allow-intent> теги, например:
<!-- Allow links to web pages to open in a browser -->
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<!-- Allow links to example.com to open in a browser -->
<allow-intent href="http://example.com/*" />
<!-- Wildcards are allowed for the protocol, as a prefix
to the host, or as a suffix to the path -->
<allow-intent href="*://*.example.com/*" />
<!-- Allow SMS links to open messaging app -->
<allow-intent href="sms:*" />
<!-- Allow tel: links to open the dialer -->
<allow-intent href="tel:*" />
<!-- Allow geo: links to open maps -->
<allow-intent href="geo:*" />
<!-- Allow all unrecognized URLs to open installed apps
*NOT RECOMMENDED* -->
<allow-intent href="*" />
Белый список сетевых запросов
Управляет сетевыми запросами (изображения, XHR и т.д.), которые разрешено выполнять (через родные хуки Cordova).
Примечание: мы рекомендуем использовать политику Content Security Policy (см. ниже), которая более безопасна. Этот белый список в основном историчен для веб-вью, которые не поддерживают CSP.
В config.xml, добавьте <access> теги, например:
<!-- Allow images, xhrs, etc. to google.com --> <access origin="http://google.com" /> <access origin="https://google.com" /> <!-- Access to the subdomain maps.google.com --> <access origin="http://maps.google.com" /> <!-- Access to all the subdomains on google.com --> <access origin="http://*.google.com" /> <!-- Enable requests to content: URLs --> <access origin="content:///*" /> <!-- Don't block any requests --> <access origin="*" />
Без <access> тегов разрешены только запросы к file:// URL-адресам. Однако, по умолчанию приложение Cordova включает <access origin="*">.
Примечание: Белый список не может блокировать перенаправления сети от разрешенного удаленного веб-сайта (т. е. http или https) на неразрешенный веб-сайт. Используйте правила CSP для смягчения перенаправлений на неразрешенные веб-сайты для веб-вью, которые поддерживают CSP.
Особенности: Android также по умолчанию разрешает запросы к https://ssl.gstatic.com/accessibility/javascript/android/, так как это необходимо для корректной работы TalkBack.
Политика безопасности контента
Управляет разрешенными сетевыми запросами (изображения, XHR и т.д.) (через веб-вью напрямую).
В Android и iOS белый список сетевых запросов (см. выше) не может отфильтровать все типы запросов (например, <video> и WebSocket не блокируются). Поэтому помимо белого списка вы должны использовать политику Content Security Policy <meta> на всех ваших страницах.
В Android поддержка CSP в системном веб-вью начинается с KitKat (но доступна во всех версиях с использованием Crosswalk WebView).
Вот некоторые примеры объявлений CSP для ваших .html страниц:
<!-- Good default declaration:
* gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication
* https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly
* Disables use of eval() and inline scripts in order to mitigate risk of XSS vulnerabilities. To change this:
* Enable inline JS: add 'unsafe-inline' to default-src
* Enable eval(): add 'unsafe-eval' to default-src
-->
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com; style-src 'self' 'unsafe-inline'; media-src *">
<!-- Allow everything but only from the same origin and foo.com -->
<meta http-equiv="Content-Security-Policy" content="default-src 'self' foo.com">
<!-- This policy allows everything (eg CSS, AJAX, object, frame, media, etc) except that
* CSS only from the same origin and inline styles,
* scripts only from the same origin and inline styles, and eval()
-->
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">
<!-- Allows XHRs only over HTTPS on the same domain. -->
<meta http-equiv="Content-Security-Policy" content="default-src 'self' https:">
<!-- Allow iframe to https://cordova.apache.org/ -->
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; frame-src 'self' https://cordova.apache.org">
© 2012, 2013, 2015 The Apache Software Foundation
Licensed under the Apache License 2.0.
https://cordova.apache.org/docs/en/7.x/reference/cordova-plugin-whitelist/index.html