Cloudreve: OAuth access tokens bypass scope enforcement due to missing client_id claim
위협 신호 · CVSS · EPSS · KEV
이론적 심각도 점수
30일 내 악용 확률 예측
실측 악용 기록 없음
계획된 패치 주기 내 조치(60일 이내)
CVSS 벡터 · 메트릭
CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:U/C:H/I:H/A:L상세 설명
Summary
Cloudreve's OAuth access tokens can bypass OAuth scope enforcement.
This does not appear to be the intended design. The documentation describes OAuth client permissions/scopes, the API
has an insufficient-scope error code, and the code comments say RequiredScopes(...) should verify scopes when a
token has scopes, while skipping checks only for non-scoped session-based authentication.
However, OAuth access tokens are issued without the OAuth client_id claim. Later, the JWT verifier only loads scopes
into the request context when claims.ClientID != "". Because the OAuth access token has no client_id, its scopes
are not loaded, and RequiredScopes(...) treats the request like a non-scoped first-party/session token and skips
scope checks.
As a result, a low-scope OAuth access token, for example one granted only openid, can call APIs requiring higher
scopes such as file, share, workflow, user setting, WebDAV account, and potentially admin scopes when the authorizing
user is an administrator.
Why this seems unintended
Cloudreve appears to have an explicit OAuth scope model:
- The official docs describe OAuth client permissions/scopes and require the authorization request to include
requested scopes. - The API error code list includes an OAuth insufficient-scope error.
RequiredScopes(...)is used across sensitive API groups such as files, shares, workflows, user settings, WebDAV
devices, and admin APIs.- The middleware comment says scope checks are skipped only when
hasScopesis false, for example session-based
authentication. - Default OAuth clients created during migration explicitly list scopes such as
Files.Write,Workflow.Write, and
Shares.Write.
This suggests the intended design is:
- First-party/session tokens may be non-scoped and skip OAuth scope checks.
- OAuth access tokens should carry scope metadata and be checked against
RequiredScopes(...).
The current implementation makes OAuth access tokens fall into the first category by mistake.
Affected code
In the OAuth authorization code exchange, Cloudreve passes both ClientID and Scopes into token issuance:
1token, err := tokenAuth.Issue(c, &auth.IssueTokenArgs{ 2 User: user, 3 ClientID: s.ClientID, 4 Scopes: authCode.Scopes, 5 RefreshTTLOverride: refreshTTLOverride, 6}) 7 8Location: 9 10- service/oauth/oauth.go11 12In Issue(...), the access token includes Scopes but does not include ClientID:13 14accessToken, err := jwt.NewWithClaims(jwt.SigningMethodHS256, Claims{15 TokenType: TokenTypeAccess,16 RegisteredClaims: jwt.RegisteredClaims{17 Subject: uidEncoded,18 NotBefore: jwt.NewNumericDate(issueDate),19 ExpiresAt: jwt.NewNumericDate(accessTokenExpired),20 },21 Scopes: args.Scopes,22}).SignedString(t.secret)23 24By contrast, the refresh token does include both:25 26Scopes: args.Scopes,27ClientID: args.ClientID,28 29Location:30 31- pkg/auth/jwt.go32 33During request authentication, scopes are only inserted into request context if ClientID is present:34 35if claims.ClientID != "" {36 util.WithValue(c, ScopeContextKey{}, claims.Scopes)37}38 39Location:40 41- pkg/auth/jwt.go42 43Then CheckScope(...) skips scope enforcement if no scopes are present in context:44 45hasScopes, tokenScopes := GetScopesFromContext(c)46if !hasScopes {47 return nil48}49 50Location:51 52- pkg/auth/jwt.go53 54RequiredScopes(...) relies on this check:55 56if err := auth.CheckScope(c, requiredScopes...); err != nil {57 c.JSON(200, serializer.Err(c, err))58 c.Abort()59 return60}61 62Location:63 64- middleware/auth.go65 66Sensitive route groups protected by RequiredScopes(...) include:67 68- Files: Files.Read / Files.Write69- Shares: Shares.Read / Shares.Write70- Workflows: Workflow.Read / Workflow.Write71- User settings and security info72- WebDAV device/account management73- Admin APIs: Admin.Read / Admin.Write74 75Location:76 77- routers/router.go78 79## Reproduction steps80 811. Create or use an OAuth client with a low-privilege scope, for example only openid.822. Complete the OAuth authorization code flow for a normal user with:83 84scope=openid85 863. Exchange the authorization code via:87 88POST /api/v4/session/oauth/token89 904. Decode the returned access token.91 92Expected token metadata should preserve enough OAuth client/scope context for later enforcement.93 94Actual behavior:95 96- The access token contains the requested scopes.97- The access token does not contain client_id.98 995. Use the returned token as a bearer token:100 101Authorization: Bearer <access_token>102 1036. Call an API that requires a scope not granted to the OAuth app, for example an endpoint requiring Files.Read,104 Files.Write, UserInfo.Write, or DavAccount.Write.105 106Expected result:107 108- The request should fail with an insufficient-scope error.109 110Actual result:111 112- The scope check is skipped because no scopes were inserted into the request context.113- The request is processed as that user.114 115If the authorizing user is an administrator, the same issue can affect admin APIs requiring Admin.Read or Admin.Write,116because the request still runs as the admin user and the admin identity check can pass while the OAuth scope check is117skipped.118 119## Impact120 121This is not an anonymous authentication bypass. The attacker still needs a valid OAuth access token for a real user.122 123The impact is an OAuth consent/scope boundary bypass:124 125- A third-party OAuth app can request a minimal scope such as openid.126- After the user authorizes it, the app receives an access token.127- That token can be used as a broader bearer token for the same user's Cloudreve account, despite not being granted128 the required scopes.129 130For normal users, this may allow access to or modification of files, shares, workflows, user settings, and WebDAV131account/device settings depending on available APIs.132 133For administrator users, it may allow access to admin-scoped functionality without the OAuth app being granted134Admin.Read or Admin.Write.135 136## Suggested fix137 1381. Include ClientID: args.ClientID in access token claims when issuing OAuth access tokens:139 140accessToken, err := jwt.NewWithClaims(jwt.SigningMethodHS256, Claims{141 TokenType: TokenTypeAccess,142 RegisteredClaims: jwt.RegisteredClaims{143 Subject: uidEncoded,144 NotBefore: jwt.NewNumericDate(issueDate),145 ExpiresAt: jwt.NewNumericDate(accessTokenExpired),146 },147 Scopes: args.Scopes,148 ClientID: args.ClientID,149}).SignedString(t.secret)150 1512. Consider making scope handling fail closed for OAuth tokens with malformed or inconsistent OAuth metadata.1523. Add regression tests for an OAuth access token granted only openid attempting to call APIs requiring:153 - Files.Read154 - Files.Write155 - UserInfo.Write156 - DavAccount.Write157 - Admin.Read158 - Admin.Write159 160Each should fail with an insufficient-scope error unless the corresponding scope was granted.AI 심층 분석
공격 시나리오 · 재현 가능한 PoC 페이로드 · 즉시 적용 가능한 차단 패치를 한 번에 받아 보세요. 보안 운영팀이 그대로 점검·티켓팅에 쓸 수 있는 형태로 정리해 드립니다.
참고 자료 5
링크 내용 불러오는 중…