add_header X-Frame-Options SAMEORIGIN is added somewhere in NextCloud 13
Steps to reproduce
In the whole /etc/nginx it is only just one place where is:
if ( $x_frame_options = "") {
set $x_frame_options "SAMEORIGIN";
}
ssl on;
#gzip off;
#add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header Strict-Transport-Security "max-age=31536000; " always;
add_header X-Frame-Options $x_frame_options;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
Expected behaviour
On my server it is right and every web sites, like this:

Actual behaviour
But in NextCloud 13 somewhere it adds in itself and because it adds 2 times for sure and is not NGINX or PHP, because I can show you many pictures, that is right:

Actually, I only use in /etc/nginx so it not anywhere, I look for, and I only there in NGINX:
root@server:/etc/nginx# find -type f | xargs egrep -i x-frame-options
./default-ssl-base.conf:add_header X-Frame-Options $x_frame_options;
So only once!
Server configuration
Operating system:
Linux server 4.12.0-2-amd64 #1 SMP Debian 4.12.13-1 (2017-09-19) x86_64 GNU/Linux
Web server:
nginx/1.13.8
Database:
mariadb Ver 15.1 Distrib 10.1.29-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
PHP version:
PHP 7.2.1-1 (cli) (built: Jan 5 2018 11:21:04) ( NTS )
Nextcloud version: (see Nextcloud admin page)
13
Actually I found this:
lib/private/legacy/response.php: header('X-Frame-Options: SAMEORIGIN'); // Disallow iFraming from other domains
If I remove this code, then my Nginx works, but it places dual headers and it senses that my config is wrong.
lib/private/legacy/response.php line 262. that is the bug
This is the actual bug (i commented and now all warning removed):


This is the actual bug (i commented and now all warning removed):
We don't support that this is set by the web server. The Nginx should not add this header. Fro your point in the call route we are not able to detect if it will be added by the web server or not and thus we add it there because this then needs fewer tweaking of the webserver itself.
This is thus not a bug but an enhancement to also support web servers that somehow set it.
See also #4605, #4863, #5246
Some headers are set in PHP, some are set in .htaccess/nginx. This inconsistency is really bad.
I found them on three different locations: https://github.com/nextcloud/server/blob/da6c2c9da1721de7aa05b15af1356e3511069980/lib/private/legacy/response.php#L251-L272 https://github.com/nextcloud/documentation/blob/b7dec9a1cab21cf637914073b096eeda44608f1c/admin_manual/installation/nginx.rst#nextcloud-in-the-webroot-of-nginx https://github.com/nextcloud/documentation/blob/b7dec9a1cab21cf637914073b096eeda44608f1c/admin_manual/configuration_server/harden_server.rst#serve-security-related-headers-by-the-web-server
Things are even worse if you run NextCloud behind a reverse proxy. The headers in the PHP file are not really customizable. I would prefer setting them only in the server config and display a warning in the setup check.
@MorrisJobke Yeah, it says add it in NGINX, then you tell me to remove from NGINX. so which one we should use??? I think server settings is better, what do you think?
Right now it is chaos.
@J0WI yeah, exactly, what i mean, you cought it!
From a security perspective it also makes more scene to add security settings in the server config, which is harder to hijack in the case of a possible vulnerability in the PHP app.
Edit: And the webserver is also able to set the security headers if PHP is broken for whatever reason.
@J0WI Server is better, but if you want to use PHP, you should comment properly, i think, but of course, we cannot document, and code and fix and etc at once. So understand. I will remove the NGINX settings and I purely set it up for PHP, that's the best right? Like add modHeadersAvailable to the ENV. That's in done on PHP without NGINX or APACHE.
@p3x-robot you can also use proxy_hide_header or fastcgi_hide_header in your nginx config to hide the headers set by PHP:
proxy_hide_header X-Content-Type-Options;
fastcgi_hide_header X-XSS-Protection;
well, i just change my server, removed that and that's it. :) it works, awesome. THANKS!
The biggest problem with that is that also there are users, that can't configure this in the webserver because they use a shared hoster. We try to make it as easy as possible for everybody :/ And sorry for the mess.
Could you open a ticket (or even better a PR) in the documentation repo to give hints for this setting in the web server, @J0WI?
@MorrisJobke i just uncommeted that i hacked:
lib/private/legacy/response.php: header('X-Frame-Options: SAMEORIGIN'); // Disallow iFraming from other domains line 262 and i removed the X-Frame-Options from NGINX and then it works.
If now Nextcloud 13 works like this, of course we have ot upgrade and update our nginx server settings,
That's all, Now pass all checks...
The biggest problem with that is that also there are users, that can't configure this in the webserver because they use a shared hoster.
@MorrisJobke shared hoster tend to allow .htaccess (which is also shipped with NextCloud).
I can open a PR for the docs, but for me it's just a workaround. The issue is that headers are set by PHP (which is not really secure) and are not customizable.
Is there a way for a php script to test if the headers are set by the webserver? So that php only adds them if they are not set via webserver. We could enable them by default and provide a configuration switch in case you can activate it on the webserver (the developers probably won't like to add another configuration option).