我有一个页面,它从查询字符串中的参数重定向到url,如:
page.html中?的redirectUrl =的index.html
在页面内我有这样的代码:
window.localtion.href = redirectUrl;
通过参数使用重定向url是必须的.该页面包含安全的敏感数据.有人可以用 javascript制作网址:
?page.html中的redirectUrl = JavaScript的:警报(的document.getElementById( “密码”)值)
安全数据可能被盗.
page.html中?的redirectUrl =的index.html
在页面内我有这样的代码:
window.localtion.href = redirectUrl;
通过参数使用重定向url是必须的.该页面包含安全的敏感数据.有人可以用 javascript制作网址:
?page.html中的redirectUrl = JavaScript的:警报(的document.getElementById( “密码”)值)
安全数据可能被盗.
如何防止绕过javascript代码到window.localtion.href?
解决方法
您可以尝试将URL放在
anchor element中并检查协议:
var anchor = document.createElement("a"); anchor.href = redirectUrl; if(anchor.protocol != "javascript:") { window.localtion.href = redirectUrl; }