OAuth2 client_secret stored in plain text in the database
OAuth2 client secrets were stored in plain text in the database, so anyone who obtained a database dump could read them directly. An attacker with such a dump could impersonate any OAuth2 client.
- Triaged in under an hour
- Fixed in 5 months
- Paid in 5 months
- Disclosed after 6 months
Summary by the program
Security advisory at https://github.com/nextcloud/security-advisories/security/advisories/GHSA-hhgv-jcg9-p4m9
The report
If an attacker would obtain a dumb of the database they could read out the OAuth2 client secret trivially. https://github.com/nextcloud/server/blob/master/apps/oauth2/lib/Controller/OauthApiController.php#L128
While I realise this is a big if it is not that hard to make sure the client secret is stored properly hashed. Or at the very least make sure it is stored encrypted. (however non recoverable has the preference here I'd say)
Impact
An attacker obtaining the read access to a dump of the database can trivially impersonate any OAuth2 client.
What the report shows
The target is the OAuth2 feature of the Nextcloud server codebase, in the nextcloud/server repository. The researcher, rullzer, looked at how OAuth2 client secrets are persisted and found that they are written to the database in plain text. The report points to the controller that handles the OAuth API, specifically the line where the client secret is handled:
https://github.com/nextcloud/server/blob/master/apps/oauth2/lib/Controller/OauthApiController.php#L128
The reasoning is short and direct: if an attacker obtains a dump of the database, they can read out the OAuth2 client secret trivially. The researcher acknowledges that this requires the attacker to have obtained a database dump first, calling it a big if, but argues that it is not hard to store the secret properly hashed, or at the very least encrypted. They state a preference for non-recoverable hashing over encryption.
The report was disclosed on 15 November 2023 with a medium severity rating and a CVSS score of 6.5, classified as cleartext storage in a file or on disk. A bounty of 100.00 USD was paid. The program's summary links to the published security advisory:
https://github.com/nextcloud/security-advisories/security/advisories/GHSA-hhgv-jcg9-p4m9
The report does not describe the fix itself, only the advisory link.
Root cause
The root cause is that the OAuth2 client secret is stored in the database in plain text, in a form that can be read back directly, rather than as a one-way hash. Both approaches leave the secret readable to anyone who can read the database contents.
Impact
The report's stated impact is that an attacker with read access to a database dump can trivially impersonate any OAuth2 client. That is a conditional impact: it depends on the attacker first obtaining the dump, which the researcher explicitly hedges as a big if. Within that condition, an attacker can trivially impersonate any OAuth2 client. The report does not describe any other consequence, such as access to user data or tokens, beyond client impersonation.
How this kind of bug works
OAuth2 clients authenticate to the authorisation server with a client identifier and a client secret. The server must be able to verify a presented secret, so it stores something derived from it. If it stores the raw secret, or an encrypted copy with the key available to the application, then any party who can read the storage layer can recover the secret. Database dumps leak through many routes: backups copied to less protected storage, SQL injection in an unrelated component, misconfigured replicas, stolen credentials, or insiders. A secret that is hashed with a slow, salted algorithm cannot be recovered from such a dump, so the leaked data has no direct value for impersonation.
The tension is that some flows need the plaintext secret, for example when the server itself acts as a client to a third party. Where the server only needs to verify a secret presented by a client, hashing is the correct choice. Where it genuinely needs the original value, encryption with a key held outside the database is the fallback, though it only raises the bar.
Defences are straightforward: store a salted hash of the secret using a password hashing function, compare in constant time, and treat the plaintext as shown once at creation. Keep encryption keys out of the database and out of backups. Restrict access to the secrets table and audit reads.
How to test for it
This class of bug is usually found by inspecting storage rather than by sending crafted requests.
- Identify features that issue credentials to third parties: OAuth2 clients, API keys, webhook signing secrets, integration tokens.
- Create a test client or key through the normal interface and note the secret value shown.
- Obtain read access to the underlying storage through a legitimate channel available to you, such as a local test instance, a provided database console, or an export feature.
- Inspect the stored row for the secret. A positive result is the exact secret value appearing in the column, or a value that decrypts to it with a key available in the same configuration.
- Confirm by changing the stored value and observing that authentication with the original secret still succeeds or fails as expected, which shows the stored form is what is compared.
A positive result looks like the literal secret in the database, or an encrypted blob whose key sits in the application configuration. Common false positives include columns that hold a hash but look opaque, truncated previews of the secret kept for display, and values that are encrypted with a key held in a separate key management service, which is a weaker finding. Check whether the stored value is the same across two clients with different secrets before concluding.
How it is fixed
The standard fix is to hash the client secret with a slow, salted algorithm and store only the hash, comparing presented secrets against it. The plaintext is shown to the user once at creation and never again. If the application must recover the secret, encrypt it with a key stored outside the database, rotate that key, and keep it out of backups. Additional measures include limiting database read access, auditing access to the secrets table, and invalidating and reissuing secrets after any suspected exposure.
Hunting notes
Secrets tend to hide in tables for OAuth clients, API tokens, webhook endpoints, SMTP and integration settings, and in configuration files shipped with the application. Recon signals include features that display a secret once, endpoints that regenerate credentials, and documentation that mentions client secrets or API keys. Reading the schema and migrations of an open source target often reveals the column type and whether a hash is used.
To make a report accepted, show the stored value and prove it is the usable secret, not a hash. Explain the realistic path to a database dump, such as a backup exposure or an injection elsewhere, without overstating it. Keep the impact tied to what the leaked secret allows, and avoid claiming access you did not demonstrate.
What happened, in plain words
Nextcloud is a self-hosted file sync and sharing platform: organisations run it on their own servers so staff can store and share files. One of its features is OAuth2, a standard way for one piece of software to ask another for permission to act on a user's behalf. When you click "Sign in with Google" on some website, OAuth2 is usually what happens behind the scenes.
To make that work, an application registers with the server and receives two things: a client identifier (a public name, like a username) and a client secret (a private password that proves the application really is who it claims to be). The server has to keep the secret somewhere so it can check it later.
The researcher, rullzer, looked at how Nextcloud stores those client secrets and found they are written into the database as plain, readable text. The report points at the part of the code that handles the OAuth API, specifically the line dealing with the client secret:
https://github.com/nextcloud/server/blob/master/apps/oauth2/lib/Controller/OauthApiController.php#L128
That link is a pointer into the Nextcloud source code on GitHub, not a request anyone can send. It tells a reader where to look: the file OauthApiController.php inside the oauth2 app, around line 128.
The reasoning in the report is short. If an attacker gets hold of a database dump (a copy of everything stored in the database, often produced for backups or migrations), they can read the OAuth2 client secret trivially. The researcher openly admits this needs the attacker to obtain a dump first, calling it a big if, but argues it is not hard to store the secret properly hashed, or at the very least encrypted. They say they would prefer hashing, because a hash cannot be turned back into the original secret.
The report was disclosed on 15 November 2023 with a medium severity rating and a CVSS score of 6.5, classified as cleartext storage in a file or on disk. A bounty of 100.00 USD was paid. The program's summary links to the published security advisory:
https://github.com/nextcloud/security-advisories/security/advisories/GHSA-hhgv-jcg9-p4m9
The report does not describe the fix itself, only that advisory link.
Why this matters
The stated impact is that an attacker with read access to a database dump can trivially impersonate any OAuth2 client. Impersonating a client means pretending to be that registered application: presenting its identifier and secret to the server and being treated as it. The impact is conditional, because it depends on the attacker first getting the dump, which the researcher explicitly hedges. Within that condition, an attacker can trivially impersonate any OAuth2 client. The report does not describe any other consequence, such as access to user data or tokens, beyond client impersonation.
The underlying cause
The root cause is that the client secret is stored in the database in plain text, in a form that can be read back directly, rather than as a one-way hash. A hash is like a meat grinder: you can put a value in and get a fixed-length result out, but you cannot turn the result back into the original. Both approaches leave the secret readable to anyone who can read the database contents.
In general, how this kind of bug works
OAuth2 clients authenticate to the authorisation server with a client identifier and a client secret. The server must be able to verify a presented secret, so it stores something derived from it. If it stores the raw secret, or an encrypted copy with the key available to the application, then any party who can read the storage layer can recover the secret.
Database dumps leak through many routes: backups copied to less protected storage, SQL injection in an unrelated component, misconfigured replicas, stolen credentials, or insiders. A secret that is hashed with a slow, salted algorithm cannot be recovered from such a dump, so the leaked data has no direct value for impersonation. A salt is random data added before hashing so that two identical secrets do not produce identical hashes, which stops an attacker from spotting repeats or using precomputed tables.
The tension is that some flows need the plaintext secret, for example when the server itself acts as a client to a third party. Where the server only needs to verify a secret presented by a client, hashing is the correct choice. Where it genuinely needs the original value, encryption with a key held outside the database is the fallback, though it only raises the bar.
Defences are straightforward: store a salted hash of the secret using a password hashing function, compare in constant time, and treat the plaintext as shown once at creation. Keep encryption keys out of the database and out of backups. Restrict access to the secrets table and audit reads.
How to test for it
This class of bug is usually found by inspecting storage rather than by sending crafted requests.
- Identify features that issue credentials to third parties: OAuth2 clients, API keys, webhook signing secrets, integration tokens.
- Create a test client or key through the normal interface and note the secret value shown.
- Obtain read access to the underlying storage through a legitimate channel available to you, such as a local test instance, a provided database console, or an export feature.
- Inspect the stored row for the secret. A positive result is the exact secret value appearing in the column, or a value that decrypts to it with a key available in the same configuration.
- Confirm by changing the stored value and observing that authentication with the original secret still succeeds or fails as expected, which shows the stored form is what is compared.
A positive result looks like the literal secret in the database, or an encrypted blob whose key sits in the application configuration. Common false positives include columns that hold a hash but look opaque, truncated previews of the secret kept for display, and values that are encrypted with a key held in a separate key management service, which is a weaker finding. Check whether the stored value is the same across two clients with different secrets before concluding.
How it is fixed
The standard fix is to hash the client secret with a slow, salted algorithm and store only the hash, comparing presented secrets against it. The plaintext is shown to the user once at creation and never again. If the application must recover the secret, encrypt it with a key stored outside the database, rotate that key, and keep it out of backups. Additional measures include limiting database read access, auditing access to the secrets table, and invalidating and reissuing secrets after any suspected exposure.
Hunting notes
Secrets tend to hide in tables for OAuth clients, API tokens, webhook endpoints, SMTP and integration settings, and in configuration files shipped with the application. Recon signals include features that display a secret once, endpoints that regenerate credentials, and documentation that mentions client secrets or API keys. Reading the schema and migrations of an open source target often reveals the column type and whether a hash is used.
To make a report accepted, show the stored value and prove it is the usable secret, not a hash. Explain the realistic path to a database dump, such as a backup exposure or an injection elsewhere, without overstating it. Keep the impact tied to what the leaked secret allows, and avoid claiming access you did not demonstrate.
Glossary
- Nextcloud: a self-hosted platform for storing and sharing files, run on an organisation's own servers.
- OAuth2: a standard protocol that lets one application ask another for permission to act on a user's behalf.
- Client identifier: the public name an application uses when it registers with an OAuth2 server.
- Client secret: the private password an application uses to prove its identity to the OAuth2 server.
- Database: the organised store where an application keeps its data, including user accounts and credentials.
- Database dump: a full copy of a database's contents, often made for backups or migrations.
- Plain text: data stored exactly as written, with no scrambling, so anyone who can read the storage can read it.
- Hash: a one-way transformation that turns a value into a fixed-length result that cannot be reversed.
- Salt: random data added before hashing so identical inputs produce different hashes.
- Encryption: scrambling data with a key so it can only be read by someone who holds that key.
- CVSS: a standard scoring system that rates the severity of a security vulnerability.
- Bounty: a payment made by a program to a researcher who reports a valid vulnerability.
- Impersonation: pretending to be another application or user by presenting its credentials.
- SQL injection: a technique where an attacker inserts database commands into an input field to read or change stored data.
- Constant time comparison: a way of comparing values that takes the same time regardless of where they differ, so timing does not leak information.