{"title":"Django 1.5.6 release notes","version":"dev","locale":"en","docname":"releases/1.5.6","url":"/en/dev/releases/1.5.6/","canonical":"https://djangodocs.dev/en/dev/releases/1.5.6/","summary":"Django 1.5.6 fixes several bugs in 1.5.5, including three security issues. Django’s URL handling is based on a mapping of regex patterns (representing the…","html":"<h1>Django 1.5.6 release notes<a class=\"heading-anchor\" href=\"#django-1-5-6-release-notes\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p><em>April 21, 2014</em></p>\n<p>Django 1.5.6 fixes several bugs in 1.5.5, including three security\nissues.</p>\n<section id=\"unexpected-code-execution-using-reverse\">\n<h2>Unexpected code execution using <code class=\"docutils literal notranslate\">reverse()</code><a class=\"heading-anchor\" href=\"#unexpected-code-execution-using-reverse\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Django’s URL handling is based on a mapping of regex patterns\n(representing the URLs) to callable views, and Django’s own processing\nconsists of matching a requested URL against those patterns to\ndetermine the appropriate view to invoke.</p>\n<p>Django also provides a convenience function – <code class=\"docutils literal notranslate\">reverse()</code> – which performs\nthis process in the opposite direction. The <code class=\"docutils literal notranslate\">reverse()</code> function takes\ninformation about a view and returns a URL which would invoke that view. Use\nof <code class=\"docutils literal notranslate\">reverse()</code> is encouraged for application developers, as the output of\n<code class=\"docutils literal notranslate\">reverse()</code> is always based on the current URL patterns, meaning developers\ndo not need to change other code when making changes to URLs.</p>\n<p>One argument signature for <code class=\"docutils literal notranslate\">reverse()</code> is to pass a dotted Python\npath to the desired view. In this situation, Django will import the\nmodule indicated by that dotted path as part of generating the\nresulting URL. If such a module has import-time side effects, those\nside effects will occur.</p>\n<p>Thus it is possible for an attacker to cause unexpected code\nexecution, given the following conditions:</p>\n<ol class=\"arabic simple\">\n<li><p>One or more views are present which construct a URL based on user\ninput (commonly, a “next” parameter in a querystring indicating\nwhere to redirect upon successful completion of an action).</p></li>\n<li><p>One or more modules are known to an attacker to exist on the\nserver’s Python import path, which perform code execution with side\neffects on importing.</p></li>\n</ol>\n<p>To remedy this, <code class=\"docutils literal notranslate\">reverse()</code> will now only accept and import dotted\npaths based on the view-containing modules listed in the project’s <a class=\"reference internal\" href=\"/en/dev/topics/http/urls/\"><span class=\"doc\">URL\npattern configuration</span></a>, so as to ensure that only modules\nthe developer intended to be imported in this fashion can or will be imported.</p>\n</section>\n<section id=\"caching-of-anonymous-pages-could-reveal-csrf-token\">\n<h2>Caching of anonymous pages could reveal CSRF token<a class=\"heading-anchor\" href=\"#caching-of-anonymous-pages-could-reveal-csrf-token\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Django includes both a <a class=\"reference internal\" href=\"/en/dev/topics/cache/\"><span class=\"doc\">caching framework</span></a> and a system\nfor <a class=\"reference internal\" href=\"/en/dev/ref/csrf/\"><span class=\"doc\">preventing cross-site request forgery (CSRF) attacks</span></a>. The CSRF-protection system is based on a random nonce\nsent to the client in a cookie which must be sent by the client on future\nrequests and, in forms, a hidden value which must be submitted back with the\nform.</p>\n<p>The caching framework includes an option to cache responses to\nanonymous (i.e., unauthenticated) clients.</p>\n<p>When the first anonymous request to a given page is by a client which\ndid not have a CSRF cookie, the cache framework will also cache the\nCSRF cookie and serve the same nonce to other anonymous clients who\ndo not have a CSRF cookie. This can allow an attacker to obtain a\nvalid CSRF cookie value and perform attacks which bypass the check for\nthe cookie.</p>\n<p>To remedy this, the caching framework will no longer cache such\nresponses. The heuristic for this will be:</p>\n<ol class=\"arabic simple\">\n<li><p>If the incoming request did not submit any cookies, and</p></li>\n<li><p>If the response did send one or more cookies, and</p></li>\n<li><p>If the <code class=\"docutils literal notranslate\">Vary: Cookie</code> header is set on the response, then the\nresponse will not be cached.</p></li>\n</ol>\n</section>\n<section id=\"mysql-typecasting\">\n<h2>MySQL typecasting<a class=\"heading-anchor\" href=\"#mysql-typecasting\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>The MySQL database is known to “typecast” on certain queries; for\nexample, when querying a table which contains string values, but using\na query which filters based on an integer value, MySQL will first\nsilently coerce the strings to integers and return a result based on that.</p>\n<p>If a query is performed without first converting values to the\nappropriate type, this can produce unexpected results, similar to what\nwould occur if the query itself had been manipulated.</p>\n<p>Django’s model field classes are aware of their own types and most\nsuch classes perform explicit conversion of query arguments to the\ncorrect database-level type before querying. However, three model\nfield classes did not correctly convert their arguments:</p>\n<ul class=\"simple\">\n<li><p><a class=\"reference internal\" href=\"/en/dev/ref/models/fields/#django.db.models.FilePathField\" title=\"django.db.models.FilePathField\"><code class=\"xref py py-class docutils literal notranslate\">FilePathField</code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/en/dev/ref/models/fields/#django.db.models.GenericIPAddressField\" title=\"django.db.models.GenericIPAddressField\"><code class=\"xref py py-class docutils literal notranslate\">GenericIPAddressField</code></a></p></li>\n<li><p><code class=\"docutils literal notranslate\">IPAddressField</code></p></li>\n</ul>\n<p>These three fields have been updated to convert their arguments to the\ncorrect types before querying.</p>\n<p>Additionally, developers of custom model fields are now warned via\ndocumentation to ensure their custom field classes will perform\nappropriate type conversions, and users of the <a class=\"reference internal\" href=\"/en/dev/ref/models/querysets/#django.db.models.query.QuerySet.raw\" title=\"django.db.models.query.QuerySet.raw\"><code class=\"xref py py-meth docutils literal notranslate\">raw()</code></a> and <a class=\"reference internal\" href=\"/en/dev/ref/models/querysets/#django.db.models.query.QuerySet.extra\" title=\"django.db.models.query.QuerySet.extra\"><code class=\"xref py py-meth docutils literal notranslate\">extra()</code></a> query methods – which allow the\ndeveloper to supply raw SQL or SQL fragments – will be advised to ensure they\nperform appropriate manual type conversions prior to executing queries.</p>\n</section>\n<section id=\"bugfixes\">\n<h2>Bugfixes<a class=\"heading-anchor\" href=\"#bugfixes\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<ul class=\"simple\">\n<li><p>Fixed <a class=\"reference internal\" href=\"/en/dev/ref/contrib/auth/#django.contrib.auth.backends.ModelBackend\" title=\"django.contrib.auth.backends.ModelBackend\"><code class=\"xref py py-class docutils literal notranslate\">ModelBackend</code></a> raising\n<code class=\"docutils literal notranslate\">UnboundLocalError</code> if <a class=\"reference internal\" href=\"/en/dev/topics/auth/customizing/#django.contrib.auth.get_user_model\" title=\"django.contrib.auth.get_user_model\"><code class=\"xref py py-func docutils literal notranslate\">get_user_model()</code></a>\nraised an error (#21439).</p></li>\n</ul>\n<p>Additionally, Django’s vendored version of six, <code class=\"docutils literal notranslate\">django.utils.six</code>,\nhas been upgraded to the latest release (1.6.1).</p>\n</section>","rootId":"django-1-5-6-release-notes","toc":[{"title":"Unexpected code execution using reverse()","anchor":"unexpected-code-execution-using-reverse","children":[]},{"title":"Caching of anonymous pages could reveal CSRF token","anchor":"caching-of-anonymous-pages-could-reveal-csrf-token","children":[]},{"title":"MySQL typecasting","anchor":"mysql-typecasting","children":[]},{"title":"Bugfixes","anchor":"bugfixes","children":[]}],"breadcrumbs":[{"docname":"releases/index","title":"Release notes","url":"/en/dev/releases/"}],"prev":{"docname":"releases/1.5.7","title":"Django 1.5.7 release notes","url":"/en/dev/releases/1.5.7/"},"next":{"docname":"releases/1.5.5","title":"Django 1.5.5 release notes","url":"/en/dev/releases/1.5.5/"},"formats":{"html":"/en/dev/releases/1.5.6/","markdown":"/en/dev/releases/1.5.6.md","json":"/en/dev/releases/1.5.6.json"},"source":"https://github.com/django/django/blob/main/docs/releases/1.5.6.txt","official":"https://docs.djangoproject.com/en/dev/releases/1.5.6/","inVersions":["dev","6.1","6.0","5.2","5.1","5.0","4.2","4.1","4.0","3.2","3.1","3.0","2.2","2.1","2.0","1.11","1.10","1.9","1.8"],"inLocales":["en"]}