Skip to content

Commit bcc49fb

Browse files
committed
Update X-XSS-Protection recommendation
While `1; mode=block` was seen as the most secure value for this header, some years ago, after possible side-channel attacks have become known, this turned towards `0` being the best-practice value, disabling XSS filtering entirely for those old browsers who still support it. MDN web docs give some explanation: https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-XSS-Protection#security_considerations The OWASP cheat sheet recommends `0`: https://cheatsheetseries.owasp.org/cheatsheets/HTTP_Headers_Cheat_Sheet.html#x-xss-protection Here the related discussion when this recommendation was updated: OWASP/CheatSheetSeries#376 A Stack Overflow question underlines the clear recommendation, adding some more details: https://stackoverflow.com/questions/9090577 Since `1; mode=block` is not a large security risk, it affects only very old browsers, not supported by Nextcloud anyway, AFAIK, and a changed recommendation will (sadly) trigger a lot of issues/topics in forum and GitHub, the old value however is allowed to pass the check. So to pass the check, either page blocking needs to be enabled along with XSS filtering, or XSS filtering needs to be disabled. The warning however will always suggest to disable it. Signed-off-by: MichaIng <micha@dietpi.com>
1 parent ce10828 commit bcc49fb

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

apps/settings/lib/SetupChecks/SecurityHeaders.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ public function run(): SetupResult {
7373
}
7474

7575
$xssFields = array_map('trim', explode(';', $response->getHeader('X-XSS-Protection')));
76-
if (!in_array('1', $xssFields) || !in_array('mode=block', $xssFields)) {
77-
$msg .= $this->l10n->t('- The `%1$s` HTTP header does not contain `%2$s`. This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.', ['X-XSS-Protection', '1; mode=block']) . "\n";
76+
if (!in_array('1', $xssFields) || !in_array('mode=block', $xssFields) and !in_array('0', $xssFields)) {
77+
$msg .= $this->l10n->t('- The `%1$s` HTTP header does not contain `%2$s`. This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.', ['X-XSS-Protection', '0']) . "\n";
7878
}
7979

8080
$referrerPolicy = $response->getHeader('Referrer-Policy');

apps/settings/tests/SetupChecks/SecurityHeadersTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function testSomeHeadersMissing(): void {
8484

8585
$result = $this->setupcheck->run();
8686
$this->assertEquals(
87-
"Some headers are not set correctly on your instance\n- The `X-Content-Type-Options` HTTP header is not set to `nosniff`. This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.\n- The `X-XSS-Protection` HTTP header does not contain `1; mode=block`. This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.\n",
87+
"Some headers are not set correctly on your instance\n- The `X-Content-Type-Options` HTTP header is not set to `nosniff`. This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.\n- The `X-XSS-Protection` HTTP header does not contain `0`. This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.\n",
8888
$result->getDescription()
8989
);
9090
$this->assertEquals(SetupResult::WARNING, $result->getSeverity());
@@ -94,7 +94,7 @@ public static function dataSuccess(): array {
9494
return [
9595
// description => modifiedHeaders
9696
'basic' => [[]],
97-
'extra-xss-protection' => [['X-XSS-Protection' => '1; mode=block; report=https://example.com']],
97+
'extra-xss-protection' => [['X-XSS-Protection' => '0; report=https://example.com']],
9898
'no-space-in-x-robots' => [['X-Robots-Tag' => 'noindex,nofollow']],
9999
'strict-origin-when-cross-origin' => [['Referrer-Policy' => 'strict-origin-when-cross-origin']],
100100
'referrer-no-referrer-when-downgrade' => [['Referrer-Policy' => 'no-referrer-when-downgrade']],
@@ -113,7 +113,7 @@ public static function dataSuccess(): array {
113113
public function testSuccess(array $headers): void {
114114
$headers = array_merge(
115115
[
116-
'X-XSS-Protection' => '1; mode=block',
116+
'X-XSS-Protection' => '0',
117117
'X-Content-Type-Options' => 'nosniff',
118118
'X-Robots-Tag' => 'noindex, nofollow',
119119
'X-Frame-Options' => 'SAMEORIGIN',
@@ -140,8 +140,8 @@ public static function dataFailure(): array {
140140
return [
141141
// description => modifiedHeaders
142142
'x-robots-none' => [['X-Robots-Tag' => 'none'], "- The `X-Robots-Tag` HTTP header is not set to `noindex,nofollow`. This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.\n"],
143-
'xss-protection-1' => [['X-XSS-Protection' => '1'], "- The `X-XSS-Protection` HTTP header does not contain `1; mode=block`. This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.\n"],
144-
'xss-protection-0' => [['X-XSS-Protection' => '0'], "- The `X-XSS-Protection` HTTP header does not contain `1; mode=block`. This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.\n"],
143+
'xss-protection-1' => [['X-XSS-Protection' => '1'], "- The `X-XSS-Protection` HTTP header does not contain `0`. This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.\n"],
144+
'xss-protection-0' => [['X-XSS-Protection' => 'mode=block'], "- The `X-XSS-Protection` HTTP header does not contain `0`. This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.\n"],
145145
'referrer-origin' => [['Referrer-Policy' => 'origin'], "- The `Referrer-Policy` HTTP header is not set to `no-referrer`, `no-referrer-when-downgrade`, `strict-origin`, `strict-origin-when-cross-origin` or `same-origin`. This can leak referer information. See the {w3c-recommendation}.\n"],
146146
'referrer-origin-when-cross-origin' => [['Referrer-Policy' => 'origin-when-cross-origin'], "- The `Referrer-Policy` HTTP header is not set to `no-referrer`, `no-referrer-when-downgrade`, `strict-origin`, `strict-origin-when-cross-origin` or `same-origin`. This can leak referer information. See the {w3c-recommendation}.\n"],
147147
'referrer-unsafe-url' => [['Referrer-Policy' => 'unsafe-url'], "- The `Referrer-Policy` HTTP header is not set to `no-referrer`, `no-referrer-when-downgrade`, `strict-origin`, `strict-origin-when-cross-origin` or `same-origin`. This can leak referer information. See the {w3c-recommendation}.\n"],
@@ -157,7 +157,7 @@ public static function dataFailure(): array {
157157
public function testFailure(array $headers, string $msg): void {
158158
$headers = array_merge(
159159
[
160-
'X-XSS-Protection' => '1; mode=block',
160+
'X-XSS-Protection' => '0',
161161
'X-Content-Type-Options' => 'nosniff',
162162
'X-Robots-Tag' => 'noindex, nofollow',
163163
'X-Frame-Options' => 'SAMEORIGIN',

0 commit comments

Comments
 (0)