Harden products batch return_url: reject quotes and nested back

This commit is contained in:
萝卜
2026-03-14 10:41:48 +00:00
parent ffd125f972
commit 722f4a1f44
4 changed files with 173 additions and 2 deletions

View File

@@ -649,7 +649,23 @@ class ProductController extends Controller
return $default;
}
return str_starts_with($candidate, '/admin/products') ? $candidate : $default;
// 作为“批量操作返回地址”,只允许站内相对路径,并且需要稳定可控:
// - 限定前缀(避免跳出 admin/products 语义域)
// - 拒绝引号/尖括号(降低注入风险)
// - 拒绝 nested back=(避免 URL 膨胀/绕过)
if (! str_starts_with($candidate, '/admin/products')) {
return $default;
}
if (preg_match('/["\'<>]/', $candidate)) {
return $default;
}
if (preg_match('/(?:^|[?&])back=/', $candidate)) {
return $default;
}
return $candidate;
}
protected function filters(Request $request): array

View File

@@ -621,7 +621,23 @@ class ProductController extends Controller
return $default;
}
return str_starts_with($candidate, '/merchant-admin/products') ? $candidate : $default;
// 作为“批量操作返回地址”,只允许站内相对路径,并且需要稳定可控:
// - 限定前缀(避免跳出 merchant-admin/products 语义域)
// - 拒绝引号/尖括号(降低注入风险)
// - 拒绝 nested back=(避免 URL 膨胀/绕过)
if (! str_starts_with($candidate, '/merchant-admin/products')) {
return $default;
}
if (preg_match('/["\'<>]/', $candidate)) {
return $default;
}
if (preg_match('/(?:^|[?&])back=/', $candidate)) {
return $default;
}
return $candidate;
}
protected function filters(Request $request): array