CVE-2026-114137: Django REST framework: TokenProxy.delete() reports success and revokes nothing
High CVSS 7.4
- OSV id
- GHSA-xw6w-gcfp-cf8m
- Also known as
- CVE-2026-114137
- Published
- Last modified
Affected packages
| Package | Affected versions | Fixed in |
|---|---|---|
| djangorestframework PyPI |
>= 3.12.0, < 3.18.2 | 3.18.2 |
Versions we track that it affects: djangorestframework 3.15.1
How to fix it
Upgrade djangorestframework to 3.18.2 or later.
# in requirements.txt: change the line to djangorestframework==3.18.2
pip install -r requirements.txt
- If it is an indirect dependency, upgrade the package that depends on it, or add a minimum version constraint for it (e.g. in constraints.txt, or as a dependency in pyproject.toml).
- Check the changelog for breaking changes (especially across major versions), update the lockfile with the package manager, and run your tests.
Not sure whether your project uses an affected version? Check your lockfile below for free.
Details
Summary
Deleting an authentication token through TokenProxy silently deletes nothing. The call raises no
exception and reports success, the database row survives, and the token keeps authenticating. Any
application, admin integration or operational script that revokes credentials by calling .delete()
on a TokenProxy instance believes it has revoked a token that is still live.
Details
TokenProxy overrides pk to return the user id (rest_framework/authtoken/models.py:49-63):
@property
def pk(self):
return self.user_id
The concrete Token model keys on key, not on an integer id. Model.delete() builds its delete
query from pk, so it emits:
DELETE FROM "authtoken_token" WHERE "authtoken_token"."key" IN ('1')
That matches a user id against the 40-character key column. Nothing matches, nothing raises, and the
call returns (0, {'authtoken.TokenProxy': 0}).
DRF already ships two workarounds for this same identity mismatch instead of a fix. In
rest_framework/authtoken/admin.py, TokenAdmin.delete_model re-fetches the concrete row:
def delete_model(self, request, obj):
Token.objects.get(key=obj.key).delete() # admin.py:30
and TokenAdmin sets actions = None with the comment "Actions not compatible with mapped IDs"
(admin.py:50-53). The shipped admin path is therefore safe, and every other caller of
TokenProxy.delete() is not. Nothing in the API signals the difference.
TokenProxy was added by e2bd3b6a (PR #7341, "Adjusted token admin to map to user ID"), first
released in 3.12.0.
A fix would drop the pk override, or give TokenProxy a delete() that operates on the concrete
row, or raise instead of silently reporting zero deletions.
PoC
Save as poc_tokenproxy_revocation.py and run it.
```python
!/usr/bin/env python
""" django-rest-framework: TokenProxy.delete() reports success and revokes nothing.
baseline token exists -> 200 TRIGGER TokenProxy.objects.get(...).delete() -> no exception, row survives, still 200 CONTROL Token.objects.get(key=...).delete() -> row gone, 401
The control is what makes the trigger meaningful: it proves the row was deletable and the credential check live, so the 200 after the proxy delete is a failed revocation and not a broken harness.
Requires: django, djangorestframework importable. No arguments. python poctokenproxyrevocation.py Exit status 0 means the revocation failure reproduced. """ import sys
import django from django.conf import settings
settings.configure( DEBUG=False, SECRETKEY="poc", ALLOWEDHOSTS=["*"], ROOTURLCONF=name, INSTALLEDAPPS=[ "django.contrib.contenttypes", "django.contrib.auth", "restframework", "restframework.authtoken", ], DATABASES={"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:"}}, DEFAULTAUTOFIELD="django.db.models.AutoField", USE_TZ=True, ) django.setup()
from django.contrib.auth import getusermodel # noqa: E402 from django.core.management import call_command # noqa: E402 from django.db import connection # noqa: E402 from django.test import Client # noqa: E402 from django.test.utils import CaptureQueriesContext # noqa: E402 from django.urls import path # noqa: E402
from restframework.authentication import TokenAuthentication # noqa: E402 from restframework.authtoken.models import Token, TokenProxy # noqa: E402 from restframework.permissions import IsAuthenticated # noqa: E402 from restframework.response import Response # noqa: E402 from rest_framework.views import APIView # noqa: E402
class Whoami(APIView): authenticationclasses = [TokenAuthentication] permissionclasses = [IsAuthenticated]
def get(self, request):
return Response({"user": request.user.get_username()})
urlpatterns = [path("", Whoami.as_view())]
def probe(client, key): response = client.get("/", headers={"authorization": "Token %s" % key}) return response.status_code
def main(): callcommand("migrate", runsyncdb=True, verbosity=0) user = getusermodel().objects.create_user(username="revoke-user", password="pw") key = Token.objects.create(user=user).key client = Client()
print("TokenProxy._meta.proxy =", TokenProxy._meta.proxy)
print("Token._meta.pk.attname =", Token._meta.pk.attname)
print("user.pk =", user.pk)
print("token key =", key)
print("\n--- baseline")
print("rows =", Token.objects.count())
baseline = probe(client, key)
print("GET / with token ->", baseline)
print("\n--- TRIGGER: delete through the proxy")
proxy = TokenProxy.objects.get(user=user)
print("proxy.pk =", proxy.pk, "(TokenProxy.pk property)")
raised = None
with CaptureQueriesContext(connection) as ctx:
try:
returned = proxy.delete()
ex
References
- GHSA-xw6w-gcfp-cf8m on OSV.dev
- Web: https://github.com/encode/django-rest-framework/security/advisories/GHSA-xw6w-gcfp-cf8m
- Advisory: https://nvd.nist.gov/vuln/detail/CVE-2026-114137
- Web: https://github.com/encode/django-rest-framework/commit/af3fabfd517307fbc5d500fba1ab8f6e25f220b0
- Package: https://github.com/encode/django-rest-framework
- Web: https://github.com/encode/django-rest-framework/releases/tag/3.18.2
Am I affected?
Upload or paste your lockfile. We check every package version in it against OSV.dev, this advisory included, and email you the vulnerable ones with the version that fixes them. Free, and no account needed.
About this data
Source: GitHub Advisory Database via OSV.dev (CC-BY 4.0). Severity comes from the advisory's own rating when it has one, else from its CVSS score.