Files
citrus-cms/app/Http/Middleware/CheckStaticHash.php
T
2026-04-28 21:14:25 +03:00

42 lines
1.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
class CheckStaticHash
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle(Request $request, Closure $next)
{
$hash = config('services.api.static_hash');
// Eğer hash config'de tanımlı değilse güvenli başarısızlık (fail-safe)
if (empty($hash)) {
return response()->json([
'status' => 'error',
'message' => 'Server configuration error: API Static Hash is not configured.'
], 500);
}
$requestHash = $request->header('X-Api-Hash');
if ($requestHash !== $hash) {
return response()->json([
'status' => 'error',
'message' => 'Unauthorized access. Invalid or missing X-Api-Hash header.'
], 401);
}
return $next($request);
}
}