- Merge request !673Issue #3214208: FinishResponseSubscriber could create duplicate headers โ (Closed) created by gapple
The Needs Review Queue Bot โ tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide โ to find step-by-step guides for working with issues.
- Status changed to Needs review
almost 2 years ago 9:15pm 1 February 2023 - Status changed to Needs work
almost 2 years ago 9:42pm 18 February 2023 - ๐บ๐ธUnited States smustgrave
Very very small change requested.
When I run the tests locally without the fix
testDefaultHeaders passes should it fail? - Status changed to Needs review
almost 2 years ago 6:37am 19 February 2023 - ๐จ๐ฆCanada gapple
Fixed the small issue, and removed the
X-UA-Compatible
from the existing header test, since it's no longer added by core.testDefaultHeaders()
should pass both before and after the change;testExistingHeaders()
should only pass after the change. - Status changed to RTBC
almost 2 years ago 3:50pm 19 February 2023 - ๐ฆ๐บAustralia larowlan ๐ฆ๐บ๐.au GMT+10
Adding review credit for @smustgrave
- ๐ฆ๐บAustralia larowlan ๐ฆ๐บ๐.au GMT+10
According to the documentation, there is only one possible value for X-Content-Type-Options, and that's
nosniff
Can you elaborate on the scenario where you need to set an alternative value?
Similarly for X-FRAME-OPTIONS there's only two options, SAMEORIGIN or DENY
If you switch it to DENY, you will break things like media library embedding of oembed videos.
Can you elaborate on the use-case for that change too?
- Status changed to Needs work
over 1 year ago 3:34am 31 March 2023 - ๐ฆ๐บAustralia larowlan ๐ฆ๐บ๐.au GMT+10
Putting back to needs work, pending response above, however I would expect we'd need to reverse the X-Content-Type-Options changes given that header only takes one possible value.
- Status changed to Needs review
over 1 year ago 9:05pm 4 April 2023 - ๐จ๐ฆCanada gapple
As I noted in the summary, the current code is unlikely to cause issues in practice since a module that wants to alter the value is likely to execute after core's handler and also replace the value set by core - core setting the
$replace
parameter is just incorrect for what the code intends to do. Were a module to be prioritized before core's event handler and also set the same value it would also result in a duplicate header, just with the same value twice.The values set in
FinishResponseSubscriber
are not changed by this issue (X-Frame-Options: SAMEORIGIN
is still the default set by core, as now tested byFinishResponseSubscriberTest::testDefaultHeaders()
), the test just sets them to different values to best ensure it is actually testing what's expected.The headers could just unconditionally set the header values by removing the
$replace
parameter value (like is done forContent-language
just before) - having the conditional just matches what appears to be the intent behind why the$replace
parameter was originally set. - Status changed to Needs work
over 1 year ago 8:17am 7 April 2023 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 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.
- Status changed to Needs review
over 1 year ago 8:54pm 7 April 2023 - ๐จ๐ฆCanada gapple
Fixed missing
parent:setUp()
in test that bot flagged. - Status changed to Needs work
over 1 year ago 11:59am 22 April 2023 - ๐ง๐ชBelgium borisson_ Mechelen, ๐ง๐ช
I found a super small code nitpick, but this change looks super solid otherwise. +1 for rtbc after that is fixed.
Great job on the test coverage, that looks great! david.muffley โ made their first commit to this issueโs fork.
- last update
about 1 year ago 29,674 pass - Status changed to RTBC
about 1 year ago 5:53am 20 October 2023 - last update
about 1 year ago 29,674 pass - last update
about 1 year ago 29,676 pass - last update
about 1 year ago 29,678 pass - last update
about 1 year ago 29,678 pass - last update
about 1 year ago 29,680 pass - last update
about 1 year ago 29,680 pass - last update
about 1 year ago 29,680 pass - last update
about 1 year ago 29,680 pass - last update
about 1 year ago 29,680 pass - last update
about 1 year ago 29,680 pass - last update
about 1 year ago 29,684 pass - last update
about 1 year ago 29,684 pass - last update
about 1 year ago 29,688 pass - last update
about 1 year ago 29,688 pass - last update
about 1 year ago 29,689 pass - last update
about 1 year ago 29,690 pass - last update
about 1 year ago 29,690 pass - last update
about 1 year ago 29,723 pass - last update
about 1 year ago 29,724 pass - last update
about 1 year ago 29,724 pass - last update
about 1 year ago 29,724 pass - last update
about 1 year ago 29,724 pass - last update
about 1 year ago 29,724 pass 58:03 53:34 Running- last update
about 1 year ago 29,724 pass - last update
about 1 year ago 29,724 pass - last update
about 1 year ago 29,724 pass - last update
about 1 year ago 29,724 pass - last update
about 1 year ago 29,724 pass - last update
about 1 year ago 29,724 pass - last update
about 1 year ago 29,724 pass - Status changed to Needs work
about 1 year ago 8:07am 22 December 2023 - ๐ฆ๐บAustralia larowlan ๐ฆ๐บ๐.au GMT+10
- ๐ฎ๐ณIndia Akhil Babu Chengannur
Akhil Babu โ made their first commit to this issueโs fork.
- ๐ฎ๐ณIndia Akhil Babu Chengannur
Akhil Babu โ changed the visibility of the branch 11.x to hidden.
- Merge request !5969Issues/3214208: FinishResponseSubscriber could create duplicate headers. โ (Closed) created by Akhil Babu
- ๐ฎ๐ณIndia Akhil Babu Chengannur
Akhil Babu โ changed the visibility of the branch 3214208-finishresponsesubscriber-could-create to hidden.
- Status changed to Needs review
12 months ago 7:21am 28 December 2023 - ๐ฎ๐ณIndia Akhil Babu Chengannur
Added the changes as per #35 and created a new merge request against 11.x branch
- Status changed to RTBC
12 months ago 5:32pm 28 December 2023 - ๐บ๐ธUnited States smustgrave
Appears feedback to only set X-Frame-Options is empty is addressed
- last update
12 months ago 29,724 pass -
larowlan โ
committed eb526a83 on 10.2.x
Issue #3214208 by gapple, Akhil Babu, larowlan, smustgrave:...
-
larowlan โ
committed eb526a83 on 10.2.x
-
larowlan โ
committed 208bb878 on 11.x
Issue #3214208 by gapple, Akhil Babu, larowlan, smustgrave:...
-
larowlan โ
committed 208bb878 on 11.x
-
larowlan โ
committed 73fb8860 on 10.2.x
Issue #3214208 by gapple, Akhil Babu, larowlan, smustgrave:...
-
larowlan โ
committed 73fb8860 on 10.2.x
-
larowlan โ
committed 354e46cb on 11.x
Issue #3214208 by gapple, Akhil Babu, larowlan, smustgrave:...
-
larowlan โ
committed 354e46cb on 11.x
- ๐ฆ๐บAustralia larowlan ๐ฆ๐บ๐.au GMT+10
Compared the two MRs
here's the diff
diff --git a/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php index 6d93ec91915..6fc54a38c00 100644 --- a/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php @@ -123,9 +123,7 @@ public function onRespond(ResponseEvent $event) { // different from the declared content-type, since that can lead to // XSS and other vulnerabilities. // https://owasp.org/www-project-secure-headers - if (!$response->headers->has('X-Content-Type-Options')) { - $response->headers->set('X-Content-Type-Options', 'nosniff'); - } + $response->headers->set('X-Content-Type-Options', 'nosniff'); if (!$response->headers->has('X-Frame-Options')) { $response->headers->set('X-Frame-Options', 'SAMEORIGIN'); } diff --git a/core/tests/Drupal/Tests/Core/EventSubscriber/FinishResponseSubscriberTest.php b/core/tests/Drupal/Tests/Core/EventSubscriber/FinishResponseSubscriberTest.php index 790c291c26e..a77403daf41 100644 --- a/core/tests/Drupal/Tests/Core/EventSubscriber/FinishResponseSubscriberTest.php +++ b/core/tests/Drupal/Tests/Core/EventSubscriber/FinishResponseSubscriberTest.php @@ -125,7 +125,8 @@ public function testExistingHeaders() { $finishSubscriber->onRespond($event); $this->assertEquals(['en'], $response->headers->all('Content-language')); - $this->assertEquals(['foo'], $response->headers->all('X-Content-Type-Options')); + // 'X-Content-Type-Options' will be unconditionally set by the core. + $this->assertEquals(['nosniff'], $response->headers->all('X-Content-Type-Options')); $this->assertEquals(['DENY'], $response->headers->all('X-Frame-Options')); }
Committed to 11.x and 10.2.x
Made a minor cleanup/grammar commit as follows:
diff --git a/core/tests/Drupal/Tests/Core/EventSubscriber/FinishResponseSubscriberTest.php b/core/tests/Drupal/Tests/Core/EventSubscriber/FinishResponseSubscriberTest.php index a77403daf41..f83951cc85a 100644 --- a/core/tests/Drupal/Tests/Core/EventSubscriber/FinishResponseSubscriberTest.php +++ b/core/tests/Drupal/Tests/Core/EventSubscriber/FinishResponseSubscriberTest.php @@ -125,7 +125,7 @@ public function testExistingHeaders() { $finishSubscriber->onRespond($event); $this->assertEquals(['en'], $response->headers->all('Content-language')); - // 'X-Content-Type-Options' will be unconditionally set by the core. + // 'X-Content-Type-Options' will be unconditionally set by core. $this->assertEquals(['nosniff'], $response->headers->all('X-Content-Type-Options')); $this->assertEquals(['DENY'], $response->headers->all('X-Frame-Options')); }
- Status changed to Fixed
12 months ago 8:58pm 28 December 2023 - ๐ง๐ชBelgium wim leers Ghent ๐ง๐ช๐ช๐บ
I bet this also fixed a bug reported against the BigPipe Sessionless module I maintain: ๐ Security headers are duplicated (X-UA-Compatible, X-Content-Type-Options, X-Frame-Options) Needs review .
Automatically closed - issue fixed for 2 weeks with no activity.