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

跟钓鱼说nO #9

Open
headwindz opened this issue Jan 18, 2018 · 0 comments
Open

跟钓鱼说nO #9

headwindz opened this issue Jan 18, 2018 · 0 comments

Comments

@headwindz
Copy link
Owner

介绍

在日常的应用中,我们经常会在链接在加上一个回调地址用于跳转。例如我的应用是
http://www.taobao.com,假设我在没登录的情况下访问了 http://www.taobao.com/shoppingcart 。这时候会跳转到 http://www.taobao.com/login?url=/shoppingcart 。登录完后再跳转到_/shoppingcart_的地址。这里有个漏洞就是可能会有人恶意发送钓鱼链接。例如我可以给你发给链接
http://www.taobao.com/login?url=http://www.baidu.com 。如果不对url参数进行验证的话就会被导向恶意网站。

方法

如果是只能跳转到内部相对地址的话,可以采取/验证。

let urlQuery = getQuery(); //假设获取到url的参数了
let returnUrl = '/dashboard'; // 默认的返回地址
if(urlQuery.startsWith('/')) { // /开头是相对路径
    returnUrl = urlQuery;
}
return returnUrl;

这里会有个问题,如果url是//开头的话, 会被当成是绝对路径

//假设我当前在https://www.baidu.com

document.location='/taobao.com'; // 会跳转到 https://www.baidu.com/taobao.com
document.location='//taobao.com'; // 则会跳转到 https://taobao.com

所以这里需要对//进行下处理

let path = require('path');
let urlQuery = path.normalize(getQuery()); //假设获取到url的参数了
let returnUrl = '/dashboard'; // 默认的返回地址
if(urlQuery.startsWith('/')) { // /开头是相对路径
    returnUrl = urlQuery;
}
return returnUrl;
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

1 participant