Skip to content

Commit 7c4bd50

Browse files
committed
Java: add AssetLoader example to WebView file access documentation
1 parent 5ac1e01 commit 7c4bd50

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

java/ql/src/Security/CWE/CWE-200/AndroidWebViewSettingsFileAccess.qhelp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@
3838

3939
<sample src="WebViewFileAccessSafe.java"/>
4040

41+
<p>
42+
In the following example, an asset loader is configured so that assets can
43+
be access over <code>https</code>, and not require file system access.
44+
</p>
45+
46+
<sample src="AssetLoaderExample.java"/>
4147
</example>
4248

4349
<references>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
WebViewAssetLoader loader = new WebViewAssetLoader.Builder()
2+
// Replace the domain with a domain you control, or use the default
3+
// appassets.androidplatform.com
4+
.setDomain("appassets.example.com")
5+
.addPathHandler("/resources", new AssetsPathHandler(this))
6+
.build();
7+
8+
webView.setWebViewClient(new WebViewClientCompat() {
9+
@Override
10+
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
11+
return assetLoader.shouldInterceptRequest(request.getUrl());
12+
}
13+
});
14+
15+
webView.loadUrl("https://appassets.example.com/resources/www/index.html");

0 commit comments

Comments
 (0)