Gitea: OAuth token introspection returns metadata of tokens issued to other clients (RFC 7662 section 4 violation)
위협 신호 · CVSS · EPSS · KEV
이론적 심각도 점수
예측 데이터 없음
실측 악용 기록 없음
계획된 패치 주기 내 조치(60일 이내)
CVSS 벡터 · 메트릭
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:L/I:N/A:N상세 설명
Live reproduction against Gitea 1.26.1
Setup: Gitea 1.26.1 docker stack with two users (admin and victim) and two OAuth applications owned by different users:
1Client A: id=5dda747d-7fdd-4694-85ff-ce4f893ce51e owner=admin 2Client B: id=588f778f-4a41-4914-ae01-85d776c369db owner=victimadmin runs an OAuth flow against Client A and obtains an access token. victim (acting through Client B's credentials) calls the introspection endpoint with Client A's access token in the body:
1$ curl -s -u "$B_ID:$B_SEC" -X POST http://localhost:3001/login/oauth/introspect \ 2 --data-urlencode "token=$CLIENT_A_ACCESS_TOKEN" 3{ 4 "active": true, 5 "username": "admin", 6 "iss": "http://localhost:3001", 7 "sub": "1", 8 "aud": [ 9 "5dda747d-7fdd-4694-85ff-ce4f893ce51e"10 ]11}Note the aud claim: the server explicitly states the token's audience is Client A, yet returns the full metadata to Client B. Per RFC 7662 section 4 ("The authorization server SHOULD also limit the information it discloses about each token to the resources that are authorized to receive it") the introspection result must not be disclosed to clients other than the token's audience.
Full reproduction script attached as poc.sh. Full session log attached as live_run.log.
Root cause
routers/web/auth/oauth2_provider.go:130-175 IntrospectOAuth:
1func IntrospectOAuth(ctx *context.Context) { 2 clientIDValid := false 3 authHeader := ctx.Req.Header.Get("Authorization") 4 if parsed, ok := httpauth.ParseAuthorizationHeader(authHeader); ok && parsed.BasicAuth != nil { 5 clientID, clientSecret := parsed.BasicAuth.Username, parsed.BasicAuth.Password 6 app, err := auth.GetOAuth2ApplicationByClientID(ctx, clientID) 7 if err != nil && !auth.IsErrOauthClientIDInvalid(err) { 8 log.Error("Error retrieving client_id: %v", err) 9 ctx.HTTPError(http.StatusInternalServerError)10 return11 }12 clientIDValid = err == nil && app.ValidateClientSecret([]byte(clientSecret))13 }14 if !clientIDValid {15 ctx.Resp.Header().Set("WWW-Authenticate", `Basic realm="Gitea OAuth2"`)16 ctx.PlainText(http.StatusUnauthorized, "no valid authorization")17 return18 }19 20 var response struct {21 Active bool `json:"active"`22 Scope string `json:"scope,omitempty"`23 Username string `json:"username,omitempty"`24 jwt.RegisteredClaims25 }26 27 form := web.GetForm(ctx).(*forms.IntrospectTokenForm)28 token, err := oauth2_provider.ParseToken(form.Token, oauth2_provider.DefaultSigningKey)29 if err == nil {30 grant, err := auth.GetOAuth2GrantByID(ctx, token.GrantID)31 if err == nil && grant != nil {32 app, err := auth.GetOAuth2ApplicationByID(ctx, grant.ApplicationID) // shadows the introspecting client's `app`33 if err == nil && app != nil {34 response.Active = true35 response.Scope = grant.Scope36 response.RegisteredClaims = oauth2_provider.NewJwtRegisteredClaimsFromUser(app.ClientID, grant.UserID, nil)37 }38 if user, err := user_model.GetUserByID(ctx, grant.UserID); err == nil {39 response.Username = user.Name40 }41 }42 }43 44 ctx.JSON(http.StatusOK, response)45}The handler:
- Authenticates the introspecting client via HTTP Basic (
app.ValidateClientSecret). The local variableappat this point references the introspecting client. - Loads the grant for
form.Tokenviaauth.GetOAuth2GrantByID(ctx, token.GrantID). - Reassigns
apptoauth.GetOAuth2ApplicationByID(ctx, grant.ApplicationID)(line 162). After this point,appis the token's issuing client, not the introspecting client. - Populates
responsefrom the reassignedappand the grant.
There is no comparison between the introspecting client's id and grant.ApplicationID. The endpoint will return metadata for any token whose JWT signature validates, regardless of which client is asking.
Patch parity with PR #37704
The same file contains two recently-hardened handlers in commit 7e54514316 ("fix(oauth): bind token exchanges to the original client request", PR #37704, 2026-05-15) that added exactly this missing check:
handleRefreshToken (routers/web/auth/oauth2_provider.go:561-568):
1if grant.ApplicationID != app.ID { 2 handleAccessTokenError(ctx, oauth2_provider.AccessTokenError{ 3 ErrorCode: oauth2_provider.AccessTokenErrorCodeInvalidGrant, 4 ErrorDescription: "refresh token belongs to a different client", 5 }) 6 return 7}handleAuthorizationCode (routers/web/auth/oauth2_provider.go:640-647):
1if authorizationCode.RedirectURI != "" && form.RedirectURI != authorizationCode.RedirectURI { 2 handleAccessTokenError(ctx, oauth2_provider.AccessTokenError{ ... }) 3 return 4} 5// later in the same function: 6if authorizationCode.Grant.ApplicationID != app.ID { 7 handleAccessTokenError(ctx, ...) 8 return 9}IntrospectOAuth shares the same problem space (it consumes a token bound to a grant whose application may differ from the requesting client) but did not receive the parallel patch.
Impact
Any authenticated OAuth client can call /login/oauth/introspect with another client's access or refresh token in the body and learn:
active(true or false). A token-validity oracle that survives across application boundaries without consuming or "using" the token.scope. The scope of the token.username. The user the token belongs to.iss,sub,aud. Standard JWT registered claims.audreveals the issuing client_id, making it obvious to the introspecting client that the token does not belong to them. The server returns the data anyway.
Practical scenarios:
- Stolen-token validation oracle. An attacker who exfiltrates an access token from logs, traffic capture, browser memory, or a leaked dump can verify the token is still active before using it for higher-noise actions like API calls. The probe does not consume the grant counter, so it does not appear in audit trails of "actual token use".
- Cross-tenant metadata enumeration. Any user can register their own OAuth application on a Gitea instance (web UI: /user/settings/applications). The attacker uses their own valid credentials to introspect tokens belonging to other tenants' clients. They learn which user/scope each token corresponds to without ever using it.
- Token-confusion reconnaissance. Before chaining a separate vulnerability (e.g., a future token-replay or session-fixation bug), the attacker can use introspection to map the token universe.
Suggested remediation
A one-line fix matching the PR #37704 pattern:
1 grant, err := auth.GetOAuth2GrantByID(ctx, token.GrantID) 2 if err == nil && grant != nil { 3+ if grant.ApplicationID != app.ID { 4+ // do not reveal token metadata for tokens not issued to this client 5+ ctx.JSON(http.StatusOK, response) // response is zero-valued, active=false 6+ return 7+ } 8 app, err := auth.GetOAuth2ApplicationByID(ctx, grant.ApplicationID)Or, equivalently, replace the inner app reassignment with a check that uses the introspecting client's app.ClientID directly for the response claims.
Affected versions
Confirmed at Gitea v1.26.1 (latest release, 2026-04-24, docker image gitea/gitea:1.26.1). The vulnerable code path has been in place since the introspection endpoint was introduced; the recent PR #37704 / #37706 OAuth hardening landed in master May 15-16 2026 but did not touch this endpoint.
Attachments
- poc.sh: Full reproduction script.
- live_run.log: Full session log.
AI 심층 분석
공격 시나리오 · 재현 가능한 PoC 페이로드 · 즉시 적용 가능한 차단 패치를 한 번에 받아 보세요. 보안 운영팀이 그대로 점검·티켓팅에 쓸 수 있는 형태로 정리해 드립니다.
참고 자료 5
링크 내용 불러오는 중…