diff --git a/api/current.txt b/api/current.txt index 10b57dd4f0c4c..f96bd595edd89 100644 --- a/api/current.txt +++ b/api/current.txt @@ -58002,7 +58002,7 @@ package android.webkit { method @Deprecated public abstract void removeSessionCookie(); method public abstract void removeSessionCookies(@Nullable android.webkit.ValueCallback); method public abstract void setAcceptCookie(boolean); - method public static void setAcceptFileSchemeCookies(boolean); + method @Deprecated public static void setAcceptFileSchemeCookies(boolean); method public abstract void setAcceptThirdPartyCookies(android.webkit.WebView, boolean); method public abstract void setCookie(String, String); method public abstract void setCookie(String, String, @Nullable android.webkit.ValueCallback); @@ -58367,8 +58367,8 @@ package android.webkit { method public abstract String getUserAgentString(); method public abstract void setAllowContentAccess(boolean); method public abstract void setAllowFileAccess(boolean); - method public abstract void setAllowFileAccessFromFileURLs(boolean); - method public abstract void setAllowUniversalAccessFromFileURLs(boolean); + method @Deprecated public abstract void setAllowFileAccessFromFileURLs(boolean); + method @Deprecated public abstract void setAllowUniversalAccessFromFileURLs(boolean); method public abstract void setAppCacheEnabled(boolean); method @Deprecated public abstract void setAppCacheMaxSize(long); method public abstract void setAppCachePath(String); diff --git a/core/java/android/webkit/CookieManager.java b/core/java/android/webkit/CookieManager.java index ff80ef7b2e944..f62a28ec0d074 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. *

- * Note that calls to this method will have no effect if made after a - * {@link WebView} or CookieManager instance has been created. + * 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). + *

+ * Loading content via {@code file://} URLs is generally discouraged. See the note in + * {@link WebSettings#setAllowFileAccess}. + * Using + * androidx.webkit.WebViewAssetLoader 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. + *

+ * 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 + * + * androidx.webkit.WebViewAssetLoader 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 53541f786da0a..35dd5760d5abf 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 any 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. + *

+ * Don't 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. + *

+ * Loading content via {@code file://} URLs is generally discouraged. See the note in + * {@link #setAllowFileAccess}. *

* 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. + * {@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 + * @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 + * + * androidx.webkit.WebViewAssetLoader 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. *

- * 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. + * Don't 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. + *

+ * Loading content via {@code file://} URLs is generally discouraged. See the note in + * {@link #setAllowFileAccess}. + *

+ * 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 + * + * androidx.webkit.WebViewAssetLoader to load file content securely. */ + @Deprecated public abstract void setAllowFileAccessFromFileURLs(boolean flag); /**