Error with security checks when nginx as reverse proxy to apache2
Steps to reproduce
When using the following nginx config: `server { listen 443 ssl http2; server_name cloud.example.com; ssl_certificate /etc/letsencrypt/live/cloud.example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/cloud.example.com/privkey.pem; ssl_trusted_certificate /etc/letsencrypt/live/cloud.example.com/chain.pem; add_header Strict-Transport-Security max-age=15768000; add_header X-Content-Type-Options nosniff; add_header X-XSS-Protection "1; mode=block"; add_header X-Frame-Options SAMEORIGIN; add_header X-Robots-Tag none; add_header Content-Security-Policy: "default-src 'none'; script-src 'self' 'unsafe-eval'; connect-src 'self'; img-src 'self' *; style-src 'self' 'unsafe-inline'"; add_header Public-Key-Pins 'pin-sha256="YLh1dUR9y6Kja30RrAn7JKnbQG/uEtLMkBgFF2Fuihg="; pin-sha256="sRHdihwgkaib1P1gxX8HFszlD+7/gTfNvuAybgLPNis="; max-age=5184000; includeSubDomains'; root /var/www/html/dummy; index index.html index.php; error_page 404 /index.html;
location ^~ / {
rewrite /owncloud/(.*) /$1 break;
proxy_pass http://owncloud.local:80/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Ssl on;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
}
}in conjunction with default apache .htaccess:
Curl reports this:
curl -s -D - https://cloud.example.com/core/img/logo-icon.svg -o /dev/null HTTP/1.1 200 OK Server: nginx Date: Tue, 23 Feb 2016 13:07:26 GMT Content-Type: image/svg+xml Content-Length: 2910 Connection: keep-alive Last-Modified: Mon, 21 Dec 2015 12:46:53 GMT ETag: "b5e-52767e228e940" Accept-Ranges: bytes Strict-Transport-Security: max-age=15768000 X-Content-Type-Options: nosniff X-XSS-Protection: 1; mode=block X-Frame-Options: SAMEORIGIN X-Robots-Tag: none Content-Security-Policy:: default-src 'none'; script-src 'self' 'unsafe-eval'; connect-src 'self'; img-src 'self' *; style-src 'self' 'unsafe-inline' Public-Key-Pins: pin-sha256="YLh1dUR9y6Kja30RrAn7JKnbQG/uEtLMkBgFF2Fuihg="; pin-sha256="sRHdihwgkaib1P1gxX8HFszlD+7/gTfNvuAybgLPNis="; max-age=5184000; includeSubDomains
But admin-page tells me the "X-XSS-Protection", "X-Content-Type-Options", "X-Robots-Tag" and "X-Frame-Options"-options are not set.
If I remove the settings from apache, but leave nginx this happens:
curl -s -D - https://cloud.example.com/core/img/logo-icon.svg -o /dev/null HTTP/1.1 200 OK Server: nginx Date: Tue, 23 Feb 2016 13:10:23 GMT Content-Type: image/svg+xml Content-Length: 2910 Connection: keep-alive Last-Modified: Mon, 21 Dec 2015 12:46:53 GMT ETag: "b5e-52767e228e940" Accept-Ranges: bytes Strict-Transport-Security: max-age=15768000 X-Content-Type-Options: nosniff X-XSS-Protection: 1; mode=block X-Frame-Options: SAMEORIGIN X-Robots-Tag: none Content-Security-Policy:: default-src 'none'; script-src 'self' 'unsafe-eval'; connect-src 'self'; img-src 'self' *; style-src 'self' 'unsafe-inline' Public-Key-Pins: pin-sha256="YLh1dUR9y6Kja30RrAn7JKnbQG/uEtLMkBgFF2Fuihg="; pin-sha256="sRHdihwgkaib1P1gxX8HFszlD+7/gTfNvuAybgLPNis="; max-age=5184000; includeSubDomains
Settings-page still complain about missing settings.
If I remove the settings from nginx, but leave apache this happens:
curl -s -D - https://cloud.example.com/core/img/logo-icon.svg -o /dev/null HTTP/1.1 200 OK Server: nginx Date: Tue, 23 Feb 2016 13:11:32 GMT Content-Type: image/svg+xml Content-Length: 2910 Connection: keep-alive Last-Modified: Mon, 21 Dec 2015 12:46:53 GMT ETag: "b5e-52767e228e940" Accept-Ranges: bytes Strict-Transport-Security: max-age=15768000 Content-Security-Policy:: default-src 'none'; script-src 'self' 'unsafe-eval'; connect-src 'self'; img-src 'self' *; style-src 'self' 'unsafe-inline' Public-Key-Pins: pin-sha256="YLh1dUR9y6Kja30RrAn7JKnbQG/uEtLMkBgFF2Fuihg="; pin-sha256="sRHdihwgkaib1P1gxX8HFszlD+7/gTfNvuAybgLPNis="; max-age=5184000; includeSubDomains
Notice that the headers are gone, and are not sendt to the client. Settings-page show "All Checks Passed". I guess #17613 is somewhat of relevance here, but the headers are not viewed twice (at least not to curl) - and when the double-headers are removed it is reported as working when it is not, and reported as not working when it is working.
Expected behaviour
Security headers should be applied on client if reported succesfull on settings-page
Actual behaviour
When reported working it is not working, when reported not working it is working.
Server configuration
Operating system: Debian 8 for frontend and backend Web server: nginx 1.9.10 reverse proxy, apache 2.4.10 backend Database: mysql 5.5.47 PHP version: 5.6.17 ownCloud version: (see ownCloud admin page) 8.2.2 Updated from an older ownCloud or fresh install: This was freshly installed when OC7 was released, but I recently moved the database (and reinstalled web-files) and then switched from using nginx as backend/frontend (no reverse proxy) too using nginx as proxy with apache as backend.
List of activated apps: Enabled:
- activity: 2.1.3
- calendar: 0.8.2
- contacts: 0.5.0.0
- files: 1.2.0
- files_external: 0.3.0
- files_pdfviewer: 0.7
- files_sharing: 0.7.0
- files_trashbin: 0.7.0
- files_versions: 1.1.0
- gallery: 14.2.0
- news: 7.1.2
- notifications: 0.1.0
- tasks: 0.8.1 Disabled:
- encryption
- external
- files_texteditor
- files_videoviewer
- firstrunwizard
- provisioning_api
- templateeditor
- user_external
- user_ldap
The content of config/config.php:
{ "system": { "instanceid": "oce15831dc7f", "passwordsalt": "_REMOVED SENSITIVE VALUE", "trusted_domains": [ "cloud.example.com" ], "datadirectory": "/mnt/owncloud/", "dbtype": "mysql", "version": "8.2.2.2", "dbname": "owncloud", "dbhost": "127.0.0.1", "dbtableprefix": "oc", "dbuser": "_REMOVED SENSITIVE VALUE", "dbpassword": "_REMOVED SENSITIVE VALUE", "installed": true, "theme": "", "filesystem_check_changes": "0", "maintenance": false, "forcessl": true, "3rdpartyroot": "/var/www/owncloud/", "3rdpartyurl": "/3rdparty", "overwrite.cli.url": "/", "overwritewebroot": "/", "overwriteprotocol": "https", "overwritehost": "cloud.example.com", "mail_smtpmode": "php", "logtimezone": "Europe/Copenhagen", "logfile": "/var/log/owncloud.log", "loglevel": "1", "log_authfailip": true, "mail_smtpname": "_REMOVED SENSITIVE VALUE", "mail_smtppassword": "_REMOVED SENSITIVE VALUE", "mail_from_address": "owncloud", "mail_domain": "cloud.example.com", "secret": "_REMOVED SENSITIVE VALUE_", "trashbin_retention_obligation": "auto", "memcache.local": "\OC\Memcache\APCu", "trusted_proxies": [ "10.0.1.19" ], "forwarded_for_headers": [ "HTTP_X_FORWARDED", "HTTP_X_FORWARDED_FOR" ] } }
Are you using external storage, if yes which one: local/smb/sftp/... Not directly, but datadir is set to /mnt/owncloud, and that folder is a smb-mount from my fileserver via fstab. Are you using encryption: yes/no no Are you using an external user-backend, if yes which one: LDAP/ActiveDirectory/Webdav/... no
Client configuration
Browser: Latest chrome Operating system: Win 10
Logs
Web server error log
[Tue Feb 23 13:08:07.786376 2016] [authz_core:error] [pid 18213] [client 10.0.1.19:41250] AH01630: client denied by server configuration: /var/www/owncloud/data/htaccesstest.txt [Tue Feb 23 13:09:23.292073 2016] [authz_core:error] [pid 13296] [client 10.0.1.19:41365] AH01630: client denied by server configuration: /var/www/owncloud/data/htaccesstest.txt [Tue Feb 23 13:10:00.900282 2016] [authz_core:error] [pid 13332] [client 10.0.1.19:41477] AH01630: client denied by server configuration: /var/www/owncloud/data/htaccesstest.txt [Tue Feb 23 13:10:22.156066 2016] [authz_core:error] [pid 13293] [client 10.0.1.19:41594] AH01630: client denied by server configuration: /var/www/owncloud/data/htaccesstest.txt [Tue Feb 23 13:30:09.845712 2016] [authz_core:error] [pid 13293] [client 10.0.1.19:41774] AH01630: client denied by server configuration: /var/www/owncloud/data/htaccesstest.txt [Tue Feb 23 13:30:22.312724 2016] [authz_core:error] [pid 13297] [client 10.0.1.19:41886] AH01630: client denied by server configuration: /var/www/owncloud/data/htaccesstest.txt [Tue Feb 23 13:35:39.276121 2016] [authz_core:error] [pid 13293] [client 10.0.1.19:42015] AH01630: client denied by server configuration: /var/www/owncloud/data/htaccesstest.txt [Tue Feb 23 13:43:24.701412 2016] [authz_core:error] [pid 13296] [client 10.0.1.19:42154] AH01630: client denied by server configuration: /var/www/owncloud/data/htaccesstest.txt [Tue Feb 23 13:44:23.677798 2016] [authz_core:error] [pid 13315] [client 10.0.1.19:42268] AH01630: client denied by server configuration: /var/www/owncloud/data/htaccesstest.txt [Tue Feb 23 13:46:13.600725 2016] [authz_core:error] [pid 13296] [client 10.0.1.19:42387] AH01630: client denied by server configuration: /var/www/owncloud/data/htaccesstest.txt
ownCloud log (data/owncloud.log)
{"reqId":"aEhyo9BNAMp0gGfiBWGu","remoteAddr":"","app":"cli","message":"Memcache \OC\Memcache\APCu not available for distributed cache","level":1,"time":"2016-02-23T13:45:01+01:00"} {"reqId":"aEhyo9BNAMp0gGfiBWGu","remoteAddr":"","app":"news","message":"Configuration value "simplePieCacheDuration" does not exist. Ignored value.","level":2,"time":"2016-02-23T13:45:01+01:00"} {"reqId":"AWFCRtqrUiu/DdgPhNEd","remoteAddr":"195.204.59.92","app":"news","message":"Configuration value "simplePieCacheDuration" does not exist. Ignored value.","level":2,"time":"2016-02-23T13:46:09+01:00"} {"reqId":"vfxoWWmJFfceDqEqk8RW","remoteAddr":"","app":"cli","message":"Memcache \OC\Memcache\APCu not available for local cache","level":1,"time":"2016-02-23T13:58:57+01:00"} {"reqId":"vfxoWWmJFfceDqEqk8RW","remoteAddr":"","app":"cli","message":"Memcache \OC\Memcache\APCu not available for distributed cache","level":1,"time":"2016-02-23T13:58:57+01:00"} {"reqId":"zTviJZNsFBfqi0gdQsC+","remoteAddr":"","app":"cli","message":"Memcache \OC\Memcache\APCu not available for local cache","level":1,"time":"2016-02-23T13:59:16+01:00"} {"reqId":"zTviJZNsFBfqi0gdQsC+","remoteAddr":"","app":"cli","message":"Memcache \OC\Memcache\APCu not available for distributed cache","level":1,"time":"2016-02-23T13:59:16+01:00"} {"reqId":"ynbVVHN0nj5gToAPC/RI","remoteAddr":"","app":"cli","message":"Memcache \OC\Memcache\APCu not available for local cache","level":1,"time":"2016-02-23T14:00:01+01:00"} {"reqId":"ynbVVHN0nj5gToAPC/RI","remoteAddr":"","app":"cli","message":"Memcache \OC\Memcache\APCu not available for distributed cache","level":1,"time":"2016-02-23T14:00:01+01:00"} {"reqId":"ynbVVHN0nj5gToAPC/RI","remoteAddr":"","app":"news","message":"Configuration value "simplePieCacheDuration" does not exist. Ignored value.","level":2,"time":"2016-02-23T14:00:01+01:00"}
Browser log
I dont know how to get any of these.
This seems like a setup related issue, please check owncloud.org/support for further references.
I can't see how it can be, when the headers are applied if I dont trust Owncloud's judgement?
There are no info regarding this here: https://doc.owncloud.com/server/8.0/admin_manual/configuration_server/reverse_proxy_configuration.html
Nor here: https://statuscode.ch/2015/05/security-and-owncloud-8.1/#security-related-headers-can-now-be-sent-by-the-web-server or here: https://doc.owncloud.com/server/8.1/admin_manual/configuration_server/harden_server.html
I'm not saying I'm wrong here, but at least I want to know what documentation I didn't read, because I cant find anything related except for double-headers, and that's not the case here.
Please post the link to your ownCloud.
https://cloud.ralin.org/
As I said, configuration problem on your side.


This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.