-
Notifications
You must be signed in to change notification settings - Fork 146
fix: 🐛 🔧 Widen DB field uids for federated sharing - #5441
Conversation
...d IDs When a federated cloud ID exceeds 64 characters, the owner_uid and editor_uid columns in oc_richdocuments_wopi silently truncate the value, which can prevent federated users from opening documents in Collabora. Widen both columns from varchar(64) to varchar(255) to accommodate the full length of federated cloud IDs in the format user@remote.domain. Signed-off-by: James Manuel <moodyjmz@users.noreply.github.com>
e5b9912 to
910cbc5
Compare
moodyjmz
commented
Feb 26, 2026
@juliusknorr I am not sure if we should make this change into the original migration file too. Also I am not sure about backporting.
moodyjmz
commented
Feb 26, 2026
One more question though, is 255 long enough?
One more question though, is 255 long enough?
That is what I've seen talk and files using. @nickvergessen @ArtificialOwl do you have any further insights there? Technically the federated cloud id could be longer then 255 characters if you are using a long domain name.
https://github.com/nextcloud/spreed/blob/b5d2a951863852f25ffe6aca2f43f8881288b570/lib/Migration/Version19000Date20240214095011.php#L39
https://github.com/nextcloud/server/blob/7e264ba58e73349f9696dd9c6c96a283ab5c7a6c/apps/files_sharing/lib/Migration/Version11300Date20201120141438.php#L50
https://github.com/nextcloud/server/blob/7e264ba58e73349f9696dd9c6c96a283ab5c7a6c/apps/contactsinteraction/lib/Migration/Version010000Date20200304152605.php#L50
juliusknorr
commented
Feb 26, 2026
I am not sure if we should make this change into the original migration file too. Also I am not sure about backporting.
Yes, we can backport this as the tables have only temporary entires so even on larger scale systems the backported migration would not cause longer downtimes on schema changes). For the backporting process i can guide you through it.
Chaning the size in the original migration as well will be faster on initial installations as then only the first one would need to run and the others can be skipped. Less db operations to get the schema setup initially.
from what I see, the length of the UID can be 64
server/lib/public/IUser.php:24
public const MAX_USERID_LENGTH = 64;
and the max for a domain is 253
So, could be 318... I think - just to be clear = adding the @ sign to get to 318
moodyjmz
commented
Feb 26, 2026
@juliusknorr So I should update the original migration file here as well?
lib/Migration/Version2060Date20200302131958.php
from what I see, the length of the UID can be 64
server/lib/public/IUser.php:24
public const MAX_USERID_LENGTH = 64;
and the max for a domain is 253
So, could be 318... I think - just to be clear = adding the @ sign to get to 318
That is with the assumpts that:
- Nextcloud is not installed in a subfolder
- It's only Nextclouds other OCM (Open Cloud Mesh) could have longer user ids
In Talk we adjusted our table later with 255 user id length and 512 server url length:
https://github.com/nextcloud/spreed/blob/c8c21215af6474536de9c10a0f3d3906e4cc1fc8/lib/Migration/Version18000Date20231024141627.php#L39-L58
But inviter_cloud_id we still have at 255 🙈
from what I see, the length of the UID can be 64
server/lib/public/IUser.php:24
public const MAX_USERID_LENGTH = 64;
and the max for a domain is 253
So, could be 318... I think - just to be clear = adding the @ sign to get to 318That is with the assumpts that:
- Nextcloud is not installed in a subfolder
- It's only Nextclouds other OCM (Open Cloud Mesh) could have longer user ids
In Talk we adjusted our table later with 255 user id length and 512 server url length: https://github.com/nextcloud/spreed/blob/c8c21215af6474536de9c10a0f3d3906e4cc1fc8/lib/Migration/Version18000Date20231024141627.php#L39-L58
But inviter_cloud_id we still have at 255 🙈
Ok
So I assumed the UID would be limited by the const at 64 and probably validated against that somewhere
and the domain length limited by DNS spec - without folders
I was incorrect in my assumptions.
Looking at the code:
$remoteServer Data Flow - DocumentController.php line 241 — the remote() method parameter
So $remoteServer looks like the initiator's own absolute URL — generated by IURLGenerator::getAbsoluteURL('/'). That returns the full base URL of the Nextcloud instance, which would include subfolders if installed in one (e.g. https://example.com/nextcloud/).
remoteServer Data Flow
No length validation exists anywhere in this chain.
-
lib/Service/FederationService.php:203—getRemoteRedirectURL()generates the initiator's own base URL via$this->urlGenerator->getAbsoluteURL('/')and stores it in$initiatorServer. This is the full URL of the Nextcloud instance where the user is browsing, including any subfolder path (e.g.https://example.com/nextcloud/). -
lib/Service/FederationService.php:217—$initiatorServeris included as theremoteServerquery parameter in a redirect URL that sends the user's browser to the source server (the server that owns the file). -
lib/Controller/DocumentController.php:241— The source server'sremote()controller method receives$remoteServerdirectly from the query string. No sanitisation or length check is performed. -
lib/Controller/DocumentController.php:268-272— The source server callsgetRemoteFileDetails()to fetch the initiator's WOPI token details via API, then passes$remoteServerunchanged toupgradeToRemoteToken(). -
lib/TokenManager.php:139-143—upgradeToRemoteToken()builds the federated cloud ID by concatenating$remoteWopi->getEditorUid() . '@' . $remoteServerand writes it toguestDisplayname(varchar(255)) via$wopi->setGuestDisplayname(). The same$remoteServeris also stored separately in$wopi->setRemoteServer().
Point of failure
The truncation occurs on the source server (the one that owns the file), not the initiator. When the source server's remote() controller calls upgradeToRemoteToken(), the values are written to the source server's richdocuments_wopi table. The database silently truncates editor_uid (varchar(64)) and guestDisplayname (varchar(255)) without raising an error. Downstream code then operates on corrupted cloud IDs, causing the document open to fail.
So 512 could also fail - unlikely, as the path is unlikely to be that long, but it could. The 255 or 512 are irrelevant, it could be 513, at which point it fails.
moodyjmz
commented
Mar 4, 2026
@nickvergessen anything new?
juliusknorr
commented
Mar 11, 2026
In Talk we adjusted our table later with 255 user id length and 512 server url length
Then I'd suggest to also go with that (+1 for the @ separator in our case). Having a limit for URLs longer then 512 characters seems reasonable to me.
Uh oh!
There was an error while loading. Please reload this page.
Uids in several fields are not long enough for names, this shifts length 64 >>>255
Summary
When a federated cloud ID exceeds 64 characters, the
owner_uidandeditor_uidcolumns in theoc_richdocuments_wopitable silently truncate the value. This can prevent federated users from opening documents in Collabora.This PR adds a database migration to widen
owner_uidandeditor_uidfromvarchar(64)tovarchar(255), aligning them with the maximum length of a federated cloud ID (user@remote).Background
The
oc_richdocuments_wopitable stores active Collabora editing sessions. Theowner_uidcolumn identifies the file owner andeditor_uididentifies the current editor. In a federation context, these values may contain a full cloud ID in the formatuser@remote.domain, which can easily exceed 64 characters with longer usernames or domain names.The columns were originally defined as
varchar(64)inVersion2060Date20200302131958, which matches the local Nextcloud user ID limit but does not account for federated cloud IDs.Changes
New migration:
Version10100Date20260226000000owner_uidfromvarchar(64)tovarchar(255)onoc_richdocuments_wopieditor_uidfromvarchar(64)tovarchar(255)onoc_richdocuments_wopinull(no-op) if the table or columns do not exist or are already the correct sizeAffected table
oc_richdocuments_wopiowner_uidvarchar(64)varchar(255)oc_richdocuments_wopieditor_uidvarchar(64)varchar(255)Notes
uidcolumns inoc_richdocuments_directandoc_richdocuments_assetsare alsovarchar(64)but currently only store local user IDs ($this->userId), so they are not affected by this issue. They can be addressed separately if needed.Version2060Date20200302131958) could also be updated to usevarchar(255)for these columns so that fresh installations get the correct size immediately.TODO
Checklist