GHSA-c3jm-gv5r-9wcp Cloudreve WOPI view sessions can write files and WOPI access token secret is ignored
SummaryCloudreve WOPI access tokens are generated as `<session-id>.<random-secret>`, but the WOPI middleware validates only the session id prefix and never compares the supplied token to the stored token. In addition, a WOPI viewer session does not store or enforce the requested viewer action. A session created for a view or preview action can still call WOPI write routes if the underlying file is writable by the session user.ImpactA WOPI integration that is only expected to view a user's file can modify that file through the WOPI write endpoints. If the WOPI URL or session id leaks, the random token suffix does not protect the session because any suffix is accepted for an existing session id.This affects deployments that configure WOPI viewers for user files. The attacker primitive is strongest when a malicious or compromised WOPI viewer receives a view-only URL and then writes content back to Cloudreve.Affected versionVerified in source and runtime on latest master commit `ba2e870bbd17f1918dd2321de861e453f696d6a3` and latest observed tag `4.16.1`.Technical detailsCloudreve creates WOPI viewer sessions in `pkg/filemanager/manager/viewer.go`:The token includes a 128-character random suffix, but `middleware.ViewerSessionValidation()` only uses the prefix before the dot:The middleware checks that the file id matches the loaded session, but it never compares `c.Query("access_token")` with `session.Token`. As a result, `<valid-session-id>.anything` is accepted.The WOPI routes are exposed without normal session authentication and rely on this middleware:The write routes are not protected by a session-level write check. `CreateViewerSessionService` accepts `preferred_action`, but `ViewerSessionCache` has no action or write-permission field and `CreateViewerSession` does not persist the chosen action. The requested action is only used to generate the WOPI source URL:`WopiService.PutContent()` checks only the underlying filesystem upload capability:It does not check whether the WOPI session was created for an edit action.ReproductionThe following sequence was verified against a disposable local Cloudreve instance built from the affected commit.Configure a WOPI viewer in Cloudreve.Create a user-owned file, for example `cloudreve://my/wopi.txt`, containing `original content`.Create a viewer session with `preferred_action` set to `view`:Observed response:Replace the token suffix with any value:Observed response: `200 OK`. The same request with an unknown session id returned `403 Forbidden`, confirming the middleware validates the session id prefix but ignores the secret suffix.Use the forged token from the view-created session to read content:Observed response:Use the same forged token from the view-created session to write content:Observed response:Read back the modified file with the forged token:Observed response:This proves both authorization failures: the random token suffix is ignored, and a view-created WOPI session can reach the content write sink.Root causeTwo authorization values are generated or accepted but not enforced:The random WOPI token suffix is generated and stored but never compared during WOPI request validation.The requested WOPI action is accepted during session creation but not persisted or enforced on WOPI write routes.RemediationCompare the full supplied `access_token` to the stored `ViewerSessionCache.Token` using constant-time comparison.Reject malformed tokens and tokens with extra separators.Store a `CanWrite` flag or selected WOPI action in `ViewerSessionCache`.Enforce that flag on `POST /contents`, `PUT_RELATIVE`, `LOCK`, and other write operations.Include session-level write permission when returning WOPI `FileInfo` fields such as `ReadOnly` and `UserCanWrite`.
CVSS v3.1 score: 6.3