Summary
InvenTree's API allows any authenticated user to create API tokens on behalf of other users by specifying an arbitrary user ID in token-creation requests.
This enables impersonation of administrators and superusers, granting full API access as the target account from any location without additional interaction.
Affected context
This vulnerability occurs in InvenTree deployments where API authentication relies on user tokens created via the /api/user/tokens/ endpoint.
The issue manifests when the backend accepts a user identifier from the client and applies it directly to the new token without verifying that the caller is allowed to create tokens for that specific account.
Any environment that exposes the API to authenticated users and treats tokens as equivalent to full user identity is affected, regardless of network location, because issued tokens can be used from anywhere.
Exploit preconditions
- Attack surface: HTTP(S) API endpoint
POST /api/user/tokens/ - Required access: Any valid authenticated InvenTree user account (even low-privileged)
- Trigger point: Sending a token creation request that includes another user's ID in the
userfield - Why exploitation is possible: The server trusts the client-supplied
useridentifier and does not enforce that the token owner matches the authenticated principal or that the caller has delegated-administration rights over the specified user
Why this happens
The underlying flaw is a missing authorization check when binding new API tokens to user accounts.
Instead of deriving the token owner from the authenticated session (or verifying that the caller is permitted to act on behalf of the specified user), the implementation uses a client-controlled user field to select the account.
This aligns with CWE-639: Insecure Direct Object Reference (IDOR) for Authorization, where access to a protected object (in this case, the ability to create tokens for a user account) is controlled solely by user-supplied identifiers without adequate permission checks.
Conceptually, the system exposes an administrative action—impersonation-level token issuance—on a multi-tenant object (user account) but bases authorization on trust of the incoming parameter rather than the authenticated identity.
Potential impact
- An attacker may create valid API tokens for administrator or superuser accounts.
- An attacker can perform any API operation that the impersonated user is allowed to perform, including configuration changes and data access.
- The attacker may exfiltrate sensitive inventory and operational data accessible to privileged users.
- The attacker can perform destructive actions such as modifying or deleting records under a trusted identity, complicating forensic analysis.
- Compromised tokens can be used from arbitrary network locations, enabling persistent unauthorized access until revoked.
General mitigation guidance
Effective mitigation focuses on enforcing strict authorization semantics around token creation and ownership:
- Bind token ownership to the authenticated principal by default; ignore or remove any client-supplied user identifier for self-service token creation.
- Where delegated administration is necessary, implement explicit role-based checks before allowing one user to create tokens for another, and constrain this to narrowly defined roles.
- Centralize authorization logic for user-related actions so that user ID parameters are always checked against the caller's identity and permissions.
- Reduce token privileges and lifetime by default (e.g., short-lived, scoped tokens) so that misuse has a smaller blast radius.
- Log all token creation events with the authenticated actor, target user, IP address, and associated context to support detection and incident response.
How teams detect issues like this
Detection efforts can focus on both code-level indicators and runtime behavior:
- Static/code review: Search for endpoints that accept a
user,user_id, or similar field from the client and then perform actions on user-linked objects without comparing it to the authenticated user or enforcing role checks. - Authorization policy checks: Verify that token-issuance logic always consults a centralized permission layer and does not bypass it for convenience or reuse internal-only APIs in public contexts.
- Automated analysis: Configure SAST or API-linter rules to flag patterns where user identifiers from requests are used directly to select user accounts or security-sensitive resources.
- Runtime monitoring: Analyze logs for suspicious patterns, such as low-privilege accounts creating tokens for higher-privilege users, sudden surges in token creation, or tokens for privileged accounts being created from atypical IP ranges or user agents.

