diff options
| author | Hazem Ashmawy <hazems@google.com> | 2020-02-20 19:39:27 +0000 |
|---|---|---|
| committer | Hazem Ashmawy <hazems@google.com> | 2020-03-05 19:56:07 +0000 |
| commit | 7536c2bda0e4683d5d39ed43f29761709e91f4e0 (patch) | |
| tree | c935c6b353dc0de20372a775f812085fa034d532 /core/java/android | |
| parent | f71d1dc5ccbfce9815f7e87d1aae62ad91d90095 (diff) | |
Android WebView: Deprecate unsafe file urls APIs
Deprecate unsafe:
- WebSettings#setAllowUniversalAccessFromFileURLs
- WebSettings#setAllowFileAccessFromFileURLs
- CookieManager#setAcceptFileSchemeCookies
And direct the users to use WebViewAssetLoader instead.
Bug: 148841999
Test: m offline-sdk-docs -j20
Change-Id: I607d1343cb2aa5baead49ceff6dbac4a4474009c
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/webkit/CookieManager.java | 27 | ||||
| -rw-r--r-- | core/java/android/webkit/WebSettings.java | 75 |
2 files changed, 64 insertions, 38 deletions
diff --git a/core/java/android/webkit/CookieManager.java b/core/java/android/webkit/CookieManager.java index ff80ef7b2e94..f62a28ec0d07 100644 --- a/core/java/android/webkit/CookieManager.java +++ b/core/java/android/webkit/CookieManager.java @@ -268,17 +268,28 @@ public abstract class CookieManager { protected abstract boolean allowFileSchemeCookiesImpl(); /** - * Sets whether the application's {@link WebView} instances should send and - * accept cookies for file scheme URLs. - * Use of cookies with file scheme URLs is potentially insecure and turned - * off by default. - * Do not use this feature unless you can be sure that no unintentional - * sharing of cookie data can take place. + * Sets whether the application's {@link WebView} instances should send and accept cookies for + * file scheme URLs. + * <p> + * Use of cookies with file scheme URLs is potentially insecure and turned off by default. All + * {@code file://} URLs share all their cookies, which may lead to leaking private app cookies + * (ex. any malicious file can access cookies previously set by other (trusted) files). + * <p class="note"> + * Loading content via {@code file://} URLs is generally discouraged. See the note in + * {@link WebSettings#setAllowFileAccess}. + * Using <a href="{@docRoot}reference/androidx/webkit/WebViewAssetLoader.html"> + * androidx.webkit.WebViewAssetLoader</a> to load files over {@code http(s)://} URLs allows + * the standard web security model to be used for setting and sharing cookies for local files. * <p> - * Note that calls to this method will have no effect if made after a - * {@link WebView} or CookieManager instance has been created. + * Note that calls to this method will have no effect if made after calling other + * {@link CookieManager} APIs. + * + * @deprecated This setting is not secure, please use + * <a href="{@docRoot}reference/androidx/webkit/WebViewAssetLoader.html"> + * androidx.webkit.WebViewAssetLoader</a> instead. */ // Static for backward compatibility. + @Deprecated public static void setAcceptFileSchemeCookies(boolean accept) { getInstance().setAcceptFileSchemeCookiesImpl(accept); } diff --git a/core/java/android/webkit/WebSettings.java b/core/java/android/webkit/WebSettings.java index 53541f786da0..35dd5760d5ab 100644 --- a/core/java/android/webkit/WebSettings.java +++ b/core/java/android/webkit/WebSettings.java @@ -983,48 +983,63 @@ public abstract class WebSettings { public abstract void setJavaScriptEnabled(boolean flag); /** - * Sets whether JavaScript running in the context of a file scheme URL - * should be allowed to access content from any origin. This includes - * access to content from other file scheme URLs. See - * {@link #setAllowFileAccessFromFileURLs}. To enable the most restrictive, - * and therefore secure policy, this setting should be disabled. - * Note that this setting affects only JavaScript access to file scheme - * resources. Other access to such resources, for example, from image HTML - * elements, is unaffected. To prevent possible violation of same domain policy - * when targeting {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH_MR1} and earlier, - * you should explicitly set this value to {@code false}. + * Sets whether cross-origin requests in the context of a file scheme URL should be allowed to + * access content from <i>any</i> origin. This includes access to content from other file + * scheme URLs or web contexts. Note that some access such as image HTML elements doesn't + * follow same-origin rules and isn't affected by this setting. + * <p> + * <b>Don't</b> enable this setting if you open files that may be created or altered by + * external sources. Enabling this setting allows malicious scripts loaded in a {@code file://} + * context to launch cross-site scripting attacks, either accessing arbitrary local files + * including WebView cookies, app private data or even credentials used on arbitrary web sites. + * <p class="note"> + * Loading content via {@code file://} URLs is generally discouraged. See the note in + * {@link #setAllowFileAccess}. * <p> * The default value is {@code true} for apps targeting - * {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH_MR1} and below, - * and {@code false} when targeting {@link android.os.Build.VERSION_CODES#JELLY_BEAN} - * and above. - * - * @param flag whether JavaScript running in the context of a file scheme - * URL should be allowed to access content from any origin + * {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH_MR1} and below, and {@code false} + * when targeting {@link android.os.Build.VERSION_CODES#JELLY_BEAN} and above. To prevent + * possible violation of same domain policy when targeting + * {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH_MR1} and earlier, you should + * explicitly set this value to {@code false}. + * + * @param flag whether JavaScript running in the context of a file scheme URL should be allowed + * to access content from any origin + * @deprecated This setting is not secure, please use + * <a href="{@docRoot}reference/androidx/webkit/WebViewAssetLoader.html"> + * androidx.webkit.WebViewAssetLoader</a> to load file content securely. */ + @Deprecated public abstract void setAllowUniversalAccessFromFileURLs(boolean flag); /** - * Sets whether JavaScript running in the context of a file scheme URL - * should be allowed to access content from other file scheme URLs. To - * enable the most restrictive, and therefore secure, policy this setting - * should be disabled. Note that the value of this setting is ignored if - * the value of {@link #getAllowUniversalAccessFromFileURLs} is {@code true}. - * Note too, that this setting affects only JavaScript access to file scheme - * resources. Other access to such resources, for example, from image HTML - * elements, is unaffected. To prevent possible violation of same domain policy - * when targeting {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH_MR1} and earlier, - * you should explicitly set this value to {@code false}. + * Sets whether cross-origin requests in the context of a file scheme URL should be allowed to + * access content from other file scheme URLs. Note that some accesses such as image HTML + * elements don't follow same-origin rules and aren't affected by this setting. * <p> - * The default value is {@code true} for apps targeting - * {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH_MR1} and below, - * and {@code false} when targeting {@link android.os.Build.VERSION_CODES#JELLY_BEAN} - * and above. + * <b>Don't</b> enable this setting if you open files that may be created or altered by + * external sources. Enabling this setting allows malicious scripts loaded in a {@code file://} + * context to access arbitrary local files including WebView cookies and app private data. + * <p class="note"> + * Loading content via {@code file://} URLs is generally discouraged. See the note in + * {@link #setAllowFileAccess}. + * <p> + * Note that the value of this setting is ignored if the value of + * {@link #getAllowUniversalAccessFromFileURLs} is {@code true}. The default value is + * {@code true} for apps targeting {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH_MR1} + * and below, and {@code false} when targeting {@link android.os.Build.VERSION_CODES#JELLY_BEAN} + * and above. To prevent possible violation of same domain policy when targeting + * {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH_MR1} and earlier, you should + * explicitly set this value to {@code false}. * * @param flag whether JavaScript running in the context of a file scheme * URL should be allowed to access content from other file * scheme URLs + * @deprecated This setting is not secure, please use + * <a href="{@docRoot}reference/androidx/webkit/WebViewAssetLoader.html"> + * androidx.webkit.WebViewAssetLoader</a> to load file content securely. */ + @Deprecated public abstract void setAllowFileAccessFromFileURLs(boolean flag); /** |
