Review main Merged

77946[TASK] Add HTTP security headers for backend by default

Torben Hansen CR +2 V +2 Easy +42 −0 updated 03/02/23, 11:23

Commit message

The TYPO3 backend currently adds a `X-Frame-Options: SAMEORIGIN`
HTTP security header to prevent clickjacking attacks. It is however
possible to use several other HTTP security headers for TYPO3 backend
requests as well.

This change adds the following HTTP security headers by default
for TYPO3 backend requests:

* `Strict-Transport-Security: max-age=31536000` (only if
  :php:`$GLOBALS[TYPO3_CONF_VARS][BE][lockSSL]` is active)
* `X-Content-Type-Options: nosniff`
* `Referrer-Policy: strict-origin-when-cross-origin`

Review

  • Code review CR +2 Done
    • Georg Ringer +2
    • Oliver Klee +1
    • Christian Kuhn +1
    • Oliver Hader +1
  • Verified V +2 Done
    • Georg Ringer +2
    • Christian Kuhn +1
    • core-ci +1 CI

Issues 1

Files 3

Review log 1921

  1. Torben Hansen uploaded patch set 1 02/25/23, 13:30

  2. core-ci voted on patch set 1 V +1 02/25/23, 13:36 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/38093

  3. Sybille Peters commented on patch set 1 V +1 CR +1 02/25/23, 17:22

    Personally, I would add that in the webserver configuration but I guess there is no harm if you can deactivate it and we have a stronger default this way.
  4. Oliver Klee voted on patch set 1 CR +1 02/25/23, 18:09

  5. Josef Glatz voted on patch set 1 CR +1 02/27/23, 20:18

  6. Christian Kuhn voted on patch set 1 V +1 CR +1 03/01/23, 12:27

  7. Oli Bartsch commented on patch set 1 03/01/23, 12:58

    AdditionalResponseHeaders.php:40

    Possible null pointer?

    AdditionalResponseHeaders.php:40

    Possible undefined array key?
  8. Christian Kuhn commented on patch set 1 03/01/23, 13:20

    AdditionalResponseHeaders.php:40 Reply

    i'd say we should rely on normalizedParams attribute being properly set by an earlier middleware. this should crash in case it has been tampered with.

    AdditionalResponseHeaders.php:40 Reply

    well, it's defined in DefaultConfiguration.php. unsetting this property will probably raise further issues elsewhere and it should be fine to rely on it being set, imho.
  9. Christian Kuhn commented on patch set 1 V 0 CR 0 03/01/23, 13:39

    not 100% sure about the hsts header by default, this is a thing you essentially can't ever get rid of again after a browser got it once. also, this is domain-wide, right? so if a FE is non-https as well, a BE user won't be able to call it http-only again? do we accept this force-browser-https as default?
  10. Christian Kuhn commented on patch set 1 03/01/23, 13:53

    Reply

    thinking about this some further, i tend to say that we shouldn't add the hsts header since this may be too intrusive by default, even in 2023 - we essentially "pollute" the entire domain as soon as the backend is https just once. i'd love to be convinced of the opposite, strong security defaults ... but maybe this is still a bit too much at the moment? an alternative is to send the hsts header only if 'isHttps()' AND 'lockSSL' = true? this would not kick in for default instances, though ... what do you think?
  11. Torben Hansen commented on patch set 1 03/01/23, 14:52

    Reply

    The patch will remove the HSTS header, if lockSSL is false AND if the website is not accessed using HTTPS. I think it may also be an option to on only set the HSTS header, if lockSSL is true. As soon as this requirement is reached, the backend is forced to use HTTPS and we can assume, that the website has a valid SSL certificate for that domain. For the scenario, that the backend must use HTTPS and the frontend HTTP, the website administrator can unset the HSTS header in `additional.php` manually.
  12. Torben Hansen commented on patch set 1 03/01/23, 15:09

    Reply

    State for other popular CMS: - WordPress: No HSTS header by default. - Drupal: No HSTS header by default. - Joomla: No HSTS header by default. Optional configurable (https://github.com/joomla/joomla-cms/blob/4.2-dev/plugins/system/httpheaders/httpheaders.php#L389) So maybe we should really only send the HSTS header for BE, if lockSSL=true
  13. Oliver Hader commented on patch set 1 03/01/23, 15:47

    Reply

    What would be valid use cases to use HTTPS only for the backend, but still rely on HTTP for the frontend? From my own experience, when a website was falling back to HTTP, it somehow was a server misconfiguration/error - which is one aspect, that HSTS is trying to mitigate. However, I'd be fine with the suggested combo with lockSSL as well for the basic default behavior.
  14. Torben Hansen uploaded patch set 2 CR +1 V +1 03/01/23, 18:03

  15. Torben Hansen commented on patch set 2 03/01/23, 18:05

    Reply

    The HSTS header is now only added, when `$GLOBALS[TYPO3_CONF_VARS][BE][lockSSL] = true`
  16. core-ci voted on patch set 2 V +1 03/01/23, 18:11 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/38272

  17. Christian Kuhn voted on patch set 2 V +1 CR +1 03/02/23, 07:49

  18. Oliver Hader voted on patch set 2 CR +1 03/02/23, 07:52

  19. Oliver Klee voted on patch set 2 CR +1 03/02/23, 09:44

  20. Georg Ringer voted on patch set 2 V +2 CR +2 03/02/23, 11:23

  21. Georg Ringer merged patch set 3 03/02/23, 11:23