Ticket #18923: 0001-Fixed-18923-Add-decorator-sensitive_post_parameters_.patch

File 0001-Fixed-18923-Add-decorator-sensitive_post_parameters_.patch, 3.3 KB (added by zbohm, 12 years ago)
  • django/contrib/auth/admin.py

    diff --git a/django/contrib/auth/admin.py b/django/contrib/auth/admin.py
    index ccf940d..268880f 100644
    a b from django.utils.safestring import mark_safe  
    1515from django.utils import six
    1616from django.utils.translation import ugettext, ugettext_lazy as _
    1717from django.views.decorators.csrf import csrf_protect
    18 from django.views.decorators.debug import sensitive_post_parameters
     18from django.views.decorators.debug import sensitive_post_parameters_m
    1919
    2020csrf_protect_m = method_decorator(csrf_protect)
    2121
    class UserAdmin(admin.ModelAdmin):  
    8484             self.admin_site.admin_view(self.user_change_password))
    8585        ) + super(UserAdmin, self).get_urls()
    8686
    87     @sensitive_post_parameters()
     87    @sensitive_post_parameters_m()
    8888    @csrf_protect_m
    8989    @transaction.commit_on_success
    9090    def add_view(self, request, form_url='', extra_context=None):
    class UserAdmin(admin.ModelAdmin):  
    114114        return super(UserAdmin, self).add_view(request, form_url,
    115115                                               extra_context)
    116116
    117     @sensitive_post_parameters()
     117    @sensitive_post_parameters_m()
    118118    def user_change_password(self, request, id, form_url=''):
    119119        if not self.has_change_permission(request):
    120120            raise PermissionDenied
  • django/views/decorators/debug.py

    diff --git a/django/views/decorators/debug.py b/django/views/decorators/debug.py
    index 5c22296..b6fc11c 100644
    a b def sensitive_post_parameters(*parameters):  
    6969            return view(request, *args, **kwargs)
    7070        return sensitive_post_parameters_wrapper
    7171    return decorator
     72
     73
     74def sensitive_post_parameters_m(*parameters):
     75    "sensitive_post_parameters function for class method"
     76    def decorator(view):
     77        @functools.wraps(view)
     78        def sensitive_post_parameters_wrapper(self, request, *args, **kwargs):
     79            if parameters:
     80                request.sensitive_post_parameters = parameters
     81            else:
     82                request.sensitive_post_parameters = '__ALL__'
     83            return view(self, request, *args, **kwargs)
     84        return sensitive_post_parameters_wrapper
     85    return decorator
  • tests/regressiontests/views/views.py

    diff --git a/tests/regressiontests/views/views.py b/tests/regressiontests/views/views.py
    index 17872ee..0b90224 100644
    a b from django.shortcuts import render_to_response, render  
    99from django.template import Context, RequestContext, TemplateDoesNotExist
    1010from django.views.debug import technical_500_response, SafeExceptionReporterFilter
    1111from django.views.decorators.debug import (sensitive_post_parameters,
    12                                           sensitive_variables)
     12                            sensitive_post_parameters_m, sensitive_variables)
    1313from django.utils.log import getLogger
    1414
    1515from . import BrokenException, except_args
    class Klass(object):  
    226226            send_log(request, exc_info)
    227227            return technical_500_response(request, *exc_info)
    228228
    229     @sensitive_post_parameters("password", "secret-key")
     229    @sensitive_post_parameters_m("password", "secret-key")
    230230    def method_post(self, request):
    231231        request.method = 'POST'
    232232        request.POST._mutable = True
Back to Top