GitHub Security Advisory: GHSA-667w-mmh7-mrr4
Package: studiocms (NPM)
Severity: HIGH (CVSS 8.8)
CWE: CWE-639: Authorization Bypass Through User-Controlled Key, CWE-863: Incorrect Authorization
Vulnerable versions: <= 0.3.0
Patched in: 0.4.0

Summary: StudioCMS has Privilege Escalation via Insecure API Token Generation

Details:
## Summary
The /studiocms_api/dashboard/api-tokens endpoint allows any authenticated user (at least Editor) to generate API tokens for any other user, including owner and admin accounts. The endpoint fails to validate whether the requesting user is authorized to create tokens on behalf of the target user ID, resulting in a full privilege escalation.

## Details
The API token generation endpoint accepts a user parameter in the request body that specifies which user the token should be created for. The server-side logic authenticates the session (via auth_session cookie) but does not verify that the authenticated user matches the target user ID nor checks if the caller has sufficient privileges to perform this action on behalf of another user.
This is a classic BOLA vulnerability: the authorization check is limited to "is the user logged in?" instead of "is this user authorized to perform this action on this specific resource?"

#### Vulnerable Code
The following is the server-side handler for the POST /studiocms_api/dashboard/api-tokens endpoint:
**File:** packages/studiocms/frontend/pages/studiocms_api/dashboard/api-tokens.ts (lines 16–57)
**Version:** studiocms@0.3.0
```
POST: (ctx) =>
    genLogger('studiocms/routes/api/dashboard/api-tokens.POST')(function* () {
        const sdk = yield* SDKCore;

        // Check if demo mode is enabled
        if (developerConfig.demoMode !== false) {
            return apiResponseLogger(403, 'Demo mode is enabled, this action is not allowed.');
        }

        // Get user data
        const userData = ctx.locals.StudioCMS.security?.userSessionData;       // [1]

        // Check if user is logged in
        if (!userData?.isLoggedIn) {                                            // [2]
            return apiResponseLogger(403, 'Unauthorized');
        }

        // Check if user has permission
        const isAuthorized = ctx.locals.StudioCMS.security?.userPermissionLevel.isEditor;  // [3]
        if (!isAuthorized) {
            return apiResponseLogger(403, 'Unauthorized');
        }

        // Get Json Data
        const jsonData = yield* readAPIContextJson<{
            description: string;
            user: string;                                                       // [4]
        }>(ctx);

        // Validate form data
        if (!jsonData.description) {
            return apiResponseLogger(400, 'Invalid form data, description is required');
        }

        if (!jsonData.user) {
            return apiResponseLogger(400, 'Invalid form data, user is required');
        }

        // [5] jsonData.user passed directly — no check against userData
        const newToken = yield* sdk.REST_API.tokens.new(jsonData.user, jsonData.description);

        return createJsonResponse({ token: newToken.key });                     // [6]
    }),
```
**Analysis**
The authorization logic has three distinct flaws:
1. **Insufficient permission gate [1][2][3]:** The handler retrieves the session from ctx.locals.Stu