Files
Siro/backend/serviceapp/updatePackages.php
T
Hamza-AyedandClaude Opus 5 4009af8dd3 Add campaign launcher and app version manager; fix SQL injection in updatePackages
serviceapp/updatePackages.php built its UPDATE by interpolating the request
values straight into the SQL string, so any caller with a valid token could
execute arbitrary SQL through the version field. It now uses bound
parameters, requires an admin role, validates the version format, and writes
an audit entry.

trigger_campaign.php gains dry_run=1: it performs the same Gemini analysis
and target selection but returns before creating the promo code and before
dispatching any notification. Launching without previewing was the only
option before, and a launch writes a seven-day discount and pushes to every
passenger in the country.

Console:
- Campaign launcher with a mandatory preview. Launching stays disabled until
  the current parameters have been previewed, and re-locks if any parameter
  changes afterwards or once a launch completes.
- App version manager with the same version-format check as the server and a
  confirmation naming the old and new values.

Cache busting: assets are served straight off a bind mount with no version,
so browsers kept running the previously cached build after a deploy. Both
asset links now carry ?v=, and the build id is shown in Session & Security
and printed in the diagnostics report.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-25 14:41:27 +03:00

54 lines
2.1 KiB
PHP

<?php
require_once __DIR__ . '/../connect.php';
// رقم الإصدار يقرره العميل: كل تطبيقات سيرو تقارن نفسها به وتفرض التحديث،
// فتغييره يؤثر على كل المستخدمين. connect.php يتحقق من صحة التوكن فقط.
if ($role !== 'admin' && $role !== 'super_admin') {
http_response_code(403);
echo json_encode([
'status' => 'failure',
'message' => 'Forbidden. Admin access required.',
], JSON_UNESCAPED_UNICODE);
exit;
}
$id = filterRequest("id");
$version = filterRequest("version");
if (empty($id) || empty($version)) {
jsonError("Both id and version are required.", 400);
}
// شكل الإصدار: أرقام ونقاط فقط (مثل 1.2.3) — يمنع أي محتوى آخر.
if (!preg_match('/^\d+(\.\d+){0,3}$/', $version)) {
jsonError("Invalid version format. Use digits separated by dots, e.g. 1.4.2", 400);
}
/**
* سابقاً كان الاستعلام يُبنى بدمج القيم مباشرة:
* "UPDATE packageInfo SET version ='$version' WHERE id = '$id'"
* وهو حقن SQL مباشر — أي مستخدم يملك توكناً صالحاً كان يستطيع تنفيذ ما يشاء
* على قاعدة البيانات عبر حقل الإصدار. الآن القيم مرتبطة كمعاملات.
*/
$stmt = $con->prepare("UPDATE `packageInfo` SET `version` = :version WHERE `id` = :id");
$stmt->execute([
':version' => $version,
':id' => $id,
]);
if (function_exists('logAudit')) {
try {
logAudit($con, (string) ($user_id ?? 'unknown'), 'تحديث إصدار التطبيق', 'packageInfo', $id, [
'version' => $version,
]);
} catch (Throwable $e) {
error_log("[updatePackages] audit failed: " . $e->getMessage());
}
}
if ($stmt->rowCount() > 0) {
jsonSuccess(['id' => $id, 'version' => $version], "Package version updated successfully for ID $id");
} else {
jsonError("No package row was updated — check that ID $id exists and the version differs.", 404);
}