说点废话,这一切都是为了那个养眼的安全系数,一步到位。之前只设置了评论链接重定向,被检测到任意跳转漏洞,然后加了个跳转页面,但只是简单加个跳转页面的话就又会新增一个跨站漏洞,所以呢也得顺便堵了这个问题才是。这篇文章不算是新文章,只是把以前的3篇文章结合到一起并且做了简化。

添加以下代码到functions.php文件

//评论者链接的网址重定向跳转   
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="', 'target="_blank" href="'.get_option('home').'/go.php?url=', $text);   
$text=str_replace("href='", "target='_blank'href='".get_option('home')."/go.php?url=", $text);   
return $text;   
}   
add_action('init', 'redirect_comment_link');   
function redirect_comment_link(){   
$redirect = $_GET['url'];   
$redirect = trim(str_replace("\r","",str_replace("\r\n","",strip_tags(str_replace("'","",str_replace("\n", "", str_replace(" ","",str_replace("\t","",trim($redirect))))),""))));   
$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;   
}   
}   
}  

然后上传go.php文件和safe.php文件到博客程序根目录。(文章结尾提供下载)
其中go.php是跳转页面,safe.php是防护脚本。
关于跳转:
方案一是直接跳转,下载包里有。
方案二是带有跳转页面,如本博客就是,这里提供了两个风格,下载包里有,请选取一个即可,也可自己制作。
最后附加安全小提示:为了更进一步避免被检测到有跨站漏洞请在404模板的最开头添加下面一句代码,(前提是上传了我提供的safe.php)
<?require_once('safe.php');?>
go.php和safe.php包下载:
http://pan.baidu.com/share/link?shareid=453686&uk=2231524802


最后修改:2019 年 08 月 06 日
如果觉得我的文章对你有用,请随意赞赏