Summary
A flawed session-based permission check in wger allows a gym trainer to escalate their session to higher-privileged roles by repeatedly invoking the trainer-login endpoint.
If a trainer can legitimately switch into a low-privileged user once, a session flag is set that bypasses further authorization checks, potentially granting full gym administration capabilities.
Affected context
This vulnerability appears in wger deployments where gym trainers are allowed to impersonate or switch into member accounts via the trainer-login endpoint.
The issue manifests when the application relies on a single session flag (trainer.identity) to authorize subsequent role switches, without re-validating the trainer's original permissions or target role.
Environments that maintain long-lived web sessions and do not enforce strict role checks on every login-like action are particularly exposed.
Exploit preconditions
- Attack surface: Web application trainer-login endpoint exposed to authenticated trainers.
- Required access: Valid trainer account with the ability to perform a legitimate switch into a low-privileged user (e.g., gym member).
- Trigger point: Performing two chained calls to the trainer-login endpoint, first as designed, then targeting a higher-privileged account.
- Why exploitation is possible: The application sets a
trainer.identitysession flag after the first legitimate switch and subsequently treats this flag as sufficient proof of authority, skipping per-request authorization checks when switching into higher-privileged accounts.
Why this happens
The root cause is an authorization design flaw where session state is over-trusted instead of enforcing role and ownership checks on every sensitive operation.
After a trainer legitimately switches into a low-privileged user, the system records a trainer.identity flag in the session and uses it as a blanket indicator that the user may access the trainer-login functionality for any target identity.
This aligns with CWE-269: Improper Privilege Management, because the application fails to correctly isolate privileges between roles and does not constrain privilege elevation paths, allowing a lower-privileged actor to assume higher-privileged identities.
Potential impact
- A trainer may assume any higher-privileged role, including gym manager or general manager accounts.
- An attacker could view all member profiles, training data, and personal information stored in the system.
- Contracts, memberships, and billing-related configuration could be modified or terminated.
- Global gym configuration, including system settings and policies, can be altered.
- Other trainers' and managers' personal and administrative data may be exposed or tampered with.
General mitigation guidance
Effective mitigation focuses on enforcing strict, per-request authorization and minimizing reliance on coarse session flags:
- Validate permissions on every trainer-login request by checking the authenticated user's role and confirming that they are allowed to impersonate the specific target account.
- Replace generic session flags with scoped, verifiable tokens that encode the permissible target identity and expire quickly.
- Apply least-privilege principles so that impersonation features are restricted to exact roles and specific actions, not broad administrative capabilities.
- Introduce defense-in-depth checks on sensitive functions (e.g., contract management, configuration changes) to ensure that only appropriate roles can perform them, regardless of session history.
- Regularly review impersonation and "login-as" patterns to ensure clear separation between support tooling and end-user sessions.
How teams detect issues like this
Detection typically combines code-level review and runtime monitoring:
- Use static analysis and manual code review to flag authorization logic that relies solely on session flags or boolean markers instead of explicit role and subject checks.
- Search for controller or view logic that allows identity switching without validating both the source role and the target account on each request.
- Implement security logging around impersonation features, capturing source user, target user, role, and time, then monitor for suspicious patterns (e.g., trainers accessing manager accounts).
- Employ automated security tests or fuzzing that attempt chained logins and role escalations across all "login-as" or impersonation endpoints.

