Skip to content

Allow custom csp header#5477

Open
TheSyscall wants to merge 59 commits intomainfrom
allow-custom-csp-header-5333
Open

Allow custom csp header#5477
TheSyscall wants to merge 59 commits intomainfrom
allow-custom-csp-header-5333

Conversation

@TheSyscall
Copy link

@TheSyscall TheSyscall commented Mar 12, 2026

Taking over #5337 (#5337 (comment)) and implementing an override for a completely custom CSP-Header.

As well as adding a table below the form which displays the source of the automatically generated CSP-Header.

Styling for this table is still WIP.

requires Icinga/ipl-web#358

closes #5337
closes #5333

@TheSyscall TheSyscall requested a review from nilmerg March 12, 2026 13:02
@TheSyscall TheSyscall self-assigned this Mar 12, 2026
@cla-bot

This comment was marked as duplicate.

@TheSyscall TheSyscall requested a review from Al2Klimov March 12, 2026 13:03
@cla-bot

This comment was marked as duplicate.

@cla-bot

This comment was marked as duplicate.

use ipl\Web\Compat\CompatForm;
use ipl\Web\Widget\Callout;

class CspConfigForm extends CompatForm
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This currently doesn't output the config.ini to the screen like the old ConfigForm did.
I think changing the form type to a CompatForm is still the right call, because we don't want to rely on Zend_Forms forever.
If this behavior essential, we should reimplement the behavior of ConfigFrom as a CompatForm instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even in new modules we reimplemented this behavior: Icinga/icingadb-web#1269

So I'd not downgrade this functionality.

@TheSyscall TheSyscall requested a review from Al2Klimov March 16, 2026 11:59
Copy link
Member

@Al2Klimov Al2Klimov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

16 review comments should be enough for a Monday 16th. :)

use ipl\Web\Compat\CompatForm;
use ipl\Web\Widget\Callout;

class CspConfigForm extends CompatForm
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about always showing the generated CSP? Even if they're not in effect, they're a good cheat sheet, especially for a custom CSP.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm personally not a fan of that, because it might confuse people about what is currently active and that isn't.
I think waiting for @flourish86 to design something and talking about that with @lippserd is the right call here.

'frame-src' => [$absoluteUrl],
],
'reason' => [
'type' => 'dashlet',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The longer I look at this code, the more I'd like it to use classes (LoginButton #5442) end enums (CalloutType #358).

Colleagues who read this, let me know your opinions on this!

Copy link
Author

@TheSyscall TheSyscall Mar 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I agree, that was my first idea as well, but then I didn't want to introduce classes that are exclusively used inside the Csp-System.

PS: I think you wanted to link Icinga/ipl-web#358

$section['use_strict_csp'] = $this->getValue('use_strict_csp');
if ($this->isCspEnabled()) {
$section['use_custom_csp'] = $this->getValue('use_custom_csp');
if ($this->isCustomCspEnabled()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have three states here:

  • No CSP
  • Generated CSP
  • Custom CSP

Ideal use case for a dropdown.

@flourish86 What do you think?

(I.e use_strict_csp would keep values "0" and "1" internally for compatibility and add "custom".)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A dropdown would be the easiest choice here. That is a common pattern for forms in icingaweb. I personally like the two "nested" checkboxes, because it makes it clearer what you are doing in a techncal level.

@TheSyscall TheSyscall requested a review from Al2Klimov March 19, 2026 08:58
html.no-js .progress-label {
display: none;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this change for?

use ipl\Web\Compat\CompatForm;
use ipl\Web\Widget\Callout;

class CspConfigForm extends CompatForm
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider a toggle which appears along with generated CSP which controls whether to include user-entered stuff, such as dashlets, in the CSP.

);

$this->addPolicyTable(
t('Dashboard'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're concerned about #5477 (comment), you should be about this one too:

As not a IW2 dev, I'd have absolutely no clue that these are only my dashboards (if any!) and others may have their own.

Consider listing the dashboard-CSPs of all users, after all we have them (by name) in the preference store or something idk.

Module-provided dashboards should already be included as you should see all modules as admin. I guess they may contain external URLs as well.

'class' => 'collapsible',
'data-visible-height' => 250,
],
new CspConfigurationTable(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the table, this form is already large enough to have its own IW2 configuration tab.

CC @JolienTrog

),
'class' => 'autosubmit',
'checkedValue' => '1',
'uncheckedValue' => '0',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New form elements don't need these, do they?

]);

$cspForm->on(ContractForm::ON_SUBMIT, function (CspConfigForm $form) use ($config) {
if ($form->isCspEnabled() && $form->hasConfigChanged()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if I disable the CSP? Don't I deserve a reload?


public function __construct()
{
$this->getAttributes()->add('class', 'csp-config-table');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if BaseHtmlElement#defaultAttributes can be used instead.

return Table::tr([
Table::td($reason['navType']),
Table::td($reason['name']),
Table::td($reason['parent'] ?? 'NA'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'NA' misses translation.

if ($policy === '*') {
$result = HtmlElement::create('span', ['class' => 'wildcard'], $policy);
} elseif ($policy === "'self'") {
$result = HtmlElement::create('span', ['class' => 'self'], $policy);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@flourish86 I wonder if such generic names for CSS classes could clash with new ones in the future.

}
}

unset($policyDirectives);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this for?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow customization of the CSP

5 participants