Summary
An improper authorization check in wger's gym-scoped user management views allows certain privileged users without a gym assignment to reset passwords for other gym-unassigned accounts.
Because the logic incorrectly treats shared gym=None state as authorized, an attacker with gym.manage_gym and no gym can trigger a password reset and obtain the new plaintext password directly in the HTML response, resulting in full account takeover.
Affected context
The vulnerability appears in wger deployments that:
- Use the
reset_user_passwordandgym_permissions_user_editviews for gym-scoped account management, and - Have users with the
gym.manage_gympermission who may not be assigned to a specific gym (gym=None), and - Allow accounts that also have
gym=None(no gym assignment).
In this context, the authorization guard incorrectly relies on a Python object comparison to enforce gym scope, which fails when both attacker and victim share the same None gym association.
Exploit preconditions
- Attack surface: Web interface endpoints for:
reset_user_passwordgym_permissions_user_edit- Required access:
- A valid wger user account
- The
gym.manage_gympermission - The attacker's user record must have
gym=None - Target conditions:
- Victim account also has
gym=None - Trigger point:
- Attacker invokes the password reset or gym user management views targeting a gym-unassigned victim.
- Why exploitation is possible:
- The authorization check relies on a Python comparison like
attacker.gym != victim.gymor similar logic. - When both
attacker.gymandvictim.gymareNone,None != Noneevaluates toFalse, so the guard condition does not fire and the request is treated as authorized. - The endpoint then performs the password reset and embeds the new plaintext password directly in the HTML response body.
Why this happens
This issue stems from an improper authorization check where access control relies on comparing gym assignments rather than explicitly asserting allowed relationships.
The code appears to assume that differing gym objects indicate cross-gym access and should be denied, while equal gyms imply valid scope. When both parties have gym=None, the comparison inadvertently treats them as belonging to the same scope, effectively removing any gym boundary.
This maps to CWE-863: Improper Authorization, where the application makes an incorrect decision about which principal is allowed to perform a sensitive action. Instead of enforcing explicit, positive authorization rules (e.g., "this manager can only reset passwords of users in gym X and never for unscoped users"), the control relies on an object inequality that has ambiguous semantics for the None case.
Potential impact
- An attacker with
gym.manage_gymandgym=Nonecan reset the password of any othergym=Noneuser. - The attacker immediately learns the new plaintext password from the HTML response and can log in as the victim.
- Complete compromise of the victim's wger account, including personal training data and any associated permissions.
- Permanent lockout of the victim, since their original password is invalidated during the reset.
- Lateral movement to other sensitive areas in wger if the victim possesses elevated privileges.
- Privacy violations if sensitive health or workout information is stored in the compromised account.
General mitigation guidance
Security-hardening for this class of bug focuses on explicit, positive authorization checks and avoiding brittle comparisons on nullable fields:
- Enforce gym scope with clear, invariant rules such as:
- "A user with
gym.manage_gymcan only manage users whosegymmatches their own non-nullgym." - Explicitly disallow privileged actions by users with
gym=Noneunless there is a well-defined global admin role with separate checks. - Replace implicit object comparison (
!=,==) on complex or nullable authorization attributes with: - Explicit checks for
Nonestates, and - Explicit membership or role-based checks tied to the target resource.
- Avoid returning plaintext credentials in any server response:
- Generate passwords server-side but either force the user through an out-of-band reset flow (email, token), or require them to set a new password on first login.
- Store only strong password hashes and never render the raw value back to the browser after creation.
- Apply defense-in-depth around sensitive operations:
- Require re-authentication or step-up verification (e.g., password re-entry or 2FA) for account management actions like password resets.
- Use role and permission design that clearly separates global administration from gym-local management and from unscoped users.
- Regularly review and normalize authorization logic so that all access decisions are implemented through central, reusable policy abstractions instead of ad-hoc comparisons scattered across views.
How teams detect issues like this
Organizations can look for similar issues through a combination of automated and manual techniques:
- Static analysis and linting:
- Rules that flag permission checks implemented with simple object comparisons on nullable fields (
obj.attr != other.attr, especially whenattrcan beNone). - Detection of authorization decisions that depend solely on equality/inequality of resource fields rather than explicit permission checks.
- Identification of views performing sensitive actions (password resets, permission changes) without a call to centralized authorization helpers.
- Code review practices:
- Require reviewers to verify that every sensitive view:
- Uses a consistent authorization framework or decorator.
- Explicitly handles the
None/ unassigned case for scoping attributes such asgym,organization, ortenant. - Never returns plaintext passwords or secrets in templates, logs, or JSON responses.
- Check for patterns where a "scope" attribute is used as the only guard without considering global/unassigned states.
- Runtime and policy enforcement:
- Implement application-level tests that simulate cross-scope access attempts (e.g., unassigned manager attempting to manage another unassigned user).
- Use integration/acceptance tests that exercise password reset endpoints with different combinations of roles and gym assignments.
- Employ automated security scanning tools that can model multi-tenant or scoped access and flag unexpected authorization outcomes.

