Change handling 'none' with additional sources

Created on 24 May 2020, almost 5 years ago
Updated 2 February 2024, about 1 year ago

Problem/Motivation

The CSP spec ignores 'none' if other sources are provided for a directive (https://github.com/w3c/webappsec-csp/issues/411).

CSP 8.x-1.x's policy optimization instead takes a strict approach, and will remove other sources from a directive if it contains 'none'. If a site wants to allow overriding 'none', an alter listener needs to remove it before it's rendered.

This also affects how configuration is used:
- if a directive is configured with 'none' as default, then any additions from modules will be removed, unless they override the 'none' by removing it (which contrib modules probably shouldn't generally do).
- if a directive is configured with an empty default, then it will not be output unless a module adds a value. This may result in a fallback directive being applied as the effective value.
So there is no way to configure "Don't allow any sources for this directive by default, but allow any module overrides".

Proposed resolution

- Change reduceSourceList() to remove 'none' if other sources are present on a directive, to align with the spec behaviour.
If a site wants to strictly enforce 'none' on a directive, it should implement a listener that executes last to remove additional values.

After the change, for configuration:
- if a directive is configured with 'none' as default, then it will always be output - either with only 'none' or with only any additions by modules. This will allow configuration to prevent a fallback directive from being used.
- if a directive is configured with an empty default, then it will not be output unless a module adds a value. (resulting in the browser using a fallback directive if present on the policy).

Remaining tasks

-
-
- Remove error suppression on deprecation warning in last 8.x-1.x release.
- Add an explicit "Block" option to directive configuration, that would prevent any module additions, and align with the 8.x-1.x behaviour?

User interface changes

API changes

The behaviour of configuring a directive with a default of 'none' will have a different effect.
Modules altering a directive to include 'none' should remove any other directives if they want the 'none' to take precedence rather than relying on the Csp class to remove them when the policy is rendered. (A helper method could be implemented to preserve compatible values like 'report-sample').

Data model changes

Feature request
Status

Fixed

Version

2.0

Component

Code

Created by

🇨🇦Canada gapple

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024