修复认证与基础安全链路
This commit is contained in:
+8
-3
@@ -15,12 +15,17 @@ return Application::configure(basePath: dirname(__DIR__))
|
||||
health: '/up',
|
||||
)
|
||||
->withMiddleware(function (Middleware $middleware) {
|
||||
$trustedProxies = array_values(array_filter(array_map(
|
||||
static fn (string $proxy): string => trim($proxy),
|
||||
explode(',', (string) env('TRUSTED_PROXIES', '127.0.0.1,::1'))
|
||||
)));
|
||||
|
||||
// 强制解析并信任 CDN (如 Cloudflare) 透传的真实 IP (最高优先级)
|
||||
$middleware->prepend(\App\Http\Middleware\CloudflareProxies::class);
|
||||
|
||||
// 信任所有代理转发头(腾讯 EdgeCDN HTTPS 回源 HTTP 场景)
|
||||
// CDN 携带 X-Forwarded-Proto: https,Laravel 据此将请求识别为 HTTPS,url()/route() 生成正确的 https:// 链接
|
||||
$middleware->trustProxies(at: '*');
|
||||
// 仅信任显式配置的反向代理 / CDN 节点,避免外部客户端伪造转发头污染 request()->ip()。
|
||||
// 生产环境需要把实际代理 IP / CIDR 写入 TRUSTED_PROXIES。
|
||||
$middleware->trustProxies(at: empty($trustedProxies) ? null : $trustedProxies);
|
||||
|
||||
$middleware->alias([
|
||||
'chat.auth' => \App\Http\Middleware\ChatAuthenticate::class,
|
||||
|
||||
Reference in New Issue
Block a user