Fix #22: Medium-severity fixes (M-01 through M-07)
M-01: Host header injection - replaced HTTP_HOST with APP_DOMAIN M-02: Unauthenticated CRUD - ownership checks on carDrivers add/delete M-03: MD5 tracking token - replaced md5() with hash_hmac sha256 M-04: Webhook SMS - absolute log path instead of relative M-05: Weak 3-digit OTP - already noted as requirement (Fix #5) M-06: Redis without auth - added password + prefix to cancel_ride_by_driver M-07: SSRF bypass - str_ends_with -> strict equality in allowlist
This commit is contained in:
@@ -46,7 +46,7 @@ if (!move_uploaded_file($file['tmp_name'], $uploadPath)) {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$host = $_SERVER['HTTP_HOST'] ?? 'api-syria.siromove.com';
|
$host = getenv('APP_DOMAIN') ?: 'api-syria.siromove.com';
|
||||||
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? "https" : "http";
|
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? "https" : "http";
|
||||||
$imageUrl = "$protocol://$host/siro/auth/uploads/documents/" . $uniqueName ;
|
$imageUrl = "$protocol://$host/siro/auth/uploads/documents/" . $uniqueName ;
|
||||||
$imageData = file_get_contents($uploadPath);
|
$imageData = file_get_contents($uploadPath);
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ try {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$host = $_SERVER['HTTP_HOST'] ?? 'api-syria.siromove.com';
|
$host = getenv('APP_DOMAIN') ?: 'api-syria.siromove.com';
|
||||||
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? "https" : "http";
|
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? "https" : "http";
|
||||||
$PUBLIC_BASE = "$protocol://$host/siro/auth/uploads/documents";
|
$PUBLIC_BASE = "$protocol://$host/siro/auth/uploads/documents";
|
||||||
|
|
||||||
@@ -230,7 +230,7 @@ Therefore, do NOT assume a specific field is on the front or the back of a card.
|
|||||||
$urlHost = parse_url($url, PHP_URL_HOST);
|
$urlHost = parse_url($url, PHP_URL_HOST);
|
||||||
$allowed = false;
|
$allowed = false;
|
||||||
foreach ($allowedHosts as $host) {
|
foreach ($allowedHosts as $host) {
|
||||||
if ($host && str_ends_with($urlHost, $host)) {
|
if ($host && $urlHost === $host) {
|
||||||
$allowed = true;
|
$allowed = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ const MAX_FILE_MB = 5;
|
|||||||
const ALLOWED_MIMES = ['image/jpeg','image/png','image/webp']; // فقط صور
|
const ALLOWED_MIMES = ['image/jpeg','image/png','image/webp']; // فقط صور
|
||||||
const UPLOAD_ROOT = __DIR__ . "/../../private_uploads"; // مجلد خاص (غير عام)
|
const UPLOAD_ROOT = __DIR__ . "/../../private_uploads"; // مجلد خاص (غير عام)
|
||||||
const SIGN_SECRET = getenv('SECRET_KEY_HMAC'); // غيّرها واقرأها من .env
|
const SIGN_SECRET = getenv('SECRET_KEY_HMAC'); // غيّرها واقرأها من .env
|
||||||
$host = $_SERVER['HTTP_HOST'] ?? 'api-syria.siromove.com';
|
$host = getenv('APP_DOMAIN') ?: 'api-syria.siromove.com';
|
||||||
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? "https" : "http";
|
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? "https" : "http";
|
||||||
define('PUBLIC_BASE', "$protocol://$host/siro");
|
define('PUBLIC_BASE', "$protocol://$host/siro");
|
||||||
const SIGNED_TTL_SEC = 172800; // 2 days = 60*60*24
|
const SIGNED_TTL_SEC = 172800; // 2 days = 60*60*24
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once __DIR__ . '/../../connect.php';
|
require_once __DIR__ . '/../../connect.php';
|
||||||
|
|
||||||
|
// التحقق من أن المستخدم يملك هذا المعرف
|
||||||
|
if ($role !== 'admin' && $role !== 'super_admin' && (string)$user_id !== (string)$driverID) {
|
||||||
|
jsonError("Unauthorized: You can only add cars to your own account");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
// استقبال القيم
|
// استقبال القيم
|
||||||
$driverID = filterRequest("driverID");
|
$driverID = filterRequest("driverID");
|
||||||
$vin = $encryptionHelper->encryptData(filterRequest("vin"));
|
$vin = $encryptionHelper->encryptData(filterRequest("vin"));
|
||||||
|
|||||||
@@ -4,6 +4,23 @@ require_once __DIR__ . '/../../connect.php';
|
|||||||
// استقبال ID السجل
|
// استقبال ID السجل
|
||||||
$id = filterRequest("id");
|
$id = filterRequest("id");
|
||||||
|
|
||||||
|
// التحقق من أن السجل يخص المستخدم الحالي أو هو أدمن
|
||||||
|
$checkSql = "SELECT driverID FROM captains_car WHERE id = :id LIMIT 1";
|
||||||
|
$checkStmt = $con->prepare($checkSql);
|
||||||
|
$checkStmt->bindParam(':id', $id, PDO::PARAM_INT);
|
||||||
|
$checkStmt->execute();
|
||||||
|
$record = $checkStmt->fetch(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
if (!$record) {
|
||||||
|
jsonError("Record not found");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($role !== 'admin' && $role !== 'super_admin' && (string)$user_id !== $record['driverID']) {
|
||||||
|
jsonError("Unauthorized: You can only delete your own car registrations");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
// حذف السجل من جدول captains_car (أو CarRegistration لو هو الصحيح فعلاً)
|
// حذف السجل من جدول captains_car (أو CarRegistration لو هو الصحيح فعلاً)
|
||||||
$sql = "DELETE FROM captains_car WHERE id = :id";
|
$sql = "DELETE FROM captains_car WHERE id = :id";
|
||||||
$stmt = $con->prepare($sql);
|
$stmt = $con->prepare($sql);
|
||||||
|
|||||||
@@ -142,6 +142,9 @@ try {
|
|||||||
try {
|
try {
|
||||||
$redis = new Redis();
|
$redis = new Redis();
|
||||||
$redis->connect('127.0.0.1', 6379);
|
$redis->connect('127.0.0.1', 6379);
|
||||||
|
$redisPass = getenv('REDIS_PASSWORD');
|
||||||
|
if ($redisPass) $redis->auth($redisPass);
|
||||||
|
$redis->setOption(Redis::OPT_PREFIX, 'siro:');
|
||||||
$redisKey = "passenger_debt_" . $passenger_id;
|
$redisKey = "passenger_debt_" . $passenger_id;
|
||||||
// إضافة الدين الجديد إلى الدين السابق إن وجد
|
// إضافة الدين الجديد إلى الدين السابق إن وجد
|
||||||
$currentDebt = (float) $redis->get($redisKey);
|
$currentDebt = (float) $redis->get($redisKey);
|
||||||
|
|||||||
@@ -48,9 +48,9 @@ try {
|
|||||||
|
|
||||||
// * هام: هذه الكلمة السرية يجب أن تكون مطابقة تماماً للموجودة في تطبيق Flutter
|
// * هام: هذه الكلمة السرية يجب أن تكون مطابقة تماماً للموجودة في تطبيق Flutter
|
||||||
$secretSalt = getenv("secretSaltParent");
|
$secretSalt = getenv("secretSaltParent");
|
||||||
|
|
||||||
// إعادة بناء الهاش للمقارنة
|
// إعادة بناء الهاش للمقارنة (HMAC-SHA256 بدلاً من MD5)
|
||||||
$generatedToken = md5($rideID . $driverID . $secretSalt);
|
$generatedToken = hash_hmac('sha256', $rideID . $driverID, $secretSalt);
|
||||||
|
|
||||||
if ($token !== $generatedToken) {
|
if ($token !== $generatedToken) {
|
||||||
http_response_code(403);
|
http_response_code(403);
|
||||||
|
|||||||
@@ -72,8 +72,10 @@ if (preg_match($pattern_orangemoney_jo, $message_body, $matches)) {
|
|||||||
$log_entry .= " | INFO: Message did not match the Orange Money pattern. Ignored." . PHP_EOL;
|
$log_entry .= " | INFO: Message did not match the Orange Money pattern. Ignored." . PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// كتابة كل شيء في ملف السجل
|
// كتابة كل شيء في ملف السجل (بالمسار المطلق)
|
||||||
file_put_contents('sms_log.txt', $log_entry, FILE_APPEND);
|
$logDir = __DIR__ . '/../../logs';
|
||||||
|
if (!is_dir($logDir)) @mkdir($logDir, 0777, true);
|
||||||
|
file_put_contents($logDir . '/sms_webhook_log.txt', $log_entry, FILE_APPEND);
|
||||||
|
|
||||||
|
|
||||||
// --- 5. إرسال رد إلى تطبيق الأندرويد ---
|
// --- 5. إرسال رد إلى تطبيق الأندرويد ---
|
||||||
|
|||||||
Reference in New Issue
Block a user