Database error shown to the user when using a long guest name in richdocuments
A guest name longer than the database column allows causes a database error that is shown to the user, exposing the full SQL query, parameters, and internal details. An attacker could use this to learn about the database schema and possibly other sensitive information.
- Triaged in 7 days
- Fixed in 7 days
- Disclosed after 40 days
When sharing a file to a guest and the file is allow for editing, the user is asked to enter a guestname if you enter a really long value for that name you get a database error that displays sensitive information:
An exception occurred while executing 'INSERT INTO oc_richdocuments_wopi(fileid,owner_uid,version,canwrite,server_host,token,expiry,guest_displayname,template_destination,hide_download,direct,is_remote_token,template_id,share) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)' with params [8606022, "8JaQyYP5xM7w2PJ6", 0, true, "https://demo2.nextcloud.com/", "hUYL4uh9Dals51BoAT2YA7WZ1IJMaCLp", 1609196332, "reallylongnameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee (Guest)", 0, false, false, false, 0, "c4A53CW6wAN2ZZa"]: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'guest_displayname' at row 1
Demo
Impact
Information Disclosure
Context
Nextcloud is a self-hosted file sync and sharing platform. One of its optional applications, richdocuments, integrates an online office suite so that documents can be edited in the browser. When a file is shared with a guest and editing is allowed, the guest is asked to enter a display name before joining the editing session. That name is stored alongside the WOPI session record in the database table oc_richdocuments_wopi.
The report concerns the handling of that guest name. A very long value is passed through to the database without being constrained to the column length, and the resulting database exception is rendered back to the user, exposing internal details.
Setup
The error output shows the host demo2.nextcloud.com. The precondition is a file shared with a guest with editing permitted, so that the guest name prompt appears. No special role on the server is described; the interaction happens as the guest joining the share.
Finding it
The researcher entered a very long guest name and the value was passed through to the database. Because the name is written into a database column, a value longer than the column allows should be rejected by validation before the insert is attempted. Instead, the insert fails at the database layer and the raw exception is surfaced to the user. That exception contains the full SQL statement, the bound parameters, the internal host, a token and the share token, which is why the issue was classified as information disclosure.
Exploitation
Step 1: Open the guest name prompt
Share a file with a guest and allow editing. The application asks the guest to enter a guest name.
Step 2: Submit an oversized name
Enter a very long guest name and submit it. The value used in the report is a long run of the letter e followed by (Guest). The insert into oc_richdocuments_wopi then fails, and the page returns the database error:
An exception occurred while executing 'INSERT INTO `oc_richdocuments_wopi`(`fileid`,`owner_uid`,`version`,`canwrite`,`server_host`,`token`,`expiry`,`guest_displayname`,`template_destination`,`hide_download`,`direct`,`is_remote_token`,`template_id`,`share`) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)' with params [8606022, "8JaQyYP5xM7w2PJ6", 0, true, "https:\/\/demo2.nextcloud.com\/", "[redacted]", 1609196332, "reallylongnameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee (Guest)", 0, false, false, false, 0, "c4A53CW6wAN2ZZa"]: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'guest_displayname' at row 1
The message shows several things at once:
- The failing statement is an
INSERTintooc_richdocuments_wopi, with the full column list:fileid,owner_uid,version,canwrite,server_host,token,expiry,guest_displayname,template_destination,hide_download,direct,is_remote_token,template_idandshare. - The bound parameters are printed in clear, including the file id
8606022, the owner uid8JaQyYP5xM7w2PJ6, the server hosthttps://demo2.nextcloud.com/, a token[redacted], the expiry1609196332, the oversized guest display name, and the share valuec4A53CW6wAN2ZZa. - The database driver error identifies the exact cause:
SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'guest_displayname' at row 1.
The demo recording shows the same flow in the browser.
Root cause
The guest display name is inserted into guest_displayname without a length check that matches the column definition. The database rejects the value with error 1406 (Data too long for column), and the application's error handling passes the exception message, including the statement and its parameters, through to the response instead of returning a generic error. The report does not include the code, so the exact validation and error-handling paths are not shown; the behaviour above is what the error output demonstrates.
Impact
A guest interacting with a shared, editable file can trigger a database error that discloses internal information: the table and column layout of oc_richdocuments_wopi, the file id, the owner uid, the configured server host, a session token, the expiry timestamp and the share token. The report classifies this as information disclosure. It does not describe what an attacker could do with the disclosed tokens, nor whether the tokens remain valid, so the practical follow-on impact is not established in the report.
Fix
The report does not describe a fix or a code change. The evident requirement is twofold: constrain or truncate the guest display name to the column length before the insert, and stop returning raw database exception text to the client, logging it server-side and showing a generic error instead.
Variants to test
- Other free-text fields that end up in fixed-length columns: submit values longer than the column and look for a 1406-style error. A positive result is a response containing the SQL statement, parameters or column name.
- Other guest or public-link flows in the same application: try oversized names, messages or labels wherever a guest supplies text that is persisted. A positive result is any database error rendered to the user.
- Error handling on other endpoints: send values that violate other constraints (wrong type, null where not allowed) and check whether the exception text is reflected. A positive result is a stack trace or driver message in the response.
Hunting notes
During recon, public demo instances and freshly installed instances are useful because error verbosity is often left at defaults. The signal is any response that includes SQL fragments, parameter arrays or driver error codes. In this report the researcher demonstrated impact simply by showing the full exception, with its tokens and internal host, in the browser, which was enough to support the information disclosure classification.
What happened, in plain words
Nextcloud is a piece of software you can install on your own server to store and share files, a bit like running your own private version of a cloud drive. It has optional add-ons, and one of them, called richdocuments, plugs in an online office suite so that documents can be opened and edited straight in the browser.
When someone shares a file with a guest (a person who does not have an account on the server) and allows that guest to edit it, the guest is first asked to type a display name. That name is saved in a database, in a table called oc_richdocuments_wopi, next to a record describing the editing session.
The researcher found that this name field accepts a value of any length. A database column, however, has a maximum size, like a form box that only has room for a certain number of characters. When the name was too long, the database refused to store it and produced an error. Instead of hiding that error and showing something friendly, the application printed the whole database message on the page. That message contained the SQL statement, the values being saved, an internal host name and two tokens. Because internal details leaked to whoever was using the page, the issue was classified as information disclosure.
Background concepts
Before walking through the steps, here are the ideas you need.
- Database: the place where an application keeps its data permanently, organised into tables with rows and columns, much like a spreadsheet. Each column has a type and often a maximum length.
- SQL: the language used to talk to a database. An
INSERTstatement adds a new row. ASELECTstatement reads rows. - SQL exception: when the database cannot carry out a statement, it returns an error. The application can either handle it gracefully or pass the raw text to the user.
- Token: a long random-looking string that acts as a pass. Whoever holds it can usually access the thing it protects, in the same way a cloakroom ticket lets you collect a coat. Tokens should never be shown to people who are not meant to have them.
- Information disclosure: a vulnerability class where the application reveals data that should stay internal, such as file paths, database layouts, server names or tokens. On its own it may look harmless, but it gives an attacker material for further attacks.
- Guest: a visitor without an account who is given access to a specific shared item through a link.
- WOPI: a protocol used by office-suite integrations to let an editor open and save documents held by another service. The table name
oc_richdocuments_wopirefers to it.
Setup
The error text itself shows the host demo2.nextcloud.com. The only precondition is a file shared with a guest with editing allowed, so that the guest name prompt appears. The report does not describe any special role on the server: the interaction happens as the guest joining the share.
Finding it
The researcher entered a very long guest name and the value was passed through to the database. Since the name is written into a database column, a value longer than the column allows should be rejected by validation before the insert is even attempted. Instead, the insert fails at the database layer and the raw exception is shown to the user. That exception contains the full SQL statement, the values bound to it, the internal host, a token and the share token, which is why the issue was classified as information disclosure.
Exploitation
Step 1: Open the guest name prompt
Share a file with a guest and allow editing. The application asks the guest to enter a guest name. This step simply puts you in front of the input field that the rest of the attack targets.
Step 2: Submit an oversized name
Enter a very long guest name and submit it. The value used in the report is a long run of the letter e followed by (Guest). The insert into oc_richdocuments_wopi then fails, and the page returns the database error:
An exception occurred while executing 'INSERT INTO `oc_richdocuments_wopi`(`fileid`,`owner_uid`,`version`,`canwrite`,`server_host`,`token`,`expiry`,`guest_displayname`,`template_destination`,`hide_download`,`direct`,`is_remote_token`,`template_id`,`share`) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)' with params [8606022, "8JaQyYP5xM7w2PJ6", 0, true, "https:\/\/demo2.nextcloud.com\/", "[redacted]", 1609196332, "reallylongnameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee (Guest)", 0, false, false, false, 0, "c4A53CW6wAN2ZZa"]: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'guest_displayname' at row 1
Reading this message piece by piece:
An exception occurred while executingis the application telling you that a database operation failed.- The quoted
INSERT INTO oc_richdocuments_wopi (...)is the exact statement it tried to run. The list in brackets names every column the row would fill:fileid,owner_uid,version,canwrite,server_host,token,expiry,guest_displayname,template_destination,hide_download,direct,is_remote_token,template_idandshare. This alone tells an outsider how the table is built. VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)shows fourteen placeholders. Placeholders are used so that the real values are sent separately, which is a normal safety measure against SQL injection.with params [...]then prints those real values in clear, which defeats the purpose of the placeholders. Among them are the file id8606022, the owner uid8JaQyYP5xM7w2PJ6, the server hosthttps://demo2.nextcloud.com/, a token[redacted], the expiry1609196332, the oversized guest display name, and the share valuec4A53CW6wAN2ZZa.SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'guest_displayname' at row 1is the database driver's own explanation: the value did not fit in theguest_displaynamecolumn, so the insert was rejected.
The demo recording shows the same flow in the browser.
Root cause
The guest display name is inserted into guest_displayname without a length check that matches the column definition. The database rejects the value with error 1406 (Data too long for column), and the application's error handling passes the exception message, including the statement and its parameters, through to the response instead of returning a generic error. The report does not include the code, so the exact validation and error-handling paths are not shown; the behaviour above is what the error output demonstrates.
Impact
A guest interacting with a shared, editable file can trigger a database error that discloses internal information: the table and column layout of oc_richdocuments_wopi, the file id, the owner uid, the configured server host, a session token, the expiry timestamp and the share token. The report classifies this as information disclosure. It does not describe what an attacker could do with the disclosed tokens, nor whether the tokens remain valid, so the practical follow-on impact is not established in the report.
Fix
The evident requirement is twofold: constrain or truncate the guest display name to the column length before the insert, and stop returning raw database exception text to the client, logging it server-side and showing a generic error instead.
Variants to test
- Other free-text fields that end up in fixed-length columns: submit values longer than the column and look for a 1406-style error. A positive result is a response containing the SQL statement, parameters or column name.
- Other guest or public-link flows in the same application: try oversized names, messages or labels wherever a guest supplies text that is persisted. A positive result is any database error rendered to the user.
- Error handling on other endpoints: send values that violate other constraints (wrong type, null where not allowed) and check whether the exception text is reflected. A positive result is a stack trace or driver message in the response.
Hunting notes
During recon, public demo instances and freshly installed instances are useful because error verbosity is often left at defaults. The signal is any response that includes SQL fragments, parameter arrays or driver error codes. In this report the researcher demonstrated impact simply by showing the full exception, with its tokens and internal host, in the browser, which was enough to support the information disclosure classification.
Glossary
- Database: the permanent storage an application uses, organised into tables of rows and columns.
- Table: one collection of related data inside a database, like a single sheet in a spreadsheet.
- Column: one field of a table, with a defined type and often a maximum length.
- Row: one record in a table, made up of one value per column.
- SQL: the language used to add, read, change and delete data in a database.
- INSERT: the SQL statement that adds a new row to a table.
- SQL exception: an error returned by the database when a statement cannot be carried out.
- Placeholder: a
?in a prepared SQL statement where a real value is supplied separately at execution time. - Bound parameter: a real value attached to a placeholder when the statement runs.
- SQLSTATE: a standard code that classifies database errors;
22001here means a string was too long. - Error 1406: the database's own code for
Data too long for column, meaning the value exceeded the column's maximum length. - Token: a long random string that acts as a pass to a resource and must be kept secret.
- Share token: the token that identifies a particular share link.
- Session: a period during which a user's interaction with an application is tracked, usually tied to a token.
- Expiry: a timestamp after which a token or session is no longer valid.
- Host: the server name and scheme part of a URL, such as
https://demo2.nextcloud.com/. - Guest: a visitor without an account who is given access to a specific shared item.
- WOPI: a protocol that lets an online editor open and save documents held by another service.
- Information disclosure: a vulnerability where the application reveals data that should stay internal.
- Validation: checking input before using it, for example rejecting a name that is too long.
- Error handling: how an application reacts to failures, ideally with a generic message to the user and details only in server logs.
- Endpoint: a specific address on a server that accepts requests and performs an action.
- Recon: the early phase of testing where you look around an application to find where to probe.
- Stack trace: a list of internal function calls produced when an error occurs, useful to developers and revealing to attackers.