Skip to content

Commit cd16fcb

Browse files
committed
阻止网络爬虫在user.login/user.reg/link.tpl之间进行循环重定向
1 parent 2a92935 commit cd16fcb

4 files changed

Lines changed: 19 additions & 4 deletions

File tree

‎src/page/link/tpl.php‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
<?php
2+
$url = trim(code::b64d($_GET['url64']));
3+
if (preg_match('/^user\.(?:login|reg)\.[^?]*\?u=user\.(?:login|reg)\./', (string)$url)) {
4+
header('HTTP/1.1 400 Bad Request');
5+
die('循环重定向');
6+
}
7+
28
$tpl = str::word($PAGE->ext[0]);
39

410
// 填充POST以触发CSRF保护
@@ -8,8 +14,6 @@
814
// 只对CSRF请求拒绝设置Cookie,以便主题修改不生效。
915
//require SUB_DIR.'/csrf_protect.php';
1016

11-
$url = trim(code::b64d($_GET['url64']));
12-
1317
if (!Page::isCsrfPost() && $PAGE->isRegTpl($tpl)) {
1418
page::setCookie('tpl', $tpl, 3600 * 24 * 3650);
1519
}

‎src/page/user/login.php‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
<?php
22
try {
3-
$tpl = $PAGE->start();
43
$u = $_GET['u'];
54
if ($u == '') $u = $_GET['url'];
5+
if (preg_match('/^user\.(?:login|reg)\./', (string)$u)) {
6+
header('HTTP/1.1 400 Bad Request');
7+
die('循环重定向');
8+
}
9+
10+
$tpl = $PAGE->start();
611
if ($u == '') $u = 'index.index.' . $PAGE->bid;
712
$tpl->assign('u', $u);
813
if (!$_POST['go']) {

‎src/page/user/reg.php‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
<?php
22
try {
3-
$tpl = $PAGE->start();
43
$u = $_GET['u'];
4+
if (preg_match('/^user\.(?:login|reg)\./', (string)$u)) {
5+
header('HTTP/1.1 400 Bad Request');
6+
die('循环重定向');
7+
}
8+
9+
$tpl = $PAGE->start();
510
if ($u == '') $u = 'index.index.' . $PAGE->bid;
611
$tpl->assign('u', $u);
712

‎src/robots.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Disallow: /q.php/user.login*
33
Disallow: /q.php/user.reg*
44
Disallow: /q.php/addin.chat*
55
Disallow: /q.php/addin.speedtest*
6+
Disallow: /q.php/link.tpl*
67
Allow: /q.php/addin*
78
Allow: /q.php/admin*
89
Allow: /q.php/api*

0 commit comments

Comments
 (0)