Skip to content

Commit

Permalink
Use ipl\Web\Style to meet CSP compliancy (#108)
Browse files Browse the repository at this point in the history
fixes #107
  • Loading branch information
nilmerg authored Aug 30, 2023
2 parents 8366fa6 + 4a3a1c3 commit 19fa458
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 89 deletions.
85 changes: 0 additions & 85 deletions library/Notifications/Common/Style.php

This file was deleted.

9 changes: 5 additions & 4 deletions library/Notifications/Widget/Calendar/BaseGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@

use DateTime;
use DateTimeInterface;
use Icinga\Module\Notifications\Common\Style;
use Icinga\Module\Notifications\Widget\Calendar;
use Icinga\Util\Csp;
use ipl\Html\Attributes;
use ipl\Html\BaseHtmlElement;
use ipl\Html\HtmlElement;
use ipl\Html\Text;
use ipl\I18n\Translation;
use ipl\Web\Style;
use ipl\Web\Widget\Link;
use SplObjectStorage;
use Traversable;
Expand Down Expand Up @@ -138,9 +139,9 @@ protected function createGridOverlay(): BaseHtmlElement

protected function assembleGridOverlay(BaseHtmlElement $overlay): void
{
$style = new Style();
$style = (new Style())->setNonce(Csp::getStyleNonce());
$style->setModule('notifications'); // TODO: Don't hardcode this!
$style->setParentSelector('.calendar-grid .overlay');
$style->setSelector('.calendar-grid .overlay');

$overlay->addHtml($style);

Expand Down Expand Up @@ -234,7 +235,7 @@ protected function assembleGridOverlay(BaseHtmlElement $overlay): void
$gridArea = $this->getGridArea($rowStart, $rowEnd, $colStart, $colEnd);
$entryClass = 'area-' . implode('-', $gridArea);

$style->addRule(".$entryClass", [
$style->add(".$entryClass", [
'grid-area' => sprintf('~"%d / %d / %d / %d"', ...$gridArea),
'background-color' => $entry->getAttendee()->getColor() . dechex((int) (256 * 0.1)),
'border-color' => $entry->getAttendee()->getColor() . dechex((int) (256 * 0.5))
Expand Down

0 comments on commit 19fa458

Please sign in to comment.