Improper integrity protection of server-side encryption keys
The public keys used for server-side encryption are not integrity-protected, so anyone with access to the data-at-rest storage can replace them with their own keys. This allows the attacker to read and modify newly created or modified files, even without administrative access to the Nextcloud server.
Originally disclosed on HackerOne
- Triaged in 17 days
- Fixed in 11 months
- Disclosed after 12 months
The public keys used for the server-side encryption are not integrity-protected. These can easily replaced by anyone who has access to the data-at-rest data (even when the per-user-keys are enabled, as described in https://nextcloud.com/security/threat-model/). This holds true for all key types - from the master key, the per-user-keys as well as for the (optional) recovery key.
Attack scenarios may look like this:
- A recovery key is set by the admin and users enabled the recovery feature (or it was mandatorily set by adding the corresponding configuration to the
oc_preferencestable for all users). As it is unlikely that the recovery key is used very often, a person that has access to the data directory (even if at rest) is able to replace the public recovery key with a newly generated one. Each newly added file and each modified file will also be encrypted for the newly generated recovery key. - A per-user-key encryption scheme is introduced and organizational shared folders are set up. To better handle access management all organizational shared folders are owned by the admin that also handles access management requests. As it is unlikely that the admin account will be used to access the individual files, a person that has access to the data directory (even if at rest) is able to replace the public key of the admin account with a newly generated one. Each newly added file and each modified file that is put into any of the organizational shared folders will also be encrypted for the newly generated admin account key.
The mentioned attack scenarios may also be executed by an external storage provider if the folder that is used as the data directory is stored at this external storage provider. Administrative access to the actual Nextcloud server is not necessary to mount this attack.
Impact
After mounting the attack the person would be able to read and modify all newly created files as well as files that have been modified since the attack was launched.
Preventing this attack could look as follows:
- The fingerprints of public and private key files that have been generated by the application could be stored in the database.
- Whenever public or private key files are read from disk the fingerprint of that file is checked against the value stored in the database.
An alternative approach for preventing this attack could look as follows:
- For each public and private key file that has been generated by the application a MAC could be calculated.
- The key for the MAC could be derived from the instance id, the instance secret and the relative file name of the corresponding key file.
- The MAC could be stored directly in the corresponding key file.
- Whenever a public or private key file is read from disk the MAC of that file could be calculated and compared with the MAC stored in the file.
Attachments
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The public keys used for server-side encryption are stored without any integrity protection, so they can be replaced by anyone with access to the data directory.
Impact
An attacker with access to the data-at-rest storage could read and modify all newly created files and files modified after the attack, without needing administrative access to the Nextcloud server.
What the attacker needed
Access to data-at-rest storage; no admin access to Nextcloud needed
The fix
The report suggests preventing the attack by storing fingerprints or MACs of key files and checking them whenever keys are read from disk.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Nextcloud encrypts files on the server using public keys. If someone can access the stored data (like a backup or external storage), they can swap those public keys with their own. Then any new or changed files get encrypted with the attacker's key, letting them read or alter those files.
What is Crypto?
Encryption, signatures, randomness or certificate checks that do not protect what they claim to.