Skip to content

Commit

Permalink
Validate hex color codes
Browse files Browse the repository at this point in the history
  • Loading branch information
Krymonota committed Oct 3, 2024
1 parent b963cdb commit b95436b
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Generator/HtmlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public function generate(MotdItemCollection $collection): string

if ($motdItem->getColor()) {
if (str_contains($motdItem->getColor(), '#')) {
// Only allow valid hex color codes (without alpha channel), such as #FFF and #000000.
if(!preg_match('/^#(([0-9A-Fa-f]{2}){3}|[0-9A-Fa-f]{3})$/i', $motdItem->getColor())) {
continue;
}

$tags['span'][] = sprintf('color: %s;', $this->escape($motdItem->getColor()));
} else {
$color = $this->colorCollection->get($motdItem->getColor());
Expand Down

0 comments on commit b95436b

Please sign in to comment.