This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Django Careful Forms is a small extension on top of django’s Forms system. It can help you discover potential security oversights in your forms.

It will emit warnings if there are any fields defined on forms that have not been accessed (the asumption beeing that not accessed fields will also not have been rendered in the template / displayed to the user).


Consider the following example:


class SomeModel(models.Model):
    name = models.CharField(max_length=100)
    email = models.CharField(max_length=100)
    is_admin = models.BooleanField()

class SomeForm(ModelForm):
    class Meta:
        model = SomeModel

# template:

{{ }}
{{ }}

You might have noticed that the model form’s Meta class misses an exclude definition for the is_admin field (assuming this is a form that is going to be displayed to an end user).

Now on first glance this won’t cause any problems since the template only displays the name and email field. However by forgetting to exclude the is_admin field you are allowing users to change state internal to your application (and in this hypothetical example gain admin rights).

If we changed this example to use careful-forms instead the missing field would have triggerd a warning (or even an exception depending on settings, see below), alerting you to the vulnerability.


The initial motivation for this package came from the recently well publicized ‘mass assignment’ vulnerability in the Rails framework. The specifics are not important but the basic problem was unchecked assignment of request data into a model.

Of course django is not susceptible to this particular problem because of its forms system. However even when using the forms system (especially when using Model Forms) it is still possible to inadvertently allow request data to be written to model fields that are supposed to be private (e.g. by forgetting to exclude internal fields).

The final trigger however was Erik Romijn’s nice talk Building secure Django websites at djangocon europe 2012 which explicitly mentions the forms pitfall in slide 53ff.


  • Python 2.6+
  • django 1.3+


The easy & recommended way:

#~ pip install django-careful-forms


  1. Add "careful_forms.middleware.CarefulFormsMiddlware" to your projects settings.MIDDLEWARE_CLASSES. You should add it near the beginning of the list to make sure all forms are covered.
  2. For every form that you want to be monitored by django-careful-forms change the base class of your forms to careful_forms.forms.CarefulModelForm (or CarefulForm for regular forms) [1].
[1]In case you already have a custom form base class you can also add CarefulFormMixin to it.


class MyForm(CarefulForm):
    # ...

class OtherForm(CarefulModelForm):
    # ...

class YetMoreForms(CarefulFormMixin, CustomFormBaseClass):
    # ...



Default: settings.DEBUG

This setting is the “main switch” for django-careful-forms. When set to True the recording of accessed form fields is active and warnings will be triggered for not accessed fields. Since the bookkeping machinery incurs a (small) per-request overhaed it is by default only enabled in DEBUG mode.

When set to False no pre-request runtime overhead is introduced.


Default: False

When set to True an exception is raised instead of a warning whenever a not accessed field is detected.

Release History

Release History


This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
django-careful-forms-0.1.tar.gz (7.8 kB) Copy SHA256 Checksum SHA256 Source Jun 8, 2012

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting