Update: 2026-06-16 01:17:28

This commit is contained in:
Hamza-Ayed
2026-06-16 01:17:29 +03:00
parent 04943e3d52
commit fc58529b09
56 changed files with 1149 additions and 1314 deletions

View File

@@ -1,12 +1,13 @@
<?php
// ============================================================
// loginFirstTimeDriver.php — توكن التسجيل الأول (السائق)
// تم التحديث: استخدام One-Time Registration Tokens
// ============================================================
require_once __DIR__ . '/core/bootstrap.php';
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: https://intaleqapp.com');
header('Access-Control-Allow-Origin: https://siromove.com');
header('Access-Control-Allow-Methods: POST, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type, Authorization');
@@ -27,7 +28,6 @@ try {
$allowed1 = getenv('allowedDriver1');
$allowed2 = getenv('allowedDriver2');
$allowedAudiences = array_values(array_filter([$allowed1, $allowed2]));
$passwordnewpassenger = getenv('passwordnewpassenger');
if (empty($id) || empty($password) || empty($audience)) {
jsonError('Missing input fields.', 400);
@@ -37,9 +37,25 @@ try {
jsonError('Invalid audience', 400);
}
if (!password_verify($password, $passwordnewpassenger)) {
securityLog("FirstTimeDriver login failed (password)", ['id' => $id]);
jsonError('Invalid credentials.', 401);
// ✅ FIX H-06: استخدام One-Time Registration Token عبر Redis بدلاً من كلمة مرور ثابتة
$useOneTimeToken = getenv('USE_ONE_TIME_REG_TOKEN') === 'true';
if ($useOneTimeToken && $redis) {
// التحقق من وجود توكن صالح في Redis
$storedToken = $redis->get("reg_token:{$id}");
if (!$storedToken || !hash_equals($storedToken, $password)) {
securityLog("FirstTimeDriver failed: Invalid or expired one-time token", ['id' => $id]);
jsonError('Invalid or expired registration token.', 401);
}
// حذف التوكن بعد الاستخدام (One-Time)
$redis->del("reg_token:{$id}");
} else {
// Fallback آمن: استخدام كلمة المرور الثابتة مع Rate Limiting مشدد
$passwordnewpassenger = getenv('passwordnewpassenger');
if (!password_verify($password, $passwordnewpassenger)) {
securityLog("FirstTimeDriver login failed (password)", ['id' => $id]);
jsonError('Invalid credentials.', 401);
}
}
$fpPepper = getenv('FP_PEPPER') ?: '';
@@ -47,6 +63,14 @@ try {
? hash('sha256', $fingerprint . $fpPepper)
: null;
// ✅ FIX C-02: استخدام getenv بدلاً من file_get_contents الثابت
$keyPath = getenv('JWT_SECRET_KEY_PATH');
if ($keyPath && file_exists($keyPath)) {
$secretKey = trim(file_get_contents($keyPath));
} else {
$secretKey = getenv('JWT_SECRET_KEY') ?: '';
}
$payload = [
'user_id' => 'new',
'sub' => $id,
@@ -62,7 +86,6 @@ try {
$payload['fingerPrint'] = $fpHash;
}
$secretKey = trim(file_get_contents('/home/siro-api/.secret_key'));
$jwt = Firebase\JWT\JWT::encode($payload, $secretKey, 'HS256');
jsonSuccess([