Skip to content

Remove XSS-Protection header from Nginx configs #9188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

minecrawler
Copy link
Contributor

By now, no modern browser supports the XSS-Protection header anymore - and with good reason. It actually has known security vulnerabilities. Instead, it is recommended to disable it and use CSP instead. See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-XSS-Protection

Hence, this patch disables the XSS header and enables CSP instead. The CSP part was copied from an earlier PR (#1714), which was closed because of an incompatible browser matrix. That issue does not exist anymore. Is it possible to merge these changes?

@HLFH
Copy link

HLFH commented Dec 8, 2022

It would be great to merge the first commit.

For the second commit, as Nextcloud devs said in the previous PR: they set the CSP from Nextcloud.
And removing the X-Frame-Options depends quite from this issue: nextcloud/server#34748

@minecrawler
Copy link
Contributor Author

I can reverse the second commit and rebase the changes, if that's what it takes.

Also, if this commit still needs other changes (like the check for the presence of the header), please tell me what and where and I can add it :)

@HLFH
Copy link

HLFH commented Dec 8, 2022

For the first commit, this code should be updated I think: https://github.com/nextcloud/server/blob/master/core/js/setupchecks.js

				var xssfields = xhr.getResponseHeader('X-XSS-Protection') ? xhr.getResponseHeader('X-XSS-Protection').split(';').map(function(item) { return item.trim(); }) : [];
				if (xssfields.length === 0 || xssfields.indexOf('1') === -1 || xssfields.indexOf('mode=block') === -1) {
					messages.push({
						msg: t('core', 'The "{header}" HTTP header does not contain "{expected}". This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.',
							{
								header: 'X-XSS-Protection',
								expected: '1; mode=block'
							}),
						type: OC.SetupChecks.MESSAGE_TYPE_WARNING
					});
				}

That would be necessary before updating the nginx documentation for Nextcloud.

@iasdeoupxe
Copy link

iasdeoupxe commented Jun 13, 2025

@MichaIng MichaIng force-pushed the feature/disable-xss-header branch from 05c3010 to 38e3885 Compare June 28, 2025 15:38
@MichaIng MichaIng added this to the Nextcloud 32 milestone Jun 28, 2025
Copy link
Member

@MichaIng MichaIng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking until nextcloud/server#53476 has been merged, but this is the complementary needed docs part then.

I hope no one has a problem with me adjusting and squashing the commits:

  • While disabling XSS explicitly is safe as well, I think it makes more sense to remove and forget this header completely. OWASP recommends to do either of both. For more details see the server PR.
  • CSP should not be set at webserver level: It would overwrite or duplicate what Nextcloud sets in PHP already, hence can break things or weaken security. CSP, the way it is designed with very selective permissions all as single header value, needs to be set in the backend as individually. There is no generic safe but functional value that could be applied on webserver level for the whole site.

@MichaIng MichaIng changed the title Disable xss header and add CSP header Remove XSS-Protection header from Nginx configs Jun 28, 2025
@MichaIng MichaIng force-pushed the feature/disable-xss-header branch from 7d38893 to 74dbee7 Compare June 30, 2025 19:57
Comment on lines +8 to +9
* PHP 8.1 is now deprecated but still supported.
* PHP 8.4 is now supported, but 8.3 is recommended.
Copy link
Member

@MichaIng MichaIng Jun 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Co-authored-by: Joas Schilling <[email protected]>
Signed-off-by: MichaIng <[email protected]>
@nickvergessen nickvergessen merged commit 9c61155 into nextcloud:master Jul 1, 2025
13 checks passed
Copy link

welcome bot commented Jul 1, 2025

Thanks for your first pull request and welcome to the community! Feel free to keep them coming! If you are looking for issues to tackle then have a look at this selection: https://github.com/nextcloud/documentation/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22

@minecrawler minecrawler deleted the feature/disable-xss-header branch July 1, 2025 23:42
@Patta
Copy link

Patta commented Jul 23, 2025

@minecrawler Shouldn't the header also be removed in the rules under # Serve static files?

add_header X-XSS-Protection "1; mode=block" always;

In addition, the version in the line 1 is outdated.

@minecrawler
Copy link
Contributor Author

@Patta well, it's a 3(!) years old PR and it's merged, now. So if there's potential for improvement, we should create a new PR and hope it's merged quicker

@MichaIng
Copy link
Member

Absolutely, that was an oversight. I will create a followup PR just now 🙂.

MichaIng added a commit that referenced this pull request Jul 23, 2025
It was removed from the config in #9188, but forgotten for the static assets block.

In addition, the date added with #12100 was is added to the subdir config as well, for consistency.

Signed-off-by: MichaIng <[email protected]>
@MichaIng
Copy link
Member

MichaIng commented Jul 23, 2025

#13445

In addition, the version in the line 1 is outdated.

Or shall we call it the "RIP Ozzy 🤘" version of the Nginx config? 😢🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants