-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
添加步骤
- Loading branch information
Showing
1 changed file
with
34 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,34 @@ | ||
anti-dns-hijecking | ||
# anti-dns-hijecking | ||
|
||
目前从部分用户反映,我们的移动终端页面受到dns劫持并插入广告的情况,此工具能够查找被插入的代码,并把劫持方式上报 | ||
|
||
--- | ||
|
||
## 问题 | ||
|
||
目前我们面临的运营商页面劫持主要是以下两种形式: | ||
1. 修改我们的页面HTML源码,直接插入广告dom元素(以iframe div 等常见) | ||
2. 修改页面HTML源代码,插入可以动态执行的javascript脚本程序,程序在用户侧(浏览器/App内置浏览容器)执行后,生成广告内容 | ||
|
||
## 思路 | ||
|
||
针对上述形式的页面篡改劫持,根据其产生的原理和时机,解决途径有两类: | ||
1. 事前预防,目前我们传输最终可见内容主要采用HTTP协议(HTML),通过调整网络传输协议(二进制协议)或内容加载方式(HTML文件先下载再展示;App通过JSON获取专题内容,native显示)可以彻底解决,但涉及资源投入较多,成本略高 | ||
|
||
2. 事后修正,在用户终端展示的时候检测页面纂改情况,并作修复。目前已经在进行demo开发的解决方案有: | ||
HTML关键内容自定义样式修饰,页面加载(onLoad)之后周期性检测并剔除未被修饰的页面元素。考虑到客户端性能,若干个周期后检测结束 | ||
页面结构(DOM)白名单,对每个dom元素增加特定属性标签,周期便利整个页面,剔除dom tree上的非法节点。该方案可以彻底解决页面纂改问题,但是对页面性能有影响 | ||
|
||
## 结论 | ||
综合各方案的优缺点,优先考虑事后修正的技术实现,并协调App开发资源进行事前预防的技术排期 | ||
|
||
## 配置 | ||
1. git clone https://github.com/lexuslin/anti-dns-hijecking.git 下载代码 | ||
2. bower install 下载依赖的JS库,保存在src/component目录下 | ||
3. npm install 加载依赖 | ||
4. 修改config.json,name是当前项目名称,为了减少项目名称冲突的几率,建议加上当前日期如: dns_ggk_20141224 | ||
5. 把需要加入反劫持代码的html页面放在src目录下,执行grunt,自动添加反劫持代码(具体是为每个dom元素添加一个特殊的属性anti-hijecking,在</body>标签前加入反劫持相关JS) | ||
|
||
|
||
|
||
|