"CSRF check failed" and linkToRouteAbsolute
Steps to reproduce
- Install a NextCloud 12 instance behind a reverse proxy (Apache or else). The internal link must be HTTP, the external link HTTPS, and the RP must redirect any incoming HTTP request to its HTTPS equivalent.
- Log in
- Log out. :)
Expected behaviour
The user should be logged out.
Actual behaviour
The user gets a "CSRF check failed" error.
Server configuration
Operating system: Ubuntu Linux 16.04
Web server: Apache 2.4.18
Database: MySQL 5.7.18
PHP version: 7.0
Nextcloud version: (see Nextcloud admin page) 12
Updated from an older Nextcloud/ownCloud or fresh install: Fresh install
Where did you install Nextcloud from: https://nextcloud.com/
Signing status:
Signing status
Login as admin user into your Nextcloud and access
http://example.com/index.php/settings/integrity/failed
paste the results here.
List of activated apps:
App list
$ php occ app:list Enabled: - activity: 2.5.2 - admin_audit: 1.2.0 - calendar: 1.5.3 - comments: 1.2.0 - dav: 1.3.0 - federatedfilesharing: 1.2.0 - federation: 1.2.0 - files: 1.7.2 - files_pdfviewer: 1.1.1 - files_sharing: 1.4.0 - files_texteditor: 2.4.1 - files_trashbin: 1.2.0 - files_versions: 1.5.0 - files_videoplayer: 1.1.0 - firstrunwizard: 2.1 - gallery: 17.0.0 - logreader: 2.0.0 - lookup_server_connector: 1.0.0 - nextcloud_announcements: 1.1 - notifications: 2.0.0 - oauth2: 1.0.5 - password_policy: 1.2.2 - provisioning_api: 1.2.0 - serverinfo: 1.2.0 - sharebymail: 1.2.0 - survey_client: 1.0.0 - systemtags: 1.2.0 - theming: 1.3.0 - twofactor_backupcodes: 1.1.1 - updatenotification: 1.2.0 - user_ldap: 1.2.1 - workflowengine: 1.2.0 Disabled: - encryption - files_external - user_externalNextcloud configuration:
Config report
$ php occ config:list system { "system": { "instanceid": "ocuyub8lv58i", "passwordsalt": "***REMOVED SENSITIVE VALUE***", "secret": "***REMOVED SENSITIVE VALUE***", "trusted_domains": [ "www.xxxxxxx.fr" ], "datadirectory": "\/var\/www\/nextcloud\/data", "overwrite.cli.url": "http:\/\/www.xxxxxxx.fr\/nextcloud", "dbtype": "mysql", "version": "12.0.0.29", "dbname": "nextcloud", "dbhost": "mysql", "dbport": "", "dbtableprefix": "oc_", "dbuser": "***REMOVED SENSITIVE VALUE***", "dbpassword": "***REMOVED SENSITIVE VALUE***", "installed": true, "ldapIgnoreNamingRules": false, "ldapProviderFactory": "\\OCA\\User_LDAP\\LDAPProviderFactory" } }Are you using external storage, if yes which one: local/smb/sftp/... no
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: Chrome 54
Operating system: Ubuntu Linux 16.10
The above problem seems to be due to the fact that the "log out" link is absolute (to the NextCloud instance), so it is http:// and not https://, as it should have been when seen from outside (behind the reverse proxy).
This seems to be linked to the way the "log out" link is formed, in the file "lib/private/NavigationManager.php", around line 190:
// Logout
$this->add([
'type' => 'settings',
'id' => 'logout',
'order' => 99999,
'href' => $this->urlGenerator->linkToRouteAbsolute(
'core.login.logout',
['requesttoken' => \OCP\Util::callRegister()]
),
'name' => $l->t('Log out'),
'icon' => $this->urlGenerator->imagePath('core', 'actions/logout.svg'),
]);
The link is formed via a call to the "linkToRouteAbsolute" function, contrary to the other ones in the same file, which are formed via the "linkToRoute" function.
Changing the call from "linkToRouteAbsolute" to "linkToRoute" fixes the bug, but I'm not sure this is the right way to deal with that problem, as if the "linkToRouteAbsolute" is used, there may well be a good reason... ;-)
Duplicate of #1075 and let me open a PR.