1.5.6.txt 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. ==========================
  2. Django 1.5.6 release notes
  3. ==========================
  4. *April 21, 2014*
  5. Django 1.5.6 fixes several bugs in 1.5.5, including three security
  6. issues.
  7. Unexpected code execution using ``reverse()``
  8. =============================================
  9. Django's URL handling is based on a mapping of regex patterns
  10. (representing the URLs) to callable views, and Django's own processing
  11. consists of matching a requested URL against those patterns to
  12. determine the appropriate view to invoke.
  13. Django also provides a convenience function --
  14. :func:`~django.core.urlresolvers.reverse` -- which performs this process
  15. in the opposite direction. The ``reverse()`` function takes
  16. information about a view and returns a URL which would invoke that
  17. view. Use of ``reverse()`` is encouraged for application developers,
  18. as the output of ``reverse()`` is always based on the current URL
  19. patterns, meaning developers do not need to change other code when
  20. making changes to URLs.
  21. One argument signature for ``reverse()`` is to pass a dotted Python
  22. path to the desired view. In this situation, Django will import the
  23. module indicated by that dotted path as part of generating the
  24. resulting URL. If such a module has import-time side effects, those
  25. side effects will occur.
  26. Thus it is possible for an attacker to cause unexpected code
  27. execution, given the following conditions:
  28. 1. One or more views are present which construct a URL based on user
  29. input (commonly, a "next" parameter in a querystring indicating
  30. where to redirect upon successful completion of an action).
  31. 2. One or more modules are known to an attacker to exist on the
  32. server's Python import path, which perform code execution with side
  33. effects on importing.
  34. To remedy this, ``reverse()`` will now only accept and import dotted
  35. paths based on the view-containing modules listed in the project's :doc:`URL
  36. pattern configuration </topics/http/urls>`, so as to ensure that only modules
  37. the developer intended to be imported in this fashion can or will be imported.
  38. Caching of anonymous pages could reveal CSRF token
  39. ==================================================
  40. Django includes both a :doc:`caching framework </topics/cache>` and a system
  41. for :doc:`preventing cross-site request forgery (CSRF) attacks
  42. </ref/csrf/>`. The CSRF-protection system is based on a random nonce
  43. sent to the client in a cookie which must be sent by the client on future
  44. requests and, in forms, a hidden value which must be submitted back with the
  45. form.
  46. The caching framework includes an option to cache responses to
  47. anonymous (i.e., unauthenticated) clients.
  48. When the first anonymous request to a given page is by a client which
  49. did not have a CSRF cookie, the cache framework will also cache the
  50. CSRF cookie and serve the same nonce to other anonymous clients who
  51. do not have a CSRF cookie. This can allow an attacker to obtain a
  52. valid CSRF cookie value and perform attacks which bypass the check for
  53. the cookie.
  54. To remedy this, the caching framework will no longer cache such
  55. responses. The heuristic for this will be:
  56. 1. If the incoming request did not submit any cookies, and
  57. 2. If the response did send one or more cookies, and
  58. 3. If the ``Vary: Cookie`` header is set on the response, then the
  59. response will not be cached.
  60. MySQL typecasting
  61. =================
  62. The MySQL database is known to "typecast" on certain queries; for
  63. example, when querying a table which contains string values, but using
  64. a query which filters based on an integer value, MySQL will first
  65. silently coerce the strings to integers and return a result based on that.
  66. If a query is performed without first converting values to the
  67. appropriate type, this can produce unexpected results, similar to what
  68. would occur if the query itself had been manipulated.
  69. Django's model field classes are aware of their own types and most
  70. such classes perform explicit conversion of query arguments to the
  71. correct database-level type before querying. However, three model
  72. field classes did not correctly convert their arguments:
  73. * :class:`~django.db.models.FilePathField`
  74. * :class:`~django.db.models.GenericIPAddressField`
  75. * :class:`~django.db.models.IPAddressField`
  76. These three fields have been updated to convert their arguments to the
  77. correct types before querying.
  78. Additionally, developers of custom model fields are now warned via
  79. documentation to ensure their custom field classes will perform
  80. appropriate type conversions, and users of the :meth:`raw()
  81. <django.db.models.query.QuerySet.raw>` and :meth:`extra()
  82. <django.db.models.query.QuerySet.extra>` query methods -- which allow the
  83. developer to supply raw SQL or SQL fragments -- will be advised to ensure they
  84. perform appropriate manual type conversions prior to executing queries.
  85. Bugfixes
  86. ========
  87. * Fixed :class:`~django.contrib.auth.backends.ModelBackend` raising
  88. ``UnboundLocalError`` if :func:`~django.contrib.auth.get_user_model`
  89. raised an error (#21439).
  90. Additionally, Django's vendored version of six, :mod:`django.utils.six`,
  91. has been upgraded to the latest release (1.6.1).