From 3152e8c288d735cfe1045779d754d574a73fe6bc Mon Sep 17 00:00:00 2001 From: Lukasz Tulikowski Date: Tue, 8 Jul 2025 20:26:05 +0200 Subject: [PATCH] fix(color): add validation for CSS color formats in getColorOpt function --- app/img/devices/compute.php | 140 ++++++++++++++++++------------------ includes/functions.php | 10 +++ 2 files changed, 80 insertions(+), 70 deletions(-) diff --git a/app/img/devices/compute.php b/app/img/devices/compute.php index bf744a3a..63ddeb44 100644 --- a/app/img/devices/compute.php +++ b/app/img/devices/compute.php @@ -8,78 +8,78 @@ $color = getColorOpt(); viewBox="0 0 291.5 203.2" style="enable-background:new 0 0 291.5 203.2;" xml:space="preserve"> diff --git a/includes/functions.php b/includes/functions.php index f1b90b9e..a3e53ef6 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -664,6 +664,16 @@ function getColorOpt() } else { $color = $_COOKIE['color']; } + + // Define the regex pattern for valid CSS color formats + $colorPattern = "/^(#([a-fA-F0-9]{3}|[a-fA-F0-9]{6})|rgb\((\s*\d+\s*,){2}\s*\d+\s*\)|rgba\((\s*\d+\s*,){3}\s*(0|0\.\d+|1)\)|[a-zA-Z]+)$/i"; + + // Validate the color + if (!preg_match($colorPattern, $color)) { + // Return a default color if validation fails + $color = "#2b8080"; + } + return $color; }