-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## `None != None` is `False`. That is the entire bug.\n\nBefore commit `e1d329ff4`, the password-reset handler at `wger/gym/views/gym.py` read like this:\n\n```python\ndef reset_user_password(request, user_pk):\n \"\"\"\n Resets the password of the selected user to random password\n \"\"\"\n user = get_object_or_404(User, pk=user_pk)\n\n if not request.user.is_authenticated:\n return HttpResponseForbidden()\n\n if not request.user.has_perm('gym.manage_gyms') and not request.user.has_perm('gym.manage_gym'):\n return HttpResponseForbidden()\n\n if (\n request.user.has_perm('gym.manage_gym')\n and request.user.userprofile.gym != user.userprofile.gym\n ):\n return HttpResponseForbidden()\n\n password = password_generator()\n user.set_password(password)\n user.save()\n\n context = {'mod_user': user, 'password': password}\n return render(request, 'gym/reset_user_password.html', context)\n```\n\nThe third `if` is the tenancy gate. Read it as a prosecutor reads a defendant's prepared remarks. The check denies access \"if the caller has `manage_gym` and the caller's gym is not the same as the target user's gym.\" When both sides are unset, the comparison evaluates `None != None`. Python's `__ne__` on `NoneType` returns `False`. The gate does not fire. Control falls through to `password_generator()`, `user.set_password(password)`, and the render call that hands the new credential back to the caller.\n\nThe patch replaced the comparison with a helper:\n\n```python\n# wger/gym/helpers.py\ndef is_same_gym(user_a, user_b):\n \"\"\"\n Returns True only when both users are members of the same, non-null gym\n \"\"\"\n gym_a = user_a.userprofile.gym_id\n gym_b = user_b.userprofile.gym_id\n return gym_a is not None and gym_a == gym_b\n```\n\nTwo changes. First, compare by `gym_id`, the integer foreign-key column, instead of by `gym`, the related model instance. Second, explicitly assert that the caller's `gym_id` is non-null before allowing any match. The first change is cosmetic for the bug we are describing; `None != None` is `False` on either form. The second clause is the fix. The original code intended to encode \"two users are in the same gym,\" and the encoding it chose (\"their gym fields are unequal\") happens to be `False` for the case the check most wanted to exclude: two users who are in no gym at all.\n\nThe replacement helper has two lines, and the load-bearing one is the second. `is_same_gym` has to assert `gym_a is not None` because the developer cannot trust Python equality to mean tenancy. The bug was that the developer had been trusting it, in nine functions, for years.\n\n## The plaintext password is in the response by design\n\nThe handler does not generate a reset token. It does not mail a reset link. It does not write to a notification queue. It returns the new password as rendered template content:\n\n```python\ncontext = {'mod_user': user, 'password': password}\nreturn render(request, 'gym/reset_user_password.html', context)\n```\n\nThe template, added in 2015 in commit `0540bdaeb` by a contributor named James Simas, is the entirety of the disclosure surface:\n\n```html\n\n {% trans \"User\" %}\n {{mod_user.get_full_name}} ({{mod_user}})\n\n\n {% trans \"Password\" %}\n {{password}}\n\n```\n\nThe sidebar copy that ships next to the table reads, in part: \"Please notify the user of their new password.\" That is the design. The handler was written for the case where a trainer at a physical gym is helping a gym member who forgot their password, and reads the new password to them across a desk. The plaintext-in-response was a feature of the trainer-with-clipboard threat model. In that model, the requesting trainer is the trusted intermediary. The model does not survive a precondition where the requester is an orphaned gym manager invoking the endpoint over HTTP from somewhere outside the gym.\n\nThe 2015 commit message lists two known issues the author wanted to address before merge. \"1. There is no confirmation dialogue for resetting the user's password, so if an admin clicks the link by accident, it will reset the password.\" \"2. It's not translatable.\" Cross-tenant disclosure is not on the list. The author was thinking about UX and i18n; they were not thinking about what the response shape becomes when the calling trainer is not in the room.\n\nThe trainer-with-clipboard assumption lived in the template for eleven years before it was tested by someone who was not a trainer.\n\n## The first patch fixed five callsites. The second patch fixed four more.\n\nThe vulnerable comparison was not one handler. It was a copy-paste idiom across two Django apps. The replacement is also a copy-paste idiom, and it had to be applied nine times.\n\nRoland Geider's first commit, `e1d329ff4`, landed on April 26, 2026, two days before the CVE was published. It replaced five comparisons with `is_same_gym`:\n\n- `wger.gym.views.gym.reset_user_password`\n- `wger.gym.views.gym.gym_permissions_user_edit`\n- `wger.core.views.user.trainer_login`\n- `wger.core.views.user.UserEditView.dispatch`\n- `wger.core.views.user.UserDetailView.dispatch`\n\nThe advisory the CVE was filed against names the first three. The other two are the maintainer's own audit-as-you-go work, the comparison grepped for and fixed where it was found. Each diff hunk is uniform: `a.userprofile.gym != b.userprofile.gym` becomes `not is_same_gym(a, b)`.\n\nTen days later, on May 8, 2026, the maintainer pushed commit `635d1dc4` with the title \"Properly (hopefully) check for all gym permission checks with helper function\" and the body \"This is necessary to correctly handle the gym=None case.\" That commit patched four more callsites that the first audit had missed:\n\n- `wger.core.views.user.delete`, the destructive account-delete handler\n- `wger.core.views.user.UserDeactivateView.dispatch`\n- `wger.core.views.user.UserActivateView.dispatch`\n- `wger.core.views.user.UserDetailView.get_context_data`, where `enable_login_button` was decided by `same_gym_id = request_user.userprofile.gym_id == page_user.userprofile.gym_id`\n\nEach of those four had the same bug. The `delete` handler's pre-patch condition was a four-line boolean chain in which the load-bearing line was `or request.user.userprofile.gym_id != user.userprofile.gym_id`. The same `None != None` collapse, on the same field, with the same outcome: an orphaned manager could delete the account of any publicly-registered user.\n\nThe CVE record covers only the handlers in the first patch. The other four were silent fixes shipped against the same root cause without a separate identifier. Defenders auditing against `CVE-2026-43948` and version `<= 2.5` will not see the second commit named in their tracker; they will see `2.6` as the patched version and trust the surface the CVE describes. The shape was the same. The fan-out was the codebase.\n\nThe maintainer wrote \"(hopefully)\" in the second commit's title because there is no static analyzer in the wger CI that says \"this Python equality cannot return False when both sides are `None`.\" The audit was a `grep` run by a human, twice. The first run found five. The second run found four more. There is no procedure that will tell a defender there is not a tenth.\n\n## What \"no gym\" is\n\nA wger instance with public registration creates new users with `gym=None`. That is the default state for the largest user population on every wger deployment that accepts sign-ups. An orphaned gym manager, whose gym record was deleted, or whose `gym_manager` group membership was set without a gym assignment, also has `gym=None`. The check the maintainer wrote, in nine places, declared `None == None` to be membership.\n\nThe exploit precondition is narrow on a properly-configured deployment, an attacker has to hold `manage_gym` permission AND have `gym=None`, and `manage_gym` is admin-granted, not public. The precondition is not narrow at all on the deployment shapes wger most commonly takes: single-instance self-hosted Django apps where a small admin team manages roles by hand, instances where a gym was created and later deleted, and instances run without any real gym infrastructure where the operator uses wger as a personal fitness tracker for friends. On each of those shapes, the population of users sharing the `gym=None` tenant is \"almost everyone,\" and a single orphaned manager attacks the lot.\n\nThe response from the patched handler in the legitimate case is HTTP 200 with the plaintext password in the rendered HTML. The response from the pre-patch handler in the bypass case was also HTTP 200 with the plaintext password in the rendered HTML. There is no visible difference. The auth gate's only contribution to the response was deciding whether the body was that page or a 403. The body itself was unchanged.\n\n## The pattern\n\nThis is `null-equals-null`. A multi-tenant authorization check encoded as Python equality between two model fields that can both legitimately be `None`. The sentinel that means \"no tenant\" becomes the membership of a shared default tenant, and the check that was supposed to deny cross-tenant access waves through the population that lives in the sentinel.\n\nThe defender's playbook against this class is to never encode tenancy as raw equality. Either compare by a non-null assertion plus equality (the `is_same_gym` shape), or model the absent state as a distinct entity (a synthetic \"no-tenant\" sentinel row that participates in tenancy comparisons but denies every cross-call) so the equality check is between two real values rather than between two `NoneType`s. The wger maintainer chose the first. The second commit's title says \"(hopefully)\" because the first option requires the helper to be invoked at every callsite, and the audit that confirms invocation everywhere is a human grep.\n\nThe deeper pattern is `Design Debt Driver`. The substrate is a Django model where `userprofile.gym` returns `None` for unassigned users, and the developer reaches for `!=` without thinking about what that operator returns when both operands are `None`. The same copy-paste idiom shipped in nine functions across eleven years. Each instance was a CVE waiting for someone to test it with both gyms unset. The patch closes nine. The substrate ships unchanged.\n\nPoC: [GHSA-mhc8-p3jx-84mm](https://github.com/advisories/GHSA-mhc8-p3jx-84mm)\n","closing_line":"The CVE record names one handler. The fix had to be written nine times.","hook_md":"wger is an open-source workout and gym-management application written in Django. Its multi-tenant authorization model scopes a gym manager's authority to the gym they manage, enforced by a line that shipped in nine handlers across two files: `if request.user.userprofile.gym != user.userprofile.gym: return HttpResponseForbidden()`. Public registration on a wger instance creates a user with `gym=None`. Orphaned gym managers, those whose gym record was deleted or whose group membership was set without a gym assignment, also have `gym=None`. In Python, `None != None` evaluates to `False`. The check does not deny. The `reset_user_password` handler generates a new password, calls `user.set_password(password)`, and renders the plaintext into the HTTP response. CVE-2026-43948 was published April 28, 2026. The maintainer's first patch closed five callsites. The second patch, ten days later, closed four more, with a commit message containing the only honest word in the disclosure: \"hopefully.\"","post_id":342,"slug":"wger-cve-2026-43948-none-is-a-gym","title":"CVE-2026-43948: wger's Tenancy Check Treats No Gym As A Gym Everyone Shares","type":"initial","unreadable_sentence":"The CVE record names one handler. The fix had to be written nine times."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCajQuAgAKCRDeZjl4jgkQ JvVvAP9H07VXY42jZUOLaWuHyOVy8AQ4J6Hijq6E6QPhHrqvQAD+Ld/fcMRluILa sBUNXcjss4Y7nlyjfb+uAA7MW4PY8ws= =Kdq7 -----END PGP SIGNATURE-----