service add APP_SIGNATURE_SERVICE 2
This commit is contained in:
@@ -259,9 +259,13 @@ class JwtService
|
|||||||
$nonce = $_SERVER['HTTP_X_NONCE'] ?? '';
|
$nonce = $_SERVER['HTTP_X_NONCE'] ?? '';
|
||||||
$body = file_get_contents('php://input') ?: '';
|
$body = file_get_contents('php://input') ?: '';
|
||||||
|
|
||||||
|
// نشتق مفتاح الـ HMAC الخاص بهذا المستخدم (نفس المعادلة في login.php)
|
||||||
|
$derivedSecret = hash_hmac('sha256', (string)$userId, $this->hmacSecret);
|
||||||
|
|
||||||
// التوقيع يضم الـ Body + Timestamp + Nonce لمنع التكرار والتلاعب
|
// التوقيع يضم الـ Body + Timestamp + Nonce لمنع التكرار والتلاعب
|
||||||
$payloadToSign = $body . $timestamp . $nonce;
|
$payloadToSign = $body . $timestamp . $nonce;
|
||||||
$expectedHmac = hash_hmac('sha256', $payloadToSign, $this->hmacSecret);
|
$expectedHmac = hash_hmac('sha256', $payloadToSign, $derivedSecret);
|
||||||
|
|
||||||
|
|
||||||
if (!hash_equals($expectedHmac, $hmacHeader)) {
|
if (!hash_equals($expectedHmac, $hmacHeader)) {
|
||||||
error_log("[SECURITY] HMAC mismatch | user: $userId | IP: " . ($_SERVER['REMOTE_ADDR'] ?? '?'));
|
error_log("[SECURITY] HMAC mismatch | user: $userId | IP: " . ($_SERVER['REMOTE_ADDR'] ?? '?'));
|
||||||
|
|||||||
Reference in New Issue
Block a user