Summary
A scoped API token can bypass its declared permissions by using the OAuth authorization flow to mint normal session credentials.
A token limited to:
can call /api/v1/oauth/authorize, receive an OAuth authorization code, exchange it at /api/v1/oauth/token, and obtain a normal bearer JWT plus refresh token. The resulting credentials are not restricted by the original API-token permissions.
Affected Component
- Scoped API tokens
- OAuth authorization flow
POST /api/v1/oauth/authorize
POST /api/v1/oauth/token
Impact
A narrowly scoped API token with only oauth.authorize can be converted into normal session credentials for the same user.
This bypasses the intended API-token permission boundary. An attacker who obtains or is delegated such a limited token can mint a normal JWT and refresh token, then access routes outside the original token scope.
Runtime validation showed that the original scoped token could not access GET /api/v1/user, but the minted OAuth access token could access:
GET /api/v1/user
GET /api/v1/projects
No cross-user access, privilege escalation to admin, or access to another account was validated.
Technical Details
The issue is caused by an authentication-context mismatch between scoped API-token authentication and OAuth authorization-code issuance.
The vulnerable chain is:
- A scoped API token authenticates the request and sets the current user context.
/api/v1/oauth/authorize accepts that API-token-authenticated user as a valid OAuth resource owner.
- The OAuth authorization endpoint issues an authorization code.
/api/v1/oauth/token exchanges that code for a normal bearer JWT and refresh token.
- The resulting credentials are not bound to the original API-token permissions.
Relevant code paths:
Steps to Reproduce
1. Create a scoped API token
Create an API token with only the following permission:
Observed response:
The returned token had only the oauth.authorize permission.
2. Negative control: direct access with scoped token fails
Request:
GET /api/v1/user
Authorization: Bearer <scoped-api-token>
Observed response:
Response body:
{"code":11,"message":"missing, malformed, expired or otherwise invalid token provided"}
This confirms that the scoped token cannot directly access the normal user route.
3. Obtain an OAuth authorization code with the scoped token
Request:
POST /api/v1/oauth/authorize
Authorization: Bearer <scoped-api-token>
Content-Type: application/json
Body:
{
"response_type": "code",
"client_id": "vikunja",
"redirect_uri": "vikunja-flutter://callback",
"code_challenge": "<pkce-s256-challenge>",
"code_challenge_method": "S256"
}
Observed response:
Response body:
{
"code": "<redacted>",
"redirect_uri": "vikunja-flutter://callback",
"state": ""
}
The scoped API token successfully obtained an OAuth authorization code.
4. Exchange the authorization code for session credentials
Request:
POST /api/v1/oauth/token
Content-Type: application/json
Body:
{
"grant_type": "authorization_code",
"code": "<redacted>",
"client_id": "vikunja",
"redirect_uri": "vikunja-flutter://callback",
"code_verifier": "<original-pkce-verifier>"
}
Observed response:
Response body:
{
"access_token": "<redacted>",
"token_type": "bearer",
"expires_in": 600,
"refresh_token": "<redacted>"
}
The authorization code was exchanged for a normal access token and refresh token.
5. Use the minted access token on normal routes
Request:
GET /api/v1/user
Authorization: Bearer <minted-oauth-access-token>
Observed response:
Additional scope check:
GET /api/v1/projects
Authorization: Bearer <minted-oauth-access-token>
Observed response:
The minted OAuth access token could access normal non-OAuth routes that the original scoped API token could not access.
Expected Behavior
A scoped API token should not be able to obtain credentials with broader permissions than its declared scope.
/api/v1/oauth/authorize should require a normal user session or another authentication context suitable for OAuth authorization-code issuance. API-token-authenticated requests should not be accepted for minting OAuth authorization codes.
Actual Behavior
A token scoped only to oauth.authorize can obtain an OAuth authorization code and exchange it for a normal JWT plus refresh token.
The minted credentials are not restricted by the original API-token permissions.
Summary
A scoped API token can bypass its declared permissions by using the OAuth authorization flow to mint normal session credentials.
A token limited to:
{"oauth":["authorize"]}can call
/api/v1/oauth/authorize, receive an OAuth authorization code, exchange it at/api/v1/oauth/token, and obtain a normal bearer JWT plus refresh token. The resulting credentials are not restricted by the original API-token permissions.Affected Component
POST /api/v1/oauth/authorizePOST /api/v1/oauth/tokenImpact
A narrowly scoped API token with only
oauth.authorizecan be converted into normal session credentials for the same user.This bypasses the intended API-token permission boundary. An attacker who obtains or is delegated such a limited token can mint a normal JWT and refresh token, then access routes outside the original token scope.
Runtime validation showed that the original scoped token could not access
GET /api/v1/user, but the minted OAuth access token could access:GET /api/v1/userGET /api/v1/projectsNo cross-user access, privilege escalation to admin, or access to another account was validated.
Technical Details
The issue is caused by an authentication-context mismatch between scoped API-token authentication and OAuth authorization-code issuance.
The vulnerable chain is:
/api/v1/oauth/authorizeaccepts that API-token-authenticated user as a valid OAuth resource owner./api/v1/oauth/tokenexchanges that code for a normal bearer JWT and refresh token.Relevant code paths:
pkg/routes/routes.go/api/v1/oauth/authorizein an authenticated API route group that also accepts scoped API tokenspkg/models/api_routes.gooauthpermission grouppkg/routes/api_tokens.goapi_tokenandapi_userin the request context during API-token authenticationpkg/user/user.goapi_useras an authenticated current userpkg/modules/auth/oauth2server/authorize.gopkg/modules/auth/oauth2server/token.goSteps to Reproduce
1. Create a scoped API token
Create an API token with only the following permission:
{"oauth":["authorize"]}Observed response:
201 CreatedThe returned token had only the
oauth.authorizepermission.2. Negative control: direct access with scoped token fails
Request:
Observed response:
401 UnauthorizedResponse body:
{"code":11,"message":"missing, malformed, expired or otherwise invalid token provided"}This confirms that the scoped token cannot directly access the normal user route.
3. Obtain an OAuth authorization code with the scoped token
Request:
Body:
{ "response_type": "code", "client_id": "vikunja", "redirect_uri": "vikunja-flutter://callback", "code_challenge": "<pkce-s256-challenge>", "code_challenge_method": "S256" }Observed response:
200 OKResponse body:
{ "code": "<redacted>", "redirect_uri": "vikunja-flutter://callback", "state": "" }The scoped API token successfully obtained an OAuth authorization code.
4. Exchange the authorization code for session credentials
Request:
Body:
{ "grant_type": "authorization_code", "code": "<redacted>", "client_id": "vikunja", "redirect_uri": "vikunja-flutter://callback", "code_verifier": "<original-pkce-verifier>" }Observed response:
200 OKResponse body:
{ "access_token": "<redacted>", "token_type": "bearer", "expires_in": 600, "refresh_token": "<redacted>" }The authorization code was exchanged for a normal access token and refresh token.
5. Use the minted access token on normal routes
Request:
Observed response:
200 OKAdditional scope check:
Observed response:
200 OKThe minted OAuth access token could access normal non-OAuth routes that the original scoped API token could not access.
Expected Behavior
A scoped API token should not be able to obtain credentials with broader permissions than its declared scope.
/api/v1/oauth/authorizeshould require a normal user session or another authentication context suitable for OAuth authorization-code issuance. API-token-authenticated requests should not be accepted for minting OAuth authorization codes.Actual Behavior
A token scoped only to
oauth.authorizecan obtain an OAuth authorization code and exchange it for a normal JWT plus refresh token.The minted credentials are not restricted by the original API-token permissions.