Changeset 75ccc48 for remit


Ignore:
Timestamp:
Jun 15, 2014, 9:42:51 PM (11 years ago)
Author:
Alex Dehnert <adehnert@…>
Branches:
master
Children:
ff623c3
Parents:
5c334f6
git-author:
Alex Dehnert <adehnert@…> (06/15/14 17:51:08)
git-committer:
Alex Dehnert <adehnert@…> (06/15/14 21:42:51)
Message:

Django 1.6: Handle the removal of UNUSABLE_PASSWORD

Django 1.6 (specifically, ticket #20079) replaced a fixed UNUSABLE_PASSWORD
with a prefix followed by a random suffix, to avoid password reset attacks.
This updates the a migration to do the same.

While in theory we could do a better job of (e.g.) using different random
passwords per-user, it's unlikely that the migration will ever impact a user --
new installs won't have any users with bad passwords, and old installs have
probably already run the migration (esp.mit.edu, the only site I know of using
SocketAuth?, already seems to have).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • remit/finance_core/migrations/0004_socket_auth_password.py

    r38843de r75ccc48  
    33from south.db import db
    44from south.v2 import DataMigration
    5 from django.contrib.auth.hashers import UNUSABLE_PASSWORD
     5import django.contrib.auth.hashers
    66from django.db import models
     7from django.db.models import F
    78
    89class Migration(DataMigration):
     
    1112        "Write your forwards methods here."
    1213        issues = orm['auth.user'].objects.filter(password__in=['', 'SocketAuth'])
    13         issues.update(password=UNUSABLE_PASSWORD)
     14        try: # pre-1.6
     15            new_password = django.contrib.auth.hashers.UNUSABLE_PASSWORD
     16        except AttributeError: # post-1.6
     17            # See https://code.djangoproject.com/ticket/20079 for details on the change.
     18            # Ideally, we'd use a different suffix per user, but I don't want
     19            # to deal with that, and this is probably acceptably secure.
     20            #
     21            # Also, it seems a little unlikely that this code will actually
     22            # run -- it requires an install that hasn't already run the
     23            # migration (notably, esp.mit.edu has already), but *does* have
     24            # accounts with SocketAuth passwords.
     25            prefix = django.contrib.auth.hashers.UNUSABLE_PASSWORD_PREFIX
     26            suffix = django.contrib.auth.hashers.get_random_string(django.contrib.auth.hashers.UNUSABLE_PASSWORD_SUFFIX_LENGTH)
     27            new_password = prefix + F("password") + prefix + suffix
     28        issues.update(password=new_password)
    1429
    1530    def backwards(self, orm):
Note: See TracChangeset for help on using the changeset viewer.