From 3152e8c288d735cfe1045779d754d574a73fe6bc Mon Sep 17 00:00:00 2001 From: Lukasz Tulikowski Date: Tue, 8 Jul 2025 20:26:05 +0200 Subject: [PATCH 1/3] 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; } From 478ba9973f88f391bba2fb5154c50261ecc66311 Mon Sep 17 00:00:00 2001 From: Lukasz Tulikowski Date: Wed, 16 Jul 2025 10:01:13 +0200 Subject: [PATCH 2/3] fix(color): enhance regex pattern for CSS color validation in getColorOpt function --- includes/functions.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/includes/functions.php b/includes/functions.php index a3e53ef6..9541e307 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -666,7 +666,12 @@ function getColorOpt() } // 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"; + $colorPattern = "/^(" . + "#([a-fA-F0-9]{3}|[a-fA-F0-9]{6})" . "|" . // Hex colors (#RGB or #RRGGBB) + "rgb\(\s*(?:\d{1,3}\s*,\s*){2}\d{1,3}\s*\)" . "|" . // RGB format + "rgba\(\s*(?:\d{1,3}\s*,\s*){3}\s*(0|0\.\d+|1)\s*\)" . "|" . // RGBA format + "[a-zA-Z]+" . // Named colors + ")$/i"; // Validate the color if (!preg_match($colorPattern, $color)) { @@ -1020,4 +1025,3 @@ function callbackTimeout(callable $callback, int $interval) return $result; } - From bad782deda45e985b837adc4e5b608be7154ea2b Mon Sep 17 00:00:00 2001 From: Lukasz Tulikowski Date: Wed, 16 Jul 2025 10:04:32 +0200 Subject: [PATCH 3/3] fix(color): sanitize color output in SVG and CSS files to prevent XSS vulnerabilities --- app/css/custom.php | 6 +++--- app/img/devices/default.php | 4 ++-- app/img/devices/zero.php | 2 +- app/img/raspAP-logo.php | 8 ++++---- app/img/solid.php | 12 ++++++------ 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/app/css/custom.php b/app/css/custom.php index 6f4db818..9113ef39 100644 --- a/app/css/custom.php +++ b/app/css/custom.php @@ -14,9 +14,9 @@ License: GNU General Public License v3.0 @import url('all.css'); :root { - --raspap-theme-color: ; - --raspap-theme-lighter: ; - --raspap-theme-darker: ; + --raspap-theme-color: ; + --raspap-theme-lighter: ; + --raspap-theme-darker: ; } body { diff --git a/app/img/devices/default.php b/app/img/devices/default.php index 9311b504..71ea0703 100644 --- a/app/img/devices/default.php +++ b/app/img/devices/default.php @@ -7,9 +7,9 @@ $color = getColorOpt(); viewBox="0 0 431 321" style="enable-background:new 0 0 431 321;" xml:space="preserve"> diff --git a/app/img/devices/zero.php b/app/img/devices/zero.php index 68c17007..4e688ad7 100644 --- a/app/img/devices/zero.php +++ b/app/img/devices/zero.php @@ -7,7 +7,7 @@ $color = getColorOpt(); diff --git a/app/img/raspAP-logo.php b/app/img/raspAP-logo.php index c23399ab..c8115634 100755 --- a/app/img/raspAP-logo.php +++ b/app/img/raspAP-logo.php @@ -32,20 +32,20 @@ $color = getColorOpt(); transform="translate(192.6768,123.4365)" id="g20"> diff --git a/app/img/solid.php b/app/img/solid.php index 9952e7fa..23bd418a 100644 --- a/app/img/solid.php +++ b/app/img/solid.php @@ -42,24 +42,24 @@ if ($showJoint) { for ($i = 1; $i < count($activeYs); $i++) { $y1 = $activeYs[$i-1]; $y2 = $activeYs[$i]; - echo ""; + echo ""; } } ?> - + - + - + - + - +