Android app does not clear end to end encryption keys
The Android app does not delete end-to-end encryption keys and the mnemonic when a user removes their account from the device. An attacker who obtains the device and logs into the victim's account can access all encrypted files.
- Disclosed after 39 days
- userA on serverA sets up end to end encryption on their android device
- userA has some end to end encrypted data
- userA removes their account on serverA from their android device (for whatever reason)
- attacker (evil admin) obtains the device of userA
- attacker (evil admin) logs in on the account of userA (reset the pw and just log in)
- attacker (evil admin) can see and access all encrypted files
Impact
While I believe the impact is minimal since you need to obtain the device of the victim. Once you remove your account all information regarding that account should be removed.
- the keys
- the mnemonic
And certainly when you re-add an account you should be asked to enter your mnemonic!
What the report shows
The target is the Nextcloud Android client, com.nextcloud.client, and the feature under scrutiny is end to end encryption. The researcher, rtod, reported the issue through HackerOne, and it was disclosed on 16 June 2021 with a low severity rating and a 100.00 USD bounty.
The finding is about what the app leaves behind on the device after an account is removed. The researcher's reproduction is short and entirely device-side:
- userA on serverA sets up end to end encryption on their Android device.
- userA has some end to end encrypted data.
- userA removes their account on serverA from their Android device (for whatever reason).
- The attacker (an evil admin) obtains the device of userA.
- The attacker logs in on the account of userA, resetting the password and logging in.
- The attacker can see and access all encrypted files.
The report does not include any request, payload, command or log output, so there is nothing to reproduce verbatim beyond the numbered steps above. It also does not describe a fix, a patch or a vendor response.
Root cause
The report argues that account removal should also delete the keys and the mnemonic, and that re-adding an account should require the mnemonic. The report's concern is that leftover key material would let a later login decrypt the files without a mnemonic prompt. The report frames the missing prompt as part of the problem: re-adding an account should require the mnemonic to be entered.
Impact
The researcher is explicit that the impact is minimal, because the attacker first has to obtain the victim's device. Given that precondition, an attacker who can log in to the victim's account on that device, including by resetting the password, can read and access all of the end to end encrypted files. The researcher rates the impact minimal because the attacker must first obtain the victim's device.
The report does not assign a CVSS score or a weakness category, and the platform record lists neither.
How this kind of bug works
End to end encryption in a client app depends on secrets that live on the device: a private key or key pair, and usually a recovery phrase (mnemonic) from which keys can be derived or restored. The server stores ciphertext and cannot read it. The security of the scheme therefore rests on the client keeping those secrets under the user's control.
A common failure is lifecycle mismatch. The account record, its sync configuration and its cached files are treated as one unit that is deleted when the user removes the account, while the cryptographic material is stored in a separate keystore, preferences file or database that the deletion path does not touch. The result is orphaned secrets: the user believes the account and its data are gone, but the keys remain and will silently be reused the next time the same account is added.
This matters because removal of an account is often a security action. A user may remove an account precisely because the device is being sold, shared or lost. If the keys survive, the protection the user expected from removal does not exist. Requiring the mnemonic when an account is re-added restores an authentication step that the leftover keys otherwise bypass.
Defences are straightforward in principle: delete all key material and the mnemonic as part of account removal, store secrets in a location that is bound to the account entry, and require the mnemonic (or a fresh key setup) whenever an encrypted account is added to a device that does not already hold a validated session.
How to test for it
This class of bug is tested by observing what persists on the device across account lifecycle events.
- Set up the encrypted account on a test device and create or receive at least one encrypted file so that keys are definitely in use.
- Remove the account from the app through the normal user-facing flow.
- Inspect the app's private storage for residual secrets: shared preferences, SQLite databases, keystore entries, files under the app's data directory. On a rooted device or an emulator with debugging enabled, pull the app data directory and search for key blobs, mnemonic words and account identifiers.
- Re-add the same account and observe whether the app asks for the mnemonic or silently decrypts existing files.
- A positive result is either key material still present after removal, or decryption succeeding after re-adding the account without any mnemonic challenge.
Common false positives: cached ciphertext or plaintext file listings that contain no key material; OS-level keystore entries that are invalidated on uninstall but not on account removal (check which event you are testing); and values that look like keys but are public parameters or nonces. Confirm that what remains can actually decrypt data, rather than assuming from a filename or a string match.
How it is fixed
Account removal should be treated as a destructive operation for all account-scoped state. The fix is to delete the private keys and the stored mnemonic in the same code path that removes the account, and to verify that no other store retains them. Where keys are kept in platform keystores, the entries should be removed explicitly rather than left to be garbage collected. On re-adding an encrypted account, the app should require the mnemonic or a fresh key exchange before granting access to existing encrypted content, so that possession of the device alone is not sufficient.
Hunting notes
Bugs of this shape hide in client apps with local cryptographic state: encrypted note and file sync clients, password managers, messaging apps and backup tools. The signal to look for is a separation between the account configuration and the key store, visible in the app's storage layout or in how the removal flow is implemented. Mobile clients are a good starting point because app data directories are easy to inspect on a rooted device or emulator.
A short numbered reproduction with the device state before and after removal is more persuasive than a description of the storage layout alone. Where the impact depends on device possession, say so up front; programs are more likely to accept a clearly scoped low-severity finding than an overstated one.
What happened, in plain words
Nextcloud is a product for storing and sharing files on a server that you or your organisation runs. The Android app, com.nextcloud.client, is the phone client for it. One of its features is end to end encryption: files are scrambled on the phone before they are uploaded, and only the phone holds the material needed to unscramble them. The server only ever stores the scrambled version, so even the server operator cannot read the files.
The researcher, rtod, reported this issue through HackerOne. It was disclosed on 16 June 2021, rated low severity, with a 100.00 USD bounty. The report does not give a CVSS score or a weakness category.
The finding is about what the app leaves behind on the phone after the user removes their account. The reproduction is short and happens entirely on the device:
- userA on serverA sets up end to end encryption on their Android device.
- userA has some end to end encrypted data.
- userA removes their account on serverA from their Android device (for whatever reason).
- The attacker (an evil admin) obtains the device of userA.
- The attacker logs in on the account of userA (resets the password and just logs in).
- The attacker can see and access all encrypted files.
Step 1 matters because it is what creates the secret material on the phone in the first place. Step 2 makes sure there is real encrypted content to protect. Step 3 is the security action: the user expects that removing the account also removes everything tied to it. Step 4 is the precondition the researcher is honest about: the attacker needs the physical device. Step 5 is how the attacker gets into the account: resetting the password and logging in. Step 6 is the consequence: the attacker can see and access all encrypted files.
The report contains no request, payload, command or log output, so there is nothing to copy verbatim beyond the numbered steps above. It also does not describe a fix, a patch or a vendor response.
Why it happens
The report points to account removal not being a complete cleanup. The researcher says that once an account is removed, the keys and the mnemonic should be removed too. A mnemonic is a list of words from which the encryption keys can be rebuilt, a bit like a spare key kept in a drawer. The report's concern is that leftover key material would let a later login decrypt the files without a mnemonic prompt. The report frames the missing prompt as part of the problem: re-adding an account should require the mnemonic to be entered.
Impact
The researcher is explicit that the impact is minimal, because the attacker first has to obtain the victim's device. Given that precondition, an attacker who can log in to the victim's account on that device, including by resetting the password, can read and access all of the end to end encrypted files. The researcher rates the impact minimal because the attacker must first obtain the victim's device.
In general, how this kind of bug works
End to end encryption in a client app depends on secrets that live on the device: a private key or key pair, and usually a recovery phrase (mnemonic) from which keys can be derived or restored. The server stores ciphertext, meaning scrambled data, and cannot read it. The security of the scheme therefore rests on the client keeping those secrets under the user's control.
A common failure is a lifecycle mismatch. The account record, its sync configuration and its cached files are treated as one unit that is deleted when the user removes the account, while the cryptographic material sits in a separate keystore, preferences file or database that the deletion path does not touch. The result is orphaned secrets: the user believes the account and its data are gone, but the keys remain and will silently be reused the next time the same account is added.
This matters because removal of an account is often a security action. A user may remove an account precisely because the device is being sold, shared or lost. If the keys survive, the protection the user expected from removal does not exist. Requiring the mnemonic when an account is re-added restores an authentication step that the leftover keys otherwise bypass.
Defences are straightforward in principle: delete all key material and the mnemonic as part of account removal, store secrets in a location that is bound to the account entry, and require the mnemonic (or a fresh key setup) whenever an encrypted account is added to a device that does not already hold a validated session.
In general, how to test for it
This class of bug is tested by observing what persists on the device across account lifecycle events.
- Set up the encrypted account on a test device and create or receive at least one encrypted file so that keys are definitely in use.
- Remove the account from the app through the normal user-facing flow.
- Inspect the app's private storage for residual secrets: shared preferences, SQLite databases, keystore entries, files under the app's data directory. On a rooted device or an emulator with debugging enabled, pull the app data directory and search for key blobs, mnemonic words and account identifiers.
- Re-add the same account and observe whether the app asks for the mnemonic or silently decrypts existing files.
- A positive result is either key material still present after removal, or decryption succeeding after re-adding the account without any mnemonic challenge.
Common false positives: cached ciphertext or plaintext file listings that contain no key material; OS-level keystore entries that are invalidated on uninstall but not on account removal (check which event you are testing); and values that look like keys but are public parameters or nonces. Confirm that what remains can actually decrypt data, rather than assuming from a filename or a string match.
In general, how it is fixed
Account removal should be treated as a destructive operation for all account-scoped state. The fix is to delete the private keys and the stored mnemonic in the same code path that removes the account, and to verify that no other store retains them. Where keys are kept in platform keystores, the entries should be removed explicitly rather than left to be garbage collected. On re-adding an encrypted account, the app should require the mnemonic or a fresh key exchange before granting access to existing encrypted content, so that possession of the device alone is not sufficient.
In general, where to look for similar bugs
Bugs of this shape hide in client apps with local cryptographic state: encrypted note and file sync clients, password managers, messaging apps and backup tools. The signal to look for is a separation between the account configuration and the key store, visible in the app's storage layout or in how the removal flow is implemented. Mobile clients are a good starting point because app data directories are easy to inspect on a rooted device or emulator.
A short numbered reproduction with the device state before and after removal is more persuasive than a description of the storage layout alone. Where the impact depends on device possession, say so up front; programs are more likely to accept a clearly scoped low-severity finding than an overstated one.
Glossary
- End to end encryption: a scheme where data is scrambled on the user's device and only the user's device holds the means to unscramble it, so the server cannot read it.
- Client: the app on the user's device that talks to the server.
- Server: the machine that stores the data and serves it to clients.
- Ciphertext: data after it has been scrambled by encryption.
- Key: the secret value used to scramble and unscramble data.
- Key pair: a matched pair of keys, one public and one private, used in some encryption schemes.
- Mnemonic: a list of words from which encryption keys can be rebuilt or restored, like a spare key.
- Keystore: a storage area on the device where the operating system or app keeps cryptographic keys.
- Shared preferences: a small key-value storage file used by Android apps for settings and other simple values.
- SQLite database: a small database file commonly used by apps to store structured data locally.
- App data directory: the private folder on the device where an app keeps its files.
- Rooted device: a phone where the owner has removed the operating system's restrictions and can read any app's private files.
- Emulator: software that imitates a phone on a computer, often used for testing apps.
- Nonce: a value used once in a cryptographic operation, not secret in itself.
- Lifecycle mismatch: when two pieces of data that belong together are deleted at different times, so one survives the other.
- Orphaned secrets: keys or passwords left behind after the thing they belonged to has been removed.
- False positive: a test result that looks like a problem but is not one.
- CVSS: a standard scoring system for rating the severity of a security issue.
- Bounty: a payment made by a program to a researcher who reports a valid security issue.