Actualiser api/index.php
CI / PHP Syntax Check (push) Has been cancelled
CI / JavaScript Lint (push) Has been cancelled
CI / Docker Build Test (push) Has been cancelled
CI / Validate Translation Files (push) Has been cancelled
CI / Auto-merge develop → main (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
Security Scan (Trivy) / Trivy — Docker image scan (push) Has been cancelled
Security Scan (Trivy) / Trivy — Filesystem scan (push) Has been cancelled

This commit is contained in:
2026-06-17 13:14:46 +00:00
parent 4a729d2d10
commit 9512e3a8df
+12 -4
View File
@@ -11,6 +11,16 @@
// ── Core bootstrap (env, security, database, logger) ─────────────────────────
require_once __DIR__ . '/bootstrap.php';
/** True if $location is a known location key (builtin or custom). */
function isValidLocation(PDO $db, string $location): bool {
static $cache = null;
if ($cache === null) {
$rows = $db->query("SELECT key FROM locations")->fetchAll(PDO::FETCH_COLUMN);
$cache = array_flip($rows);
}
return isset($cache[$location]);
}
const RECIPE_PANTRY_MIN_MATCH_SCORE = 80;
const RECENTLY_EXHAUSTED_DAYS = 30;
/** How long to suppress auto-re-add after user bought an item (ms, synced with client blocklist). */
@@ -3039,8 +3049,7 @@ function addToInventory(PDO $db): void {
}
// Validate location
$validLocations = ['dispensa', 'frigo', 'freezer', 'altro'];
if (!in_array($location, $validLocations)) {
if (!isValidLocation($db, $location)) {
EverLog::warn('addToInventory: invalid location (400)');
http_response_code(400);
echo json_encode(['error' => 'Invalid location']);
@@ -11874,9 +11883,8 @@ function familySiblingSuggest(PDO $db): void {
return;
}
$validLocations = ['dispensa', 'frigo', 'freezer', 'altro'];
$location = $input['location'] ?? 'dispensa';
if (!in_array($location, $validLocations, true)) {
if (!isValidLocation($db, $location)) {
$location = 'dispensa';
}