#37514 new Bug

UserAdmin allows adding users without change permission through _saveasnew

Reported by: Sarah Boyce Owned by:
Component: contrib.auth Version: 6.1
Severity: Normal Keywords: not-security
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

UserAdmin requires both add and change permissions to create users. See ​https://github.com/django/django/blob/9e2e5a31e2ef2e8673d3c2a38d2a391dbf42cf23/django/contrib/auth/admin.py#L122-L129

However, the additional change permission check can be bypassed by posting to a user’s change URL with _saveasnew.
The POST is processed even with the default save_as=False.

Here is a test to show the behavior:

  • tests/auth_tests/test_views.py

    a b class ChangelistTests(MessagesTestMixin, AuthViewsTestCase):  
    15071507            )
    15081508        self.assertEqual(response.status_code, 400)
    15091509
     1510    def test_save_as_new_requires_change_permission(self):
     1511        user = User.objects.create_user(username="add_only", is_staff=True)
     1512        add_permission = Permission.objects.get(codename="add_user")
     1513        user.user_permissions.add(add_permission)
     1514        self.client.force_login(user)
     1515
     1516        data = {
     1517            "username": "new_user",
     1518            "usable_password": "true",
     1519            "password1": "a-long-test-password-123",
     1520            "password2": "a-long-test-password-123",
     1521            "_saveasnew": "Save as new",
     1522        }
     1523        for url in [
     1524            reverse("admin:auth_user_add"),
     1525            reverse("admin:auth_user_change", args=[user.pk])
     1526        ]:
     1527            with self.subTest(url=url):
     1528                response = self.client.post(url, data)
     1529                self.assertEqual(response.status_code, 403)
     1530                self.assertFalse(User.objects.filter(username="new_user").exists())
     1531
    15101532    def test_user_change_email(self):
    15111533        data = self.get_user_data(self.admin)

This was reviewed by the Django Security Team and is being handled as a permissions consistency bug rather than a security issue. With the default UserAdmin, this path still uses the restricted user creation form: submitted privilege fields such as is_superuser are ignored, and the created account is an ordinary user.

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top