Review main Merged

85632[TASK] Introduce Content-Security-Policy-Report-Only handling

Oliver Hader CR +2 V +2 Expert +942 −84 updated 08/28/24, 13:13

Commit message

+ new feature flag `security.frontend.reportContentSecurityPolicy`,
  to be used next to `security.frontend.enforceContentSecurityPolicy`,
  resulting in `Content-Security-Policy-Report-Only` and/or
  `Content-Security-Policy` HTTP headers
+ new `enforce` and `report` segments in `csp.yaml` site config
+ possibility to disable CSP for a particular site by either setting
  `active: false` in the `csp.yaml` site config
+ allows having the HTTP headers `Content-Security-Policy` and
  `Content-Security-Policy-Report-Only` side-by-side in the frontend

Review

  • Code review CR +2 Done
    • Oliver Hader +2
    • Benjamin Franzke +1
    • Garvin Hicking +1
  • Verified V +2 Done
    • Oliver Hader +2
    • Benjamin Franzke +1
    • Garvin Hicking +1
    • core-ci +1 CI

Issues 2

Files 18

Review log 72104

Show 5079 earlier messages
  1. Oliver Hader uploaded patch set 1 08/14/24, 17:16

  2. core-ci voted on patch set 1 V +1 08/14/24, 17:24 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63397

  3. Garvin Hicking commented on patch set 1 08/14/24, 17:36

    Good idea; I'm wondering though if "disposition" is a yaml keyword that is easy to recognize, or search for. At least for me it triggers a "Content-Disposition" HTTP header muscle memory, and I would wonder how CSP relates to download/content dispositions. How would you feel about searching for another wording like: activationMode: mode: toggle: enforcement: enforce: activation: activate: behavior: state: apply: activation: enable: (Couldn't test the actual patch yet)
  4. Oliver Hader commented on patch set 1 08/14/24, 17:41

    Reply

    `disposition` is a term from the CSP specs at https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP#disposition - that's why I used it here as well
  5. Chris Müller commented on patch set 1 08/14/24, 18:02

    A question: It's possible to use both "Content-Security-Policy" and "Content-Security-Policy-Report-Only"in one response (read lately about it but can't find the source currently in the specs). Is this an edge case which is intentionally not covered? Or would it be worth to allow both headers at once? For example, one does not enforce form-action currently (allowing all sources), but want to test the settings for it in report-only mode before enforcing it. It is worth thinking about it?
  6. Oliver Hader commented on patch set 1 08/14/24, 18:43

    Reply

    > A question: It's possible to use both "Content-Security-Policy" and "Content-Security-Policy-Report-Only"in one response (read lately about it but can't find the source currently in the specs). Is this an edge case which is intentionally not covered? Or would it be worth to allow both headers at once? > > For example, one does not enforce form-action currently (allowing all sources), but want to test the settings for it in report-only mode before enforcing it. > > It is worth thinking about it? Technically it's possible to use both headers `Content-Security-Policy` and `Content-Security-Policy-Report-Only` at the same time - e.g. using an existing policy and trying out changes before actually enforcing them. Some hours ago I've written my thoughts on that in a comment at https://forge.typo3.org/issues/104470#note-4 Especially for TYPO3 extensions this probably needs to more thoughts (e.g. installing a new extension, that defines ne CSP directives that should be applied to `Content-Security-Policy-Report-Only` - but still having the existing regular CSP headers in place)
  7. Oliver Hader commented on patch set 1 08/14/24, 19:08

    Reply

    I've added some more potential examples (ideas) to https://forge.typo3.org/issues/104470#note-5
  8. Garvin Hicking commented on patch set 1 08/14/24, 19:56

    Reply

    Thank you, then this totally makes sense. Sorry for not recognizing this before.
  9. Oliver Hader uploaded patch set 2 V +1 08/15/24, 16:23

  10. core-ci voted on patch set 2 V +1 08/15/24, 16:30 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63519

  11. Chris Müller commented on patch set 2 08/15/24, 16:32

    Reply

    Acknowledged
  12. Oliver Hader uploaded patch set 3 V +1 08/17/24, 12:19

  13. core-ci voted on patch set 3 V -1 08/17/24, 12:28 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63648

  14. Oliver Hader uploaded patch set 4 V -1 08/17/24, 13:00

  15. Oliver Hader uploaded patch set 5 08/17/24, 13:05

  16. core-ci voted on patch set 4 V -1 08/17/24, 13:06 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63657

  17. core-ci voted on patch set 5 V -1 08/17/24, 13:14 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63659

  18. core-ci commented on patch set 5 08/17/24, 13:21 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63659

  19. core-ci commented on patch set 5 08/17/24, 13:45 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63659

  20. Oliver Hader uploaded patch set 6 V -1 08/17/24, 14:36

  21. core-ci voted on patch set 6 V -1 08/17/24, 14:45 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63661

  22. Oliver Hader uploaded patch set 7 V -1 08/17/24, 18:31

  23. core-ci voted on patch set 7 V -1 08/17/24, 18:39 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63665

  24. Oliver Hader uploaded patch set 8 V -1 08/17/24, 18:44

  25. core-ci voted on patch set 8 V -1 08/17/24, 18:53 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63666

  26. Oliver Hader uploaded patch set 9 V -1 08/17/24, 19:02

  27. core-ci voted on patch set 9 V -1 08/17/24, 19:10 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63667

  28. Oliver Hader uploaded patch set 10 V -1 08/17/24, 19:15

  29. core-ci voted on patch set 10 V -1 08/17/24, 19:23 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63668

  30. Oliver Hader uploaded patch set 11 V -1 08/17/24, 19:34

  31. core-ci voted on patch set 11 V -1 08/17/24, 19:42 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63670

  32. Oliver Hader uploaded patch set 12 V -1 08/17/24, 19:49

  33. core-ci voted on patch set 12 V -1 08/17/24, 19:57 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63672

  34. Oliver Hader uploaded patch set 13 V -1 08/17/24, 20:13

  35. core-ci voted on patch set 13 V -1 08/17/24, 20:22 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63673

  36. Oliver Hader uploaded patch set 14 V -1 08/17/24, 20:39

  37. core-ci voted on patch set 14 V -1 08/17/24, 20:47 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63674

  38. Oliver Hader uploaded patch set 15 V -1 08/17/24, 21:01

  39. core-ci voted on patch set 15 V -1 08/17/24, 21:09 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63675

  40. Oliver Hader uploaded patch set 16 V -1 08/17/24, 21:22

  41. Oliver Hader uploaded patch set 17 08/17/24, 21:25

  42. core-ci voted on patch set 16 V -1 08/17/24, 21:32 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63676

  43. core-ci voted on patch set 17 V -1 08/17/24, 21:34 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63677

  44. Oliver Hader uploaded patch set 18 V -1 08/18/24, 10:32

  45. core-ci voted on patch set 18 V +1 08/18/24, 10:37 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63699

  46. Oliver Hader uploaded patch set 19 V +1 08/18/24, 12:07

  47. core-ci voted on patch set 19 V +1 08/18/24, 12:12 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63701

  48. Oliver Hader uploaded patch set 20 V +1 08/18/24, 12:48

  49. core-ci voted on patch set 20 V +1 08/18/24, 12:55 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63702

  50. Oliver Hader commented on patch set 20 08/18/24, 13:02

    CspAjaxController.php:106

    On a 2nd thought, it should not be blocked here... Dynamic mutations are only scope-specific - that's enough.
  51. Oliver Hader uploaded patch set 21 V +1 08/18/24, 13:16

  52. Oliver Hader commented on patch set 21 08/18/24, 13:19

    CspAjaxController.php:106 Reply

    Done
  53. core-ci voted on patch set 21 V -1 08/18/24, 13:21 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63704

  54. Oliver Hader uploaded patch set 22 V -1 08/18/24, 19:45

  55. core-ci voted on patch set 22 V +1 08/18/24, 19:52 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63731

  56. Oliver Hader uploaded patch set 23 V +1 08/19/24, 11:48

  57. core-ci voted on patch set 23 V -1 08/19/24, 11:54 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63766

  58. core-ci voted on patch set 23 V +1 08/19/24, 11:59 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63766

  59. Oliver Hader uploaded patch set 24 V +1 08/20/24, 19:56

  60. Oliver Hader wrote 08/20/24, 20:01

    Topic set to csp
  61. core-ci voted on patch set 24 V +1 08/20/24, 20:01 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63849

  62. Oliver Hader commented on patch set 24 08/20/24, 20:02

    This change is ready for review.
  63. Garvin Hicking updated the commit message in patch set 25 V +1 08/20/24, 20:48

  64. core-ci voted on patch set 25 V +1 08/20/24, 20:57 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63858

  65. Garvin Hicking commented on patch set 25 08/20/24, 21:00

    some questions, can also try to figure that out via code, but wanted to take notes before it may get merged, hope that's fine.

    Important-101580-IntroduceContentSecurityPolicyReportOnlyHandling.rst:19

    Not checked the code yet, but I read this so that if the report flag is enabled, it also enables "enforce" as well to be emittable, because ir says "precedence"? So if only the enforce-flag is set (not reporting), any YAML directive that would lead to a reportonly header be emitted wouldn't take effect then? Or can the site csp yaml settings be used either way and are completely distinct from this feature flag? Then we could maybe enhance the last paragraph about site settings ignoring these feature flags, maybe just replacing "can be controlled" with "can be overridden" to indicate this? (asking to understand for future docs)

    Important-104549-IntroduceSiteSpecificContentSecurityPolicyDisposition.rst:27

    This "bool-" should be "bool|"

    Important-104549-IntroduceSiteSpecificContentSecurityPolicyDisposition.rst:28

    So this is effectively a short-hand for "report: false" + "enforce: false", which allows to keep more complex definitions in the file for these report/enforce options, right? If true maybe that can be highlighted along the lines of: 'enable: (false)' allows to disable emitting any of the two compiled HTTP headers mentioned before, thus allowing to still define complex disposition-arrays (for example through a YAML import of a central file), but prevent their emission for specific sites.

    Important-104549-IntroduceSiteSpecificContentSecurityPolicyDisposition.rst:32

    so that would refer to the usual csp definitions of a sitepackage or extension? mention that as examples?

    Important-104549-IntroduceSiteSpecificContentSecurityPolicyDisposition.rst:34

    "applied to"?

    Important-104549-IntroduceSiteSpecificContentSecurityPolicyDisposition.rst:51

    I don't understand the "instead" here (need to check the code, haven't yet): Is it because "enforce: true" is not set, and the default is "enforce: false"? Or is the example missing a "enforce: false"?
  66. Stefan Bürk commented on patch set 24 08/20/24, 21:08

    MutationRepository.php:187

    Enum as array key ? should that not be $dispisition->value ? or is there something I miss within the Map implementation, at least phpstorm seams also to struggle with that. Do hwe have any tests which explicitly test this (and the following method) below in some way ??? Taking this this code should not work https://3v4l.org/a8Uf5

    MutationRepository.php:199

    same question as above - baked enum as array key ? should that not be `$map[$reducedScope->value]` ? Taking this this code should not work https://3v4l.org/a8Uf5
  67. Stefan Bürk commented on patch set 25 08/20/24, 21:11

    MutationRepository.php:187 Reply

    Ok, due to the Map implementation this "works" - it just renderes `weired`in PHPStorm stating it as illegal array key type. I guess finding some hint to avoid "error cringles" below the "enum array" keys feels kind of more conveniant here - does something exists ? Having object/enum as array keys feels kind of wrong (which is here only hidden behind the Map implementation).

    MutationRepository.php:199 Reply

    see above for provideDispositionInMap().
  68. Oliver Hader commented on patch set 25 08/20/24, 21:37

    MutationRepository.php:187 Reply

    > I guess finding some hint to avoid "error cringles" below the "enum array" keys feels kind of more conveniant here - does something exists ? Having object/enum as array keys feels kind of wrong (which is here only hidden behind the Map implementation). I'm not sure, what that means, but... The "Map" concept is known in JavaScript as well, e.g. see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map Using objects as keys in a key-value pair exists for a long time with `SplObjectStorage` in PHP. However, PHP failed to get that straight... the newly introduced `WeakMap` has the disadvantage to keep references that were assigned outside of the declaring function scope → that's why `\TYPO3\CMS\Core\Type\Map` has been introduced. The tests for `Map` actually prove, that it does work indeed, please see https://github.com/TYPO3/typo3/blob/main/typo3/sysext/core/Tests/Unit/Type/MapTest.php
  69. Oliver Hader commented on patch set 25 08/20/24, 21:40

    Reply

    These are great aspects & thanks for pointing them out... I'll respond to them soon & it feels something still needs to be adjusted for feature flag and site-dispositions - e.g. the `report` site-configuration can be used if the `reportContentSecurityPolicy` is not enabled...
  70. Oliver Hader commented on patch set 25 08/21/24, 19:48

    MutationRepository.php:187 Reply

    > Ok, due to the Map implementation this "works" - it just renderes weired in PHPStorm stating it as illegal array key type. PhpStorm complains about `$this->resolvedMutations[$scope][$disposition]` (`$disposition` would be an "illegal array key type"). However, the same happens with the native build in functionality for `\SplObjectStorage`. ``` $key = new \stdClass(); $storage = new \SplObjectStorage(); $storage[$key] = new \SplObjectStorage(); // PhpStorm complains about the 2nd level assignment, it // would be an "illegal array key type", but PhpStorm is wrong $storage[$key][$key] = true; ```
  71. Oliver Hader commented on patch set 25 08/21/24, 20:15

    Reply

    I was on a wrong track here... the feature flags are not about either enabling `report` or `enforce`, but to actually instruct the generic behavior (unless there is a more specific definition in a `my-site/csp.yaml` configuration). --- The current behavior without the patch is `enforceContentSecurityPolicy` must be enabled, otherwise no CSP header will be sent. In case `enforceContentSecurityPolicy` is active, but there is no `my-site/csp.yaml`, the still would be a (generic) CSP header as fallback. --- With the patch (patch-set 25), either the `enforceContentSecurityPolicy` or `reportContentSecurityPolicy` flag must be active, to have any CSP (or CSP-RO) header being sent. But I think it should be still adjusted a bit: * the interpretation of `enforce = false` and `report = false` shall be dropped - there shall be only on option to disable CSP per site, which is `enable = false` (or `disable = true` in case somebody is in favor of it) → that's new, allowing to disable CSP for a particular site, fine * in case the `my-site/csp.yaml` properties for `enforce` or `report` are either `true` or an array - thus shall be used to control CSP headers - even if both feature flags are disabled → that's new, CSP headers and disposition can be controlled by the site-configuration, *if declared explicitly there* * only in case `my-site/csp.yaml` properties for `enforce` or `report` are not defined, the fallback behavior kicks in, relying on the state of both feature flags → this is unchanged and is like the current behavior without the change What do you think?

    Important-101580-IntroduceContentSecurityPolicyReportOnlyHandling.rst:19 Reply

    If having both feature flags active, `report` takes precedence - because there is no possibility to make further adjustments to the CSP directives. The `csp.yaml` site-settings shall be distinct from the feature flags (see explanation in the main thread, the patch still has to be adjusted to reflect that). In case both `enforce` and `report` are configured in the `csp.yaml` configuration - if both are `true`, then `report` takes precedence (similar to having both feature flags enabled, because theres no way to declare the differences) - if both are configured with the `disposition-array`, then both CSP headers are sent (the array allows to declare different CSP directives). However, we also might remove these interpretations and just say "if you enabled both `report` and `enforce`, then both headers are sent - the integrator is responsible to get that correct" - code-wise it would be a bit easier and would remove the "takes precedence" part...

    Important-104549-IntroduceSiteSpecificContentSecurityPolicyDisposition.rst:28 Reply

    I'd opt for dropping `enforce: false` and `report: false` here to simplify the configuration. Just using `enable: false` indeed allows to disable the disposition - with keeping the other config in the `csp.yaml` file, without having to remove or comment these sections.

    Important-104549-IntroduceSiteSpecificContentSecurityPolicyDisposition.rst:34 Reply

    Yes

    Important-104549-IntroduceSiteSpecificContentSecurityPolicyDisposition.rst:51 Reply

    "... instead of the usual CSP header" - but I guess, I can drop the last part
  72. Garvin Hicking commented on patch set 25 08/21/24, 21:12

    Reply

    > the interpretation of enforce = false and report = false shall be dropped - there shall be only on option to disable CSP per site, which is enable = false I think that would make it more easy to understand, yes. I'd be in favor of "enable = false", then we could have "enable = true" as default which feels better than "disable = false" as default ;-) > in case the my-site/csp.yaml properties for enforce or report are either true or an array - thus shall be used to control CSP headers - even if both feature flags are disabled Strongly in favor, yes. Then one could specifically only enable CSP/CSP-RO on specific sites. I actually think in v14 we might want to deprecate the old and new related feature flags alltogether and make it site-config based only? Migration wizards could iterate all existing site configs and add default settings based on current feature flag settings then? Because the main issue with this is that people may think "I disable the feature flag, so it's disabled everywhere" which isn't the case. We might want to enhance the feature flag descriptions and say that the csp.yaml files can override the feature flag to raise awareness (and move towards csp.yaml files instead of feature flag). > only in case my-site/csp.yaml properties for enforce or report are not defined, the fallback behavior kicks in, relying on the state of both feature flags That's good and would be my expectation, yes!

    Important-101580-IntroduceContentSecurityPolicyReportOnlyHandling.rst:19 Reply

    (Sorry for my late-night rambling, I hope this makes sense at the light of day:) I'm a bit unsure at this moment because I haven't checked the code yet, but my feeling would be to not work with "precedence" for report and enforce, and actually possibly send both headers depending on config, and rely on the integrator to utilize both to their will. I do think it is a useful and common way to set "non-offensive" CSP headers first, and some "offensive" ones additionally as CSP-RO headers. At some point, integrators will refactor the offensive ones to work out and generate not too many reports, and then move the rules to the real CSP headers. Then either new rules can be tested with CSP-RO, or people may want to disable CSP-RO completely, and only keeping the CSP ones. My expectations for this patch would be: 1: I can configure "CSP" alone (no CSP-RO) 2: I can configure "CSP-RO" alone (no CSP) 3: I can configure CSP and CSP-RO alongside each other, with different policies 4: I can configure those facts centrally for ALL sites 5: I can configure each of those distinctly for each site, and even disable it on some sites. I can use CSP on one site, and CSP-RO on another 6: I can easily switch/migrate CSP-RO rules into CSP ones (and vice versa) If I read your comments right, those expectations should all be met, but (4) only with copy+paste on all site configs - because a Sitepackage's ContentSecurityPolicies.php only defines the inheritDefault settings, and does not distinguish between CSP and CSP-RO? So everything set in ContentSecurityPolicies.php would be factored into a csp.yaml, but that one would be the ultimate decission. To rephrase: A ContentSecurityPolicies.php (at this point) could not set 'enable = true' to override YAML settings. If that's right, I think it's acceptable, and only needs to be mentioned specifically to understand that CSPs are really quite site-oriented.
  73. Oliver Hader commented on patch set 25 08/21/24, 21:38

    Reply

    > I think that would make it more easy to understand, yes. I'd be in favor of "enable = false", then we could have "enable = true" as default which feels better than "disable = false" as default ;-) I think I would go with `disable: true` or `active: false` (I realized, that I mistyped `enable` and actually meant `enforce` - muscle memory - that's why I'd use a different property name here). > > in case the my-site/csp.yaml properties for enforce or report are either true or an array - thus shall be used to control CSP headers - even if both feature flags are disabled > > Strongly in favor, yes. Then one could specifically only enable CSP/CSP-RO on specific sites. I actually think in v14 we might want to deprecate the old and new related feature flags alltogether and make it site-config based only? Migration wizards could iterate all existing site configs and add default settings based on current feature flag settings then? Because the main issue with this is that people may think "I disable the feature flag, so it's disabled everywhere" which isn't the case. We might want to enhance the feature flag descriptions and say that the csp.yaml files can override the feature flag to raise awareness (and move towards csp.yaml files instead of feature flag). The behavior with that patch would still be backward-compatible - means, if feature flags are disabled and neither `enforce` nor `report` is `true` or `disposition-array` - no CSP, no CSP-RO headers are sent. But I'd be fine to require an explicit `active: true` then (in v14).

    Important-101580-IntroduceContentSecurityPolicyReportOnlyHandling.rst:19 Reply

    > (Sorry for my late-night rambling, I hope this makes sense at the light of day:) Thanks, that's great & helpful feedback! 👍 > My expectations for this patch would be: > > 1: I can configure "CSP" alone (no CSP-RO) > 2: I can configure "CSP-RO" alone (no CSP) > 3: I can configure CSP and CSP-RO alongside each other, with different policies > 4: I can configure those facts centrally for ALL sites > 5: I can configure each of those distinctly for each site, and even disable it on some sites. I can use CSP on one site, and CSP-RO on another > 6: I can easily switch/migrate CSP-RO rules into CSP ones (and vice versa) (4) is not available code-wise, but since our `YamlFileLoader` is used, it's possible to process `imports` and it's possible to use YAML anchors (`&` and `*`) for nested sections. > If I read your comments right, those expectations should all be met, but (4) only with copy+paste on all site configs - because a Sitepackage's ContentSecurityPolicies.php only defines the inheritDefault settings, and does not distinguish between CSP and CSP-RO? So everything set in ContentSecurityPolicies.php would be factored into a csp.yaml, but that one would be the ultimate decission. `ContentSecurityPolicies.php` is defined per package (which is kept internally in the `MutationOrigin`, so TYPO3 knows which directive was defined by which package). However, the decision whether to use `enforce` (CSP) or `report` (CSP-RO) cannot be made by extension authors, that's the task of an integrator by aggregating the declarations in a specific `csp.yaml` file. > To rephrase: A ContentSecurityPolicies.php (at this point) could not set 'enable = true' to override YAML settings. If that's right, I think it's acceptable, and only needs to be mentioned specifically to understand that CSPs are really quite site-oriented. Basically `ContentSecurityPolicies.php` never will have that possibility, since an extension should not be able to declare that on a global level.
  74. Oliver Hader uploaded patch set 26 V +1 08/21/24, 22:16

  75. Oliver Hader commented on patch set 25 08/21/24, 22:16

    Important-104549-IntroduceSiteSpecificContentSecurityPolicyDisposition.rst:27 Reply

    Done

    Important-104549-IntroduceSiteSpecificContentSecurityPolicyDisposition.rst:34 Reply

    Done

    Important-104549-IntroduceSiteSpecificContentSecurityPolicyDisposition.rst:51 Reply

    Done
  76. core-ci voted on patch set 26 V +1 08/21/24, 22:23 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63937

  77. Oliver Hader commented on patch set 26 08/21/24, 22:25

    Important-104549-IntroduceSiteSpecificContentSecurityPolicyDisposition.rst:32 Reply

    `inheritDefault` would take the definitions of `ContentSecurityPolicies.php` which were assigned to the `Scope::frontend()` (and are not site-specific). This setting did exist already and was enabled per default in case it was not explicitly disabled by `inheritDefault: false`
  78. Garvin Hicking commented on patch set 26 08/22/24, 10:57

    Reply

    I'm fine with `active: true|false`, thanks :-)
    I have now checked the code, with some more comments and also tested in on my v13 setup. Works as advertised (also curious was Chris can say, he's taking a deeper CSP dive than I did)! When enabling both feature flags, I get this content applied to both CSP and CSP-RO, which is expected by me: ``` default-src 'self'; script-src 'self' 'nonce-awrVra7sFDIMlTnDqrYS0dCUE_QHohxReywqK0ZvTaOgQSoTqxpjPw' 'report-sample'; style-src-attr 'unsafe-inline' 'report-sample'; img-src 'self' data: *.ytimg.com *.vimeocdn.com; base-uri 'self'; frame-src 'self' *.youtube-nocookie.com *.youtube.com *.vimeo.com; style-src-elem 'self' 'nonce-awrVra7sFDIMlTnDqrYS0dCUE_QHohxReywqK0ZvTaOgQSoTqxpjPw' 'report-sample'; report-uri https://typo3-core-bugreproduce-base.ddev.site/en/@http-reporting?csp=report&requestTime=1724322616822056 ``` However, two questions: - Is it okay the nonce is the same for both headers, spec-wise? - Is it okay that the report-uri is the same for both headers? Would having https://typo3-core-bugreproduce-base.ddev.site/en/@http-reporting?csp=report&requestTime=1724322616822056&disposition=enforce & https://typo3-core-bugreproduce-base.ddev.site/en/@http-reporting?csp=report&requestTime=1724322616822056&disposition=report be helpful?

    CspAjaxController.php:63

    Is this a drive-by bugfix, what would this address?

    DispositionConfiguration.php:20

    Is this class intentionally not @internal? (maybe final too?)

    DispositionMapFactory.php:24

    internal/final?

    DispositionMapFactory.php:49

    Maybe deprecate the feature settings for main then already? Or is it too soon?

    DefaultConfigurationDescription.yaml:198

    Add something like "Per-site configuration allows to disable and configure specifics of this feature."?

    DefaultConfigurationDescription.yaml:201

    I'm still a bit afraid how "precedence" might be misread leading people into thinking, they cannot send both headers (which is now the case after the recent patchset). How about: "If on, HTTP Content-Security-Policy-Report-Only (CSP-RO) header will be applied for each HTTP frontend request. Per-site configuration allows to disable and configure specifics of this feature. This feature can be used independent from security.frontend.enforceContentSecurityPolicy." ("This feature switch will be removed in TYPO3 v.XX in favor of a site-specific configuration."?)

    Important-101580-IntroduceContentSecurityPolicyReportOnlyHandling.rst:19 Reply

    Acknowledged

    Important-101580-IntroduceContentSecurityPolicyReportOnlyHandling.rst:26

    "Since this allows more granularity, the global feature switch is planned to be removed in TYPO3 vXX"?

    Important-104549-IntroduceSiteSpecificContentSecurityPolicyDisposition.rst:28 Reply

    Acknowledged

    Important-104549-IntroduceSiteSpecificContentSecurityPolicyDisposition.rst:32 Reply

    Acknowledged

    DispositionConfigurationTest.php:80

    Not sure what the Core recommendation is, some tests use named yield arguments like: ``` yield 'all to be dropped, b/b & c/c included' => [ 'packages' => [ '*' => false, 'b/b' => true, 'c/c' => true, ], 'packageNames' => ['a/a', 'b/b', 'c/c'], 'expectation' => ['b/b', 'c/c'], ]; ``` which is a bit easier on the eyes? I can do the legwork, if you agree. ;)

    DispositionMapFactoryTest.php:191

    I love the permutation thoroughness here, much appreciated to help me understand the established rules :)
  79. Chris Müller commented on patch set 26 08/25/24, 08:03

    Important-101580-IntroduceContentSecurityPolicyReportOnlyHandling.rst:19

    I read this as: When both are activated, only the report-only header is send. But I get both headers (with the same content - and when no site-specific csp.yaml is configured). I am fine with stating: "When both feature flags are activated, both headers are sent. You can deactivate one disposition in the site-specific configuration."
  1. Oliver Hader commented on patch set 26 08/27/24, 09:38

    Reply

    > However, two questions: > > - Is it okay the nonce is the same for both headers, spec-wise? That's fine - the nonce value needs to be different per HTTP request. > - Is it okay that the report-uri is the same for both headers? Would having https://typo3-core-bugreproduce-base.ddev.site/en/@http-reporting?csp=report&requestTime=1724322616822056&disposition=enforce & https://typo3-core-bugreproduce-base.ddev.site/en/@http-reporting?csp=report&requestTime=1724322616822056&disposition=report be helpful? The violation that is created by the browser has a corresponding `disposition` property - which can either be `report` of `enforce` (see https://developer.mozilla.org/en-US/docs/Web/API/SecurityPolicyViolationEvent/disposition)

    CspAjaxController.php:63 Reply

    This change is not required here, but just ensures that all actions without an HTTP body (like in `GET`) are not accepted. Let's call it "hardening"...

    DispositionConfiguration.php:20 Reply

    `readonly` classes cannot be extended, thus it implies `final`. Adding `@internal` is fine for me...

    DispositionMapFactory.php:24 Reply

    `readonly` classes cannot be extended, thus it implies `final`. Adding `@internal` is fine for me...

    DispositionMapFactory.php:49 Reply

    That would be a separate task for v13 only.

    DefaultConfigurationDescription.yaml:198 Reply

    Sounds good

    DefaultConfigurationDescription.yaml:201 Reply

    Actually the description is wrong here - both headers are sent (https://review.typo3.org/c/Packages/TYPO3.CMS/+/85632/26/typo3/sysext/core/Tests/Unit/Security/ContentSecurityPolicy/Configuration/DispositionMapFactoryTest.php#54 `both features enabled` verifies that). I'd postpone announcing the removal to a separate patch...

    Important-101580-IntroduceContentSecurityPolicyReportOnlyHandling.rst:26 Reply

    Later

    DispositionConfigurationTest.php:80 Reply

    Fine for me. Those array keys are actually mapped to argument names by PhpUnit... I'll take care of it - I need to adjust a bunch of other things anyway.
  2. Oliver Hader uploaded patch set 27 V +1 08/27/24, 09:55

  3. Oliver Hader commented on patch set 26 08/27/24, 09:55

    DispositionConfiguration.php:20 Reply

    Done

    DispositionMapFactory.php:24 Reply

    Done

    DefaultConfigurationDescription.yaml:198 Reply

    Done

    DefaultConfigurationDescription.yaml:201 Reply

    Done

    Important-101580-IntroduceContentSecurityPolicyReportOnlyHandling.rst:19 Reply

    Good catch. I forgot to adjust that... Done

    DispositionConfigurationTest.php:80 Reply

    Done
  4. core-ci voted on patch set 27 V +1 08/27/24, 10:04 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/64285

  5. Garvin Hicking commented on patch set 27 CR +1 V +1 08/27/24, 11:39

    Thanks for the updates/feedback, ack to all. :-)

    CspAjaxController.php:63 Reply

    Acknowledged
  6. Andreas Kienast commented on patch set 27 CR +1 V +1 08/27/24, 14:32

    Nitpick: the backend module states > The following features flags are currently disabled and won't be shown in this module > * security.frontend.enforceContentSecurityPolicy Albeit there are logs in report-only mode. IMO no blocker for this patch, tho.
  7. Oliver Hader commented on patch set 27 08/27/24, 17:33

    Reply

    Good catch... I have not tested that with `report` only...
  8. Oliver Hader uploaded patch set 28 CR +1 V +1 08/27/24, 18:02

  9. Oliver Hader commented on patch set 28 08/27/24, 18:02

    Reply

    Done
  10. core-ci voted on patch set 28 V +1 08/27/24, 18:09 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/64346

  11. Andreas Kienast voted on patch set 28 CR +1 V +1 08/27/24, 20:09

  12. Garvin Hicking commented on patch set 28 08/28/24, 06:24

    When I set the "enforce" feature to off, but "reporting to on" I would expect the CSP module to say that "enforce" feature is not shown. But instead, no message appears. If I set "enforce" to "on", but reporting to "off", also no message appears. Only if both are off I get the message. Is that the intended behaviour of the module?
  13. Oliver Hader commented on patch set 28 08/28/24, 07:31

    Reply

    For instance for the case `enforce` is active, but `report` is not, the message shown would advertise to enable `report` as well - so, I'd say it's the desired behavior. In general the message is to make people aware, that the feature flag has to be enabled manually to have potential violations listed in the backend module.
  14. Garvin Hicking commented on patch set 28 CR +1 V +1 08/28/24, 08:32

    Reply

    I now understand, so it's a 'any enabled feature flag will do' message.Alright!
  15. Benjamin Franzke commented on patch set 28 CR +1 V +1 08/28/24, 08:35

    For sites with mixed report/enforce configurations I'd love if the backend module would show disposition: report/enforce in the table. But that's not a blocker, rather a nice-to-have.

    Important-104549-IntroduceSiteSpecificContentSecurityPolicyDisposition.rst:57

    I understand why `inheritDefault` is listed here (due to the following paragraph), it is still a bit misleading, as the example implies that `inheritDefault` does not default to `true`. But i'm fine with leaving this as-is.

    ContentSecurityPolicyHeaders.php:74

    I stumbled over this for a second and questioned why nonce is cloned, but I figured it is probably because you want a standalone instance for every disposition. Is it because you feared the policy compiler of the first disposition would consume the nonce although it hasn't been consumed yet? (Shouldn't happen as it checks `count()` and uses `->value` directly instead of `->consume()`) Is there another reason?
  16. Oliver Hader commented on patch set 28 08/28/24, 08:54

    Important-104549-IntroduceSiteSpecificContentSecurityPolicyDisposition.rst:57 Reply

    I could add a comment like ``` # inheritDefault is enable per default if omitted ``` Better?

    ContentSecurityPolicyHeaders.php:74 Reply

    Exactly, I tried to keep nonce consumption separated for each header disposition. Basically I had the events in the policy-provider in mind. After I second thought, this change probably should be dropped - since the counterpart (markup, events, ...) are using the same nonce-value.
  17. Benjamin Franzke commented on patch set 28 08/28/24, 09:36

    Important-104549-IntroduceSiteSpecificContentSecurityPolicyDisposition.rst:57 Reply

    yes 👍

    ContentSecurityPolicyHeaders.php:74 Reply

    ok, thx, then let's drop it, since I'd consider that a bug if the policy provider events consume the nonce.
  18. Oliver Hader uploaded patch set 29 CR +1 V +1 08/28/24, 10:01

  19. Oliver Hader commented on patch set 29 08/28/24, 10:01

    Important-104549-IntroduceSiteSpecificContentSecurityPolicyDisposition.rst:57 Reply

    Done

    ContentSecurityPolicyHeaders.php:74 Reply

    Done
  20. core-ci voted on patch set 29 V +1 08/28/24, 10:07 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/64403

  21. Benjamin Franzke voted on patch set 29 CR +1 V +1 08/28/24, 12:12

  22. Garvin Hicking voted on patch set 29 CR +1 V +1 08/28/24, 13:10

  23. Oliver Hader voted on patch set 29 CR +2 V +2 08/28/24, 13:12

  24. Oliver Hader commented on patch set 29 08/28/24, 13:13

    Thanks folks! 😊
  25. Oliver Hader merged patch set 30 08/28/24, 13:13