nextcloud / server

☁️ Nextcloud server, a safe home for all your data
https://nextcloud.com
GNU Affero General Public License v3.0
26.65k stars 3.99k forks source link

Lack of SFTP (SSH) Host Key Verification #14108

Open JunaidLoonat opened 5 years ago

JunaidLoonat commented 5 years ago

Connections to SFTP external storage were made without verifying the remote host's SSH host key.

This behaviour did not appear to be documented anywhere so that users may factor it into their decision to use the External Storage application for remote SFTP resources. This is important since a change of the remote host's SSH host key may indicate that a man-in-the-middle attack is in progress.

From the application logic, host key checking would only be performed if a "_sshhostKeys" file exists for the given user. However, this file was not created by default. Furthermore, the method "writeHostKeys()" would only update the list of SSH host keys if the user's "_sshhostKeys" file already existed.

To conclude, the verification logic does already exist within the current Nextcloud code base but is not used by default. I do recognise that the reason for this is because of the associated functionality that is presently missing such as the user's ability to manage their own "_sshhostKeys" file.

Steps to reproduce

  1. On Nextcloud, create a SFTP external storage as normal
  2. Through Nextcloud, access the files stored on the remote SFTP storage
  3. On the remote SSH host, change the SSH host key and restart the SSH service
  4. Through Nextcloud, once again access the files stored on the remote SFTP storage

Expected behaviour

The Nextcloud instance should alert the user with an error message stating "Host public key does not match known key". It should be noted that this message does actually appear if the user's "_sshHostKeys" file exists and contains a host key that differs the remote host's current one (i.e. verification has failed).

Actual behaviour

The Nextcloud instance permits the user to access the remote SFTP storage without any indication that the remote host's SSH host key has been changed.

Server configuration

Operating system: Ubuntu GNU/Linux 18.04.1 LTS

Web server: Apache 2.4.29-1ubuntu4.5

Database: MariaDB 10.1.34-0ubuntu0.18.04.1

PHP version: 7.2+60ubuntu1

Nextcloud version: 15.0.2

Updated from an older Nextcloud/ownCloud or fresh install: Fresh

Where did you install Nextcloud from: Official website archive

Signing status:

Signing status No errors have been found.

Are you using external storage, if yes which one: SFTP

Are you using encryption: No

Are you using an external user-backend, if yes which one: No

szaimen commented 3 years ago

I'm closing this issue due to inactivity. If this is still happening please make sure to upgrade to the latest version. After that, feel free to reopen.

danxuliu commented 2 months ago

This is still valid.

A few more details: