\App\Http\MiddlewareVerifyOriginMiddleware

同源来源校验

职责:为无 CSRF 令牌的 API 提供 CSRF 纵深防御——浏览器跨站请求必带 Origin 头(且跨站无法伪造),非浏览器客户端(curl/移动端/服务端) 不带 Origin 头,天然放行不受影响。

Summary

Methods
Properties
Constants
handle()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
isAllowed()
No private properties found
N/A

Methods

handle()

handle(\Illuminate\Http\Request  $request, \Closure  $next) : \Symfony\Component\HttpFoundation\Response

处理请求:仅校验非安全方法且携带 Origin 的请求。

判定:Origin 为同源(host 与请求 Host 一致)或在 CORS 白名单内 → 放行; 否则 403(与 CSRF 拒绝同语义)。无 Origin 头(curl/移动端)放行。

Parameters

\Illuminate\Http\Request $request
\Closure $next

Returns

\Symfony\Component\HttpFoundation\Response —

isAllowed()

isAllowed(string  $origin, \Illuminate\Http\Request  $request) : bool

允许判定:同源 或 命中 CORS 白名单。

同源比对 host(含端口);白名单取 config('cors.allowed_origins') 精确匹配——与 CORS 中间件同一事实源,避免两处白名单漂移。

Parameters

string $origin
\Illuminate\Http\Request $request

Returns

bool —