Last active
December 21, 2015 11:59
-
-
Save sandyxu/6302517 to your computer and use it in GitHub Desktop.
防止浏览器存在url跳转漏洞被利用钓鱼
This file contains hidden or 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
# 来自wooyun的白帽子安全 http://www.wooyun.org/bugs/subtype-65/page/1 | |
# 通过params[:continue] 的安全url进行跳转 | |
def safe_continue_redirect(continue = params[:continue]) | |
if continue | |
redirect_to safe_continue_url(continue) | |
else | |
redirect_to(root_path) | |
end | |
end | |
# 安全的URL地址,防止跳转欺骗 | |
def safe_continue_url(url) | |
uri = URI(url) | |
host = uri.host | |
setting = Settings.hostname | |
if host.nil? or host == setting or host.end_with?(".#{setting}") | |
url | |
else | |
root_url | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment