---
title: "django-guardian’s get_objects_for_user returns every object when two models share a permission codename"
slug: django-guardian-codename-collision
draft: false
date: "2026-11-24"
datetime: "2026-11-24T06:36:19Z"
updated: "2026-11-24"
description: "django-guardian tests global permissions by the bare app_label.codename string. When two models in one app share a codename, a user holding only one model’s permission passes the other model’s check…"
abstract: >-
  Django keeps one Permission row per (content_type, codename), so two models in one app may both define can_publish. django-guardian’s get_objects_for_user resolves the requested codenames against the queried model’s content type but tests the user’s global permissions with user.has_perm("app.codename"), which cannot see the content type. A user holding only the other model’s global permission passes the test, the matching codename is removed, and with no codenames left the function returns the full queryset. We reproduced it on django-guardian 3.5.2, the current release, and on its PermissionListMixin. The sibling get_objects_for_group was fixed for this exact class in 3.5.2; the user-facing function was not. No advisory or CVE covers this collision.
authors:
  - name: EZO Labs Security
    url: https://ezolabs.net
section: environments
report_number: EZO-R-2026-25
lang: en
og:
  kicker: "EZO LABS // SECURITY"
  title:
    - "django-guardian’s"
    - "get_objects_for_user returns"
    - "every object when two models"
  foot:
    - "An independent write-up."
    - "Notes from the disclosure."
bibtex_key: djangoguardiancodenamecollision
revisions:
  - date: "2026-11-24"
    note: "First publication."
license: cc-by-4.0
---

## Summary

A permission in Django is an app label and a codename. It does not name a model. django-guardian’s user-facing lookup treats that string as sufficient, while the group lookup it fixed in 3.5.2 does not.

## The gap

`get_objects_for_user` tests a global permission with the bare `app_label.codename` string, so a permission row belonging to a different model in the same app satisfies it, the codename is dropped, and the function returns every object of the queried model.

- `guardian/shortcuts.py:691`: The global-permission test is `user.has_perm(ctype.app_label + "." + code)`, which cannot see the content type.
- `guardian/shortcuts.py:692-693`: The matching codename is removed from the set once any codename matches.
- `guardian/shortcuts.py:700-701`: With no codenames left, the function returns the full queryset.
- `guardian/shortcuts.py:887-889`: The sibling `get_objects_for_group` (fixed in 3.5.2) filters `content_type=ctype, codename__in=codenames`, the model-aware form `get_objects_for_user` lacks.

## Reproduction

A two-model app (`Project`, `Article`, both declaring `can_publish`) in in-memory SQLite; alice holds only `Article.can_publish`; `get_objects_for_user(alice, ["can_publish"], klass=Project)`, the `PermissionListMixin`, and `get_objects_for_group(team, ["can_publish"], klass=Project)` are called in one run.

alice -> `['p1','p2']`; dave (same, via his group) -> `['p1','p2']`; carol (`Project.can_publish`, control) -> `['p1','p2']`; bob (nothing) -> `[]`; `get_objects_for_group(team, ['can_publish'], klass=Project)` -> `[]`; `PermissionListMixin` for alice -> `['p1','p2']`.

## Impact

A user who holds a global permission belonging to a different model in the same app is granted every object of the queried model: list views, admin screens and bulk actions built on `get_objects_for_user` or `PermissionListMixin` show and operate on rows the user holds no permission on, so the user reads and can act on records outside their authorization boundary.

## Affected versions

All releases through `django-guardian 3.5.2` (still the latest release, uploaded 2026-10-20) that carry the model-blind global test; the same branch is present throughout the 3.x and 2.x lines. No patched version exists.

## Fix status

No release carries the fix. The change is to scope the global-permission test to the queried content type, as `get_objects_for_group` does since 3.5.2 (commit `99867b8`), instead of testing `user.has_perm("<app_label>.<codename>")`.

## The vendor’s record

The maintainer accepted the report and a draft advisory exists (`GHSA-3m3v-3wmf-wr4c`, `submission.accepted: true`); the draft is unpublished and no CVE is assigned. No vendor comment disputes the defect.

## Timeline

- 2026-11-09T08:07:43Z: Private report filed (`GHSA-3m3v-3wmf-wr4c`)
- 2026-11-09T10:00:59Z: Draft accepted (inferred from `updated_at`)
- 2026-11-12T01:04:33Z: Comment 369868 posted in the advisory thread with an empty body
- 2026-11-12T15:30:56Z: Class-anchored publish ask added to comment 369868 by edit
- 2026-11-18: The draft remained unpublished; no further notice was sent
- 2026-11-23T10:00:59Z: Deadline passed with the draft unpublished
- 2026-11-24T06:36:19Z: This write-up published
- 2026-11-24: MITRE CNA-LR request submitted

## References

- get_objects_for_group: filter group permissions on content_type: https://github.com/django-guardian/django-guardian/commit/99867b8
- Private report: https://github.com/django-guardian/django-guardian/security/advisories/GHSA-3m3v-3wmf-wr4c

## Disclosure

This note is an independent write-up. It is published on 2026-11-24 as the public reference for a CVE request. The private advisory and this write-up describe the same defect; the vendor advisory named above is the authority where one exists.
