Skip to content

Commit

Permalink
[1.5.x] Fixed #20078: don't allow filtering on password in the user a…
Browse files Browse the repository at this point in the history
…dmin.

Backport of 9e462f8 from master.
  • Loading branch information
jacobian committed Mar 27, 2013
1 parent 572a300 commit 87f4860
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
6 changes: 6 additions & 0 deletions django/contrib/auth/admin.py
Expand Up @@ -83,6 +83,12 @@ def get_urls(self):
self.admin_site.admin_view(self.user_change_password))
) + super(UserAdmin, self).get_urls()

def lookup_allowed(self, lookup, value):
# See #20078: we don't want to allow any lookups involving passwords.
if lookup.startswith('password'):
return False
return super(UserAdmin, self).lookup_allowed(lookup, value)

@sensitive_post_parameters()
@csrf_protect_m
@transaction.commit_on_success
Expand Down
18 changes: 18 additions & 0 deletions django/contrib/auth/tests/urls_admin.py
@@ -0,0 +1,18 @@
"""
Test URLs for auth admins.
"""

from django.conf.urls import patterns, include
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin, GroupAdmin
from django.contrib.auth.models import User, Group
from django.contrib.auth.urls import urlpatterns

# Create a silo'd admin site for just the user/group admins.
site = admin.AdminSite(name='auth_test_admin')
site.register(User, UserAdmin)
site.register(Group, GroupAdmin)

urlpatterns = urlpatterns + patterns('',
(r'^admin/', include(site.urls)),
)
15 changes: 15 additions & 0 deletions django/contrib/auth/tests/views.py
Expand Up @@ -516,3 +516,18 @@ def test_security_check(self, password='password'):
self.assertTrue(good_url in response['Location'],
"%s should be allowed" % good_url)
self.confirm_logged_out()

@skipIfCustomUser
class ChangelistTests(AuthViewsTestCase):
urls = 'django.contrib.auth.tests.urls_admin'

# #20078 - users shouldn't be allowed to guess password hashes via
# repeated password__startswith queries.
def test_changelist_disallows_password_lookups(self):
# Make me a superuser before loging in.
User.objects.filter(username='testclient').update(is_staff=True, is_superuser=True)
self.login()

# A lookup that tries to filter on password isn't OK
with self.assertRaises(SuspiciousOperation):
response = self.client.get('/admin/auth/user/?password__startswith=sha1$')

0 comments on commit 87f4860

Please sign in to comment.