- πΊπΈUnited States bkosborne New Jersey, USA
I guess the X-Frame-Options header that core adds via FinishResponseSubscriber should also be removed when this is done. The "frame-ancestors" directive in the CSP header is well supported and obsoletes X-Frame-Options.
- π¨π¦Canada gapple
With IE no longer being supported, core could replace its default
X-Frame-Options: SAMEORIGIN
withContent-Security-Policy: frame-ancestors 'self'
. Starting to always add a default CSP header could cause problems for a site that setsX-Frame-Options: DENY
though. (It looks like IE was the only browser to supportALLOW-FROM
).A possible transition is:
[11.1] Add a late-subscriber that translates x-frame-options to a CSP frame-ancestors if the response does not have a CSP header (assume if a CSP header is set but does not include frame-ancestors, then it was intended to allow any frame parent). Issue a deprecation warning if the response has a value other thanX-Frame-Options: SAMEORIGIN
to notify users to use CSP instead.
[12.0] Remove the late subscriber, and replaceX-Frame-Options
with a static CSP policy that includesframe-ancestors 'self'
. A site that uses the Content-Security-Policy module, SecKit, or a custom listener to set the CSP header will override this default value.My suggestion for a minimal static policy that core can add by default:
Content-Security-Policy: script-src * 'unsafe-inline'; object-src 'none'; frame-ancestors 'self'
The simplest way to allow modifying the default CSP (or adding a CSP-Report-Only), would be to have a container parameter. Users wanting a more flexible implementation can use the CSP module.
- Merge request !7304Draft: Replace X-Frame-Ancestors with Content-Security-Policy β (Open) created by gapple
- Status changed to Needs review
10 months ago 9:53am 3 April 2024 - π¨π¦Canada gapple
A slightly rough MR:
- Introduce a new service parameter for setting static CSP values
- A late acting response subscriber will translateX-Frame-Options
toContent-Secutity-Policy: frame-ancestors
- If a CSP policy is set (via service parameter, or another module like CSP or seckit), then that value is not changed.
- TheX-Frame-Options
header is always removed - either it's being replaced by core with an equivalent CSP policy, or we assume that the CSP policy set by the user has their desiredframe-ancestors
value (including the option of being omitted).
- IfX-Frame-Options
is not set toSAMEORIGIN
, then a deprecation warning is issued to use CSP to set the value. (If the value is still the defaultSAMEORIGIN
, then a future version of Drupal changing toframe-ancestors 'self'
will not change browser behaviour).
-ALLOW-FROM
is ignored by modern browsers (and equivalent to not sending theX-Frame-Options
header), but is translated to a CSP value if used.In a future version of Drupal:
- The service parameter can be set to a default enforced CSP value
- The late acting event subscriber can be completely removed
- Core can stop settingX-Frame-Options
- Modules (such as CSP or seckit) will still override core's default (now static) value.Why the CSP policy value:
-script-src * 'unsafe-inline'
will only blockeval()
. Not including'unsafe-inline'
would have the potential to break existing sites (and hopefully its presence leads people to explore making sure it's not required...)
-object-src 'none'
is recommended to block legacy HTML elements
-frame-ancestors
replacesX-Frame-Options
- I don't think there's other values that can safely be added as a default enforced policy directive without a reasonable risk of negatively affecting some sites. (maybebase-uri 'self'
?) - Status changed to Needs work
10 months ago 11:29am 3 April 2024 The Needs Review Queue Bot β tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide β to find step-by-step guides for working with issues.
- Assigned to gapple
- Issue was unassigned.
- Status changed to Needs review
8 months ago 11:58am 19 May 2024 - π¨π¦Canada gapple
Rebased and fixed the bot's previous issue.
In my previous comment I wasn't sure of the core dev timeline, but this looks like it's something that could be put in 10.4, with the compatibility later removed in 11.0.0.
- Status changed to Needs work
8 months ago 2:49pm 20 May 2024 - Status changed to Needs review
8 months ago 10:10am 21 May 2024 - Status changed to Needs work
8 months ago 5:41pm 29 May 2024 - πΊπΈUnited States smustgrave
Can be rebased so tests appear green please.
Also is it meant to be draft?For the CR you can actually go ahead and create it just don't check published yet till the issue is merged.
- Status changed to Needs review
5 months ago 7:21am 6 September 2024 - π¨π¦Canada gapple
- Squashed and rebased
- Draft Change Record created β
- Postponed issue for 12.x created π [12.x] Set default Content-Security-Policy in services.yml PostponedI'm not sure why tests are failing on
ImageStylesPathAndUrlTest:L315
Remaining questions:
- Service parameter name: http.response.content_security_policy (like http.response.debug_cacheability_headers) or csp.config (like cors.config) or ?
- Should any X-Frame-Options header present on a response be removed, since browsers will ignore it when CSP is present?
- Review additional directives to add by default:script-src * 'unsafe-inline'; object-src 'none'
The Needs Review Queue Bot β tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide β to find step-by-step guides for working with issues.
The Needs Review Queue Bot β tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide β to find step-by-step guides for working with issues.
- π¨π¦Canada gapple
Something that came up in #2868079: Add a default Content-Security-Policy-header for svg files β is that there may be a need for different policies in certain cases - uploaded files should probably have scripts and styles blocked, though SVGs may need inline styles, image data, and fonts. Private files can have the header applied from the event subscriber, but public files would require an addition to .htaccess.
Instead of a single set of policies, the service parameter could be keyed by use:
default: report_only: enforced: "script-src * 'unsafe-inline'; object-src 'none'; frame-ancestors 'self'" private_files: report_only: enforced: "default-src 'none'" svg: report_only: enforced: "default-src 'none'; style-src 'unsafe-inline'; image-src data: font-src: data:"