wordpress评论者链接网址重定向跳转设置后出现的HTTP响应拆分漏洞
其实这个HTTP响应拆分漏洞是‘360安全网站检测’检测出来的。该漏洞的危害:攻击者可能注入自定义HTTP头。例如,攻击者可以注入会话cookie或HTML代码。这可能会进行类似的XSS(跨站点脚本)或会话固定漏洞。
解决方案:限制用户输入的CR和LF,或者对CR和LF字符正确编码后再输出,以防止注入自定义HTTP头。
出现这个问题,是因为添加了wordpress评论外链跳转功能,站外网址的跳转是使用“/?r=”直接跳转,没有使用中间跳转页,而且代码过滤不严格。
关于评论者链接网址重定向的方法网上很多,代码是这样的:
- //评论者链接的网址重定向跳转
- add_filter('get_comment_author_link', 'add_redirect_comment_link', 5);
- add_filter('comment_text', 'add_redirect_comment_link', 99);
- function add_redirect_comment_link($text = ''){
- $text=str_replace('href="', 'href="'.get_option('home').'/?r=', $text);
- $text=str_replace("href='", "href='".get_option('home')."/?r=", $text);
- return $text;
- }
- add_action('init', 'redirect_comment_link');
- function redirect_comment_link(){
- $redirect = $_GET['r'];
- $host = $_SERVER['HTTP_HOST'];
- if($redirect){
- if(strpos($_SERVER['HTTP_REFERER'],get_option('home')) !== false){
- header("Location: $redirect#from:$host");
- exit;
- }
- else {
- header("Location: $redirect#from:$host");
- exit;
- }
- }
- }
解决参数r的HTTP响应拆分漏洞:
$redirect = $_GET['r'];后面必须过滤CR和LF字符,在该代码后面加上以下代码:
- $redirect = trim(str_replace("\r","",str_replace("\r\n","",strip_tags(str_replace("'","",str_replace("\n", "", str_replace(" ","",str_replace("\t","",trim($redirect))))),""))));
没有评论:
发表评论