Lack of SFTP (SSH) Host Key Verification
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 36.9k
- Forks
- 5.2k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 713
Description
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 "ssh_hostKeys" 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 "ssh_hostKeys" 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 "ssh_hostKeys" file.
Steps to reproduce
- On Nextcloud, create a SFTP external storage as normal
- Through Nextcloud, access the files stored on the remote SFTP storage
- On the remote SSH host, change the SSH host key and restart the SSH service
- 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 "ssh_HostKeys" 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with apps/files_external/lib/Lib/Storage/SFTP.php, especially the existing host-key checking logic and _writeHostKeys(). Trace why the user's ssh_hostKeys file is not created or updated by default, then review the missing user-management functionality. Done means changed remote host keys produce the documented "Host public key does not match known key" error instead of allowing access silently.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend, security
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100