Summary
Craft CMS contains an improper authorization flaw in the user impersonation flow, where a low-privilege or shared-URL user can abuse the UsersController->actionImpersonateWithToken endpoint to become an administrator.
When an attacker can obtain or trigger a valid impersonation token without appropriate privilege checks, they can escalate to full admin access and take over the CMS instance.
Affected context
The vulnerability appears in Craft CMS installations that:
- Run affected 4.x or 5.x versions where
UsersController->actionImpersonateWithTokenis exposed - Use shared URLs or tokenized links that allow limited access for low-privilege or unauthenticated users
- Rely on user impersonation features without strict server-side permission enforcement
It becomes relevant in deployments where support, preview, or account-sharing workflows use impersonation tokens and assume those tokens cannot grant higher privileges than the current user.
Exploit preconditions
- Attack surface: Web application (HTTP endpoints of Craft CMS).
- Required access: A low-privilege account, or access to a shared URL that grants limited, token-based access.
- Trigger point: Invoking
UsersController->actionImpersonateWithTokenwith a crafted or existing impersonation token. - Why exploitation is possible: The impersonation endpoint does not sufficiently validate that the caller is authorized to impersonate the targeted account, allowing token-based escalation from a constrained context to administrator privileges.
Why this happens
This issue stems from improper authorization checks around user impersonation, mapping to CWE-863: Improper Authorization.
The actionImpersonateWithToken logic trusts the presence and validity of an impersonation token but does not rigorously tie that token to the requester's current privileges or intended scope.
As a result, a low-privilege or shared-URL user can leverage a token to impersonate an administrator, bypassing normal access-control rules.
Conceptually, this is an authorization bug where a high-privilege action (impersonating an admin) is gated only by token possession rather than by a combination of identity, role, and context-aware permission checks.
Potential impact
- Full administrative access to the Craft CMS instance.
- Creation, modification, or deletion of content and site configuration.
- Management of user accounts, including adding or removing admin users.
- Access to sensitive data stored in the CMS, including private content and configuration secrets.
- Installation or modification of plugins and templates that could introduce additional security risks.
- Lateral movement into integrated services if the CMS is used as a control plane or integration hub.
General mitigation guidance
Mitigation focuses on enforcing strict, role-aware authorization for impersonation and token-based access:
- Treat impersonation as a high-risk capability that is restricted to explicitly privileged roles (e.g., admins with a dedicated permission).
- Bind impersonation tokens to both the issuer and the target account, ensuring the requester cannot use tokens beyond their own effective privileges.
- Make impersonation tokens short-lived, single-use, and tightly scoped to specific actions or views instead of granting full account control.
- Validate, on every impersonation request, that the caller's current session and role are allowed to impersonate the requested user.
- Reduce reliance on broadly scoped shared URLs; where necessary, constrain them to read-only or narrowly defined operations.
- Apply the principle of least privilege in user and role design so that accidental escalation paths are minimized even if a token is misused.
How teams detect issues like this
Effective detection strategies include:
- Reviewing controller actions handling impersonation or token-based login for:
- Missing role checks before switching identities
- Logic that trusts token possession without validating caller privileges
- Flows where low-privilege or unauthenticated contexts can reach impersonation endpoints
- Using static analysis rules to flag patterns such as:
- Account context changes (
impersonate,switchUser,loginAs) without adjacent authorization checks. - Implementing logging and monitoring for:
- Impersonation events, especially those originating from shared URLs or non-admin accounts.
- Sudden privilege changes or admin-level activity from previously low-privilege users.
- Enforcing security review of features involving:
- Magic links, shared URLs, or token-based access mechanisms.
- Administrative workflows that act "on behalf of" another user.
- Leveraging automated application security testing tools that:
- Exercise token-based and impersonation endpoints.
- Attempt privilege escalation from low-privilege sessions.

