当前位置:网站首页>WebView whitelist
WebView whitelist
2022-07-28 23:07:00 【ZZ White Dragon】
1. Time to add white list verification
1.loadurl
2.shouldOverRideUrlLoading
3. If you need to classify the security level of the white list , Still need to be in JavascriptInterface Add verification function to ,JavascriptInterface Required in webview.getUrl() To get webview Current domain
Risk warning :
If you do all the above, you may be attacked , For example, there are servers in the white list XSS Loophole , Or the server in the white list is controlled by the attacker , perhaps webview The access did not use a secure transmission channel, resulting in being hijacked by intermediaries , Can inject malicious into the white list trust domain JavaScript
2. Code implementation
private boolean checkDomain(String inputUrl) throws URISyntaxException {
if (!inputUrl.startsWith("http://")&&!inputUrl.startsWith("https://")) {
// Important reminder : It is recommended to use only https Protocol communication , Avoid man in the middle attacks
return false;
}
String[] whiteList=new String[]{"site1.com","site2.com"};
java.net.URI url=new java.net.URI(inputUrl);
String inputDomain=url.getHost();
// extract host, If verification is required Path Can pass url.getPath() obtain
for (String whiteDomain:whiteList)
{
if (inputDomain.endsWith("."+whiteDomain)||inputDomain.equals(whiteDomain)) //www.site1.com app.site2.com
return true;
}
return false;
}
It can be summarized as the following development suggestions :
Do not use indexOf This fuzzy matching function ;
Don't write regular expressions to match ;
Use as much as possible Java Encapsulated method of obtaining domain name , such as java.net.URI, Do not use java.net.URL;
Not only to set a white list for domain names , Also set a white list for the agreement , Commonly used HTTP and HTTPS Two protocols , However, it is strongly recommended not to use HTTP agreement , Because of the mobile Internet era , The threshold for mobile phones to be attacked by intermediaries is very low , Make a malice WiFi You can hijack mobile network traffic ;
The principle of minimizing permissions , Try to use a more accurate domain name or path .
Of course, the above code may not fully meet the needs of business development , Here is just a reference , You can refer to the case of this article to develop a more suitable verification method .
This blog is learned from this blog
https://blog.csdn.net/weixin_33816946/article/details/94607053
边栏推荐
- 轮子七:TCP客户端
- 希捷发布全新RISC-V架构处理器:机械硬盘相关性能暴涨3倍
- 18张图,直观理解神经网络、流形和拓扑
- Written questions and answers of software test interview (software test question bank)
- Summary of core functions of software testing tool Fiddler postman JMeter charlse
- 芯华章宣布完成超2亿A轮融资,全面布局EDA2.0研发
- Date time functions commonly used in MySQL
- Thesis reading (0) - alexnet of classification
- sql优化常用的几种方法
- 18 diagrams, intuitive understanding of neural networks, manifolds and topologies
猜你喜欢

无代码开发平台通讯录导出入门教程

NPM run dev, automatically open the browser after running the project

定了!哪吒S全系产品将于7月31日上市发售
![[physical application] atmospheric absorption loss with matlab code](/img/72/e6ac23012a59ac48a37bcbb068890b.png)
[physical application] atmospheric absorption loss with matlab code

Recurrent neural network (RNN)

MySQL foundation - data query
![[3D target detection] 3dssd (II)](/img/8a/e8927cd868eb99d8880d4f199d8918.png)
[3D target detection] 3dssd (II)

【MySQL系列】 MySQL表的增删改查(进阶)

Target detection notes -yolo
![[C language] implementation of three piece chess games](/img/53/7ee14e604c06fd77d65af29d6d92b8.png)
[C language] implementation of three piece chess games
随机推荐
NPM run dev, automatically open the browser after running the project
Shell script foundation - shell operation principle + variable and array definitions
OSV_ q The size of tensor a (704) must match the size of tensor b (320) at non-singleton dime
Cglib create proxy
Multi activity disaster recovery construction after 713 failure of station B | takintalks share
A new paradigm of distributed deep learning programming: Global tensor
c语言进阶篇:指针(三)
MySQL Basics - Introduction and basic instructions
pg_ Installation and use of RMAN "PostgreSQL"
Yolov5 improvement 5: improve the feature fusion network panet to bifpn
【MySQL系列】 MySQL表的增删改查(进阶)
Paper reading: deep forest / deep forest /gcforest
今年联发科5G芯片出货有望达到5000万套!
Torch.fft.fft 2. () error reporting problem solution
Thesis reading (3) - googlenet of classification
Sqlilabs-3 (entry notes)
1.8tft color screen test code (stm32f407ve)
leetcode101. 对称二叉树
[C language] implementation of three piece chess games
RuntimeError: set_ sizes_ contiguous is not allowed on a Tensor created from .data or .detach().