2
0

security.txt 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. ==========================
  2. Django's security policies
  3. ==========================
  4. Django's development team is strongly committed to responsible
  5. reporting and disclosure of security-related issues. As such, we've
  6. adopted and follow a set of policies which conform to that ideal and
  7. are geared toward allowing us to deliver timely security updates to
  8. the official distribution of Django, as well as to third-party
  9. distributions.
  10. .. _reporting-security-issues:
  11. Reporting security issues
  12. =========================
  13. **Short version: please report security issues by emailing
  14. security@djangoproject.com**.
  15. Most normal bugs in Django are reported to `our public Trac instance`_, but
  16. due to the sensitive nature of security issues, we ask that they **not** be
  17. publicly reported in this fashion.
  18. Instead, if you believe you've found something in Django which has security
  19. implications, please send a description of the issue via email to
  20. ``security@djangoproject.com``. Mail sent to that address reaches the `security
  21. team <https://www.djangoproject.com/foundation/teams/#security-team>`_.
  22. Once you've submitted an issue via email, you should receive an acknowledgment
  23. from a member of the security team within 3 working days. After that, the
  24. security team will begin their analysis. Depending on the action to be taken,
  25. you may receive followup emails. It can take several weeks before the security
  26. team comes to a conclusion. There is no need to chase the security team unless
  27. you discover new, relevant information. All reports aim to be resolved within
  28. the industry-standard 90 days. Confirmed vulnerabilities with a
  29. :ref:`high severity level <severity-levels>` will be addressed promptly.
  30. .. admonition:: Sending encrypted reports
  31. If you want to send an encrypted email (*optional*), the public key ID for
  32. ``security@djangoproject.com`` is ``0xfcb84b8d1d17f80b``, and this public
  33. key is available from most commonly-used keyservers.
  34. .. _our public Trac instance: https://code.djangoproject.com/query
  35. Reporting guidelines
  36. --------------------
  37. Include a runnable proof of concept
  38. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  39. Please privately share a minimal Django project or code snippet that
  40. demonstrates the potential vulnerability. Include clear instructions on how to
  41. set up, run, and reproduce the issue.
  42. Please do not attach screenshots of code.
  43. User input must be sanitized
  44. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  45. Reports based on a failure to sanitize user input are not valid security
  46. vulnerabilities. It is the developer's responsibility to properly handle user
  47. input. This principle is explained in our :ref:`security documentation
  48. <sanitize-user-input>`.
  49. For example, the following is **not considered valid** because ``email`` has
  50. not been sanitized::
  51. from django.core.mail import send_mail
  52. from django.http import JsonResponse
  53. def my_proof_of_concept(request):
  54. email = request.GET.get("email", "")
  55. send_mail("Email subject", "Email body", email, ["admin@example.com"])
  56. return JsonResponse(status=200)
  57. Developers must **always validate and sanitize input** before using it. The
  58. correct approach would be to use a Django form to ensure ``email`` is properly
  59. validated::
  60. from django import forms
  61. from django.core.mail import send_mail
  62. from django.http import JsonResponse
  63. class EmailForm(forms.Form):
  64. email = forms.EmailField()
  65. def my_proof_of_concept(request):
  66. form = EmailForm(request.GET)
  67. if form.is_valid():
  68. send_mail(
  69. "Email subject",
  70. "Email body",
  71. form.cleaned_data["email"],
  72. ["admin@example.com"],
  73. )
  74. return JsonResponse(status=200)
  75. return JsonResponse(form.errors, status=400)
  76. Similarly, as Django's raw SQL constructs (such as :meth:`~.QuerySet.extra` and
  77. :class:`.RawSQL` expression) provide developers with full control over the
  78. query, they are insecure if user input is not properly handled. As explained in
  79. our :ref:`security documentation <sql-injection-protection>`, it is the
  80. developer's responsibility to safely process user input for these functions.
  81. For instance, the following is **not considered valid** because ``query`` has
  82. not been sanitized::
  83. from django.shortcuts import HttpResponse
  84. from .models import MyModel
  85. def my_proof_of_concept(request):
  86. query = request.GET.get("query", "")
  87. q = MyModel.objects.extra(select={"id": query})
  88. return HttpResponse(q.values())
  89. Request headers and URLs must be under 8K bytes
  90. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  91. To prevent denial-of-service (DoS) attacks, production-grade servers impose
  92. limits on request header and URL sizes. For example, by default Gunicorn allows
  93. up to roughly:
  94. * `4k bytes for a URL`_
  95. * `8K bytes for a request header`_
  96. Other web servers, such as Nginx and Apache, have similar restrictions to
  97. prevent excessive resource consumption.
  98. Consequently, the Django security team will not consider reports that rely on
  99. request headers or URLs exceeding 8K bytes, as such inputs are already
  100. mitigated at the server level in production environments.
  101. .. admonition:: :djadmin:`runserver` should never be used in production
  102. Django's built-in development server does not enforce these limits because
  103. it is not designed to be a production server.
  104. .. _`4k bytes for a URL`: https://docs.gunicorn.org/en/stable/settings.html#limit-request-line
  105. .. _`8k bytes for a request header`: https://docs.gunicorn.org/en/stable/settings.html#limit-request-field-size
  106. The request body must be under 2.5 MB
  107. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  108. The :setting:`DATA_UPLOAD_MAX_MEMORY_SIZE` setting limits the default maximum
  109. request body size to 2.5 MB.
  110. As this is enforced on all production-grade Django projects by default, a proof
  111. of concept must not exceed 2.5 MB in the request body to be considered valid.
  112. Issues resulting from large, but potentially reasonable setting values, should
  113. be reported using the `public ticket tracker`_ for hardening.
  114. .. _public ticket tracker: https://code.djangoproject.com/
  115. Code under test must feasibly exist in a Django project
  116. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  117. The proof of concept must plausibly occur in a production-grade Django
  118. application, reflecting real-world scenarios and following standard development
  119. practices.
  120. Django contains many private and undocumented functions that are not part of
  121. its public API. If a vulnerability depends on directly calling these internal
  122. functions in an unsafe way, it will not be considered a valid security issue.
  123. Content displayed by the Django Template Language must be under 100 KB
  124. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  125. The Django Template Language (DTL) is designed for building the content needed
  126. to display web pages. In particular its text filters are meant for that kind of
  127. usage.
  128. For reference, the complete works of Shakespeare have about 3.5 million bytes
  129. in plain-text ASCII encoding. Displaying such in a single request is beyond the
  130. scope of almost all websites, and so outside the scope of the DTL too.
  131. Text processing is expensive. Django makes no guarantee that DTL text filters
  132. are never subject to degraded performance if passed deliberately crafted,
  133. sufficiently large inputs. Under default configurations, Django makes it
  134. difficult for sites to accidentally accept such payloads from untrusted
  135. sources, but, if it is necessary to display large amounts of user-provided
  136. content, it’s important that basic security measures are taken.
  137. User-provided content should always be constrained to known maximum length. It
  138. should be filtered to remove malicious content, and validated to match expected
  139. formats. It should then be processed offline, if necessary, before being
  140. displayed.
  141. Proof of concepts which use over 100 KB of data to be processed by the DTL will
  142. be considered invalid.
  143. .. _security-report-evaluation:
  144. How does Django evaluate a report
  145. =================================
  146. These are criteria used by the security team when evaluating whether a report
  147. requires a security release:
  148. * The vulnerability is within a :ref:`supported version <security-support>` of
  149. Django.
  150. * The vulnerability does not depend on manual actions that rely on code
  151. external to Django. This includes actions performed by a project's developer
  152. or maintainer using developer tools or the Django CLI. For example, attacks
  153. that require running management commands with uncommon or insecure options
  154. do not qualify.
  155. * The vulnerability applies to a production-grade Django application. This
  156. means the following scenarios do not require a security release:
  157. * Exploits that only affect local development, for example when using
  158. :djadmin:`runserver`.
  159. * Exploits which fail to follow security best practices, such as failure to
  160. sanitize user input. For other examples, see our :ref:`security
  161. documentation <cross-site-scripting>`.
  162. * Exploits in AI generated code that do not adhere to security best practices.
  163. The security team may conclude that the source of the vulnerability is within
  164. the Python standard library, in which case the reporter will be asked to report
  165. the vulnerability to the Python core team. For further details see the `Python
  166. security guidelines <https://www.python.org/dev/security/>`_.
  167. On occasion, a security release may be issued to help resolve a security
  168. vulnerability within a popular third-party package. These reports should come
  169. from the package maintainers.
  170. If you are unsure whether your finding meets these criteria, please still report
  171. it :ref:`privately by emailing security@djangoproject.com
  172. <reporting-security-issues>`. The security team will review your report and
  173. recommend the correct course of action.
  174. .. _security-support:
  175. Supported versions
  176. ==================
  177. At any given time, the Django team provides official security support
  178. for several versions of Django:
  179. * The `main development branch`_, hosted on GitHub, which will become the
  180. next major release of Django, receives security support. Security issues that
  181. only affect the main development branch and not any stable released versions
  182. are fixed in public without going through the :ref:`disclosure process
  183. <security-disclosure>`.
  184. * The two most recent Django release series receive security
  185. support. For example, during the development cycle leading to the
  186. release of Django 1.5, support will be provided for Django 1.4 and
  187. Django 1.3. Upon the release of Django 1.5, Django 1.3's security
  188. support will end.
  189. * :term:`Long-term support release`\s will receive security updates for a
  190. specified period.
  191. When new releases are issued for security reasons, the accompanying
  192. notice will include a list of affected versions. This list is
  193. comprised solely of *supported* versions of Django: older versions may
  194. also be affected, but we do not investigate to determine that, and
  195. will not issue patches or new releases for those versions.
  196. .. _main development branch: https://github.com/django/django/
  197. .. _severity-levels:
  198. Security issue severity levels
  199. ==============================
  200. The severity level of a security vulnerability is determined by the attack
  201. type.
  202. Severity levels are:
  203. * **High**
  204. * Remote code execution
  205. * SQL injection
  206. * **Moderate**
  207. * Cross site scripting (XSS)
  208. * Cross site request forgery (CSRF)
  209. * Denial-of-service attacks
  210. * Broken authentication
  211. * **Low**
  212. * Sensitive data exposure
  213. * Broken session management
  214. * Unvalidated redirects/forwards
  215. * Issues requiring an uncommon configuration option
  216. .. _security-disclosure:
  217. How Django discloses security issues
  218. ====================================
  219. Our process for taking a security issue from private discussion to
  220. public disclosure involves multiple steps.
  221. Approximately one week before public disclosure, we send two notifications:
  222. First, we notify |django-announce| of the date and approximate time of the
  223. upcoming security release, as well as the severity of the issues. This is to
  224. aid organizations that need to ensure they have staff available to handle
  225. triaging our announcement and upgrade Django as needed.
  226. Second, we notify a list of :ref:`people and organizations
  227. <security-notifications>`, primarily composed of operating-system vendors and
  228. other distributors of Django. This email is signed with the PGP key of someone
  229. from `Django's release team`_ and consists of:
  230. * A full description of the issue and the affected versions of Django.
  231. * The steps we will be taking to remedy the issue.
  232. * The patch(es), if any, that will be applied to Django.
  233. * The date on which the Django team will apply these patches, issue
  234. new releases and publicly disclose the issue.
  235. On the day of disclosure, we will take the following steps:
  236. #. Apply the relevant patch(es) to Django's codebase.
  237. #. Issue the relevant release(s), by placing new packages on the :pypi:`Python
  238. Package Index <Django>` and on the `djangoproject.com website
  239. <https://www.djangoproject.com/download/>`_, and tagging the new release(s)
  240. in Django's git repository.
  241. #. Post a public entry on `the official Django development blog`_,
  242. describing the issue and its resolution in detail, pointing to the
  243. relevant patches and new releases, and crediting the reporter of
  244. the issue (if the reporter wishes to be publicly identified).
  245. #. Post a notice to the |django-announce| and oss-security@lists.openwall.com
  246. mailing lists that links to the blog post.
  247. .. _the official Django development blog: https://www.djangoproject.com/weblog/
  248. If a reported issue is believed to be particularly time-sensitive --
  249. due to a known exploit in the wild, for example -- the time between
  250. advance notification and public disclosure may be shortened
  251. considerably.
  252. Additionally, if we have reason to believe that an issue reported to
  253. us affects other frameworks or tools in the Python/web ecosystem, we
  254. may privately contact and discuss those issues with the appropriate
  255. maintainers, and coordinate our own disclosure and resolution with
  256. theirs.
  257. The Django team also maintains an :doc:`archive of security issues
  258. disclosed in Django</releases/security>`.
  259. .. _Django's release team: https://www.djangoproject.com/foundation/teams/#releasers-team
  260. .. _security-notifications:
  261. Who receives advance notification
  262. =================================
  263. The full list of people and organizations who receive advance
  264. notification of security issues is not and will not be made public.
  265. We also aim to keep this list as small as effectively possible, in
  266. order to better manage the flow of confidential information prior to
  267. disclosure. As such, our notification list is *not* simply a list of
  268. users of Django, and being a user of Django is not sufficient reason
  269. to be placed on the notification list.
  270. In broad terms, recipients of security notifications fall into three
  271. groups:
  272. 1. Operating-system vendors and other distributors of Django who
  273. provide a suitably-generic (i.e., *not* an individual's personal
  274. email address) contact address for reporting issues with their
  275. Django package, or for general security reporting. In either case,
  276. such addresses **must not** forward to public mailing lists or bug
  277. trackers. Addresses which forward to the private email of an
  278. individual maintainer or security-response contact are acceptable,
  279. although private security trackers or security-response groups are
  280. strongly preferred.
  281. 2. On a case-by-case basis, individual package maintainers who have
  282. demonstrated a commitment to responding to and responsibly acting
  283. on these notifications.
  284. 3. On a case-by-case basis, other entities who, in the judgment of the
  285. Django development team, need to be made aware of a pending
  286. security issue. Typically, membership in this group will consist of
  287. some of the largest and/or most likely to be severely impacted
  288. known users or distributors of Django, and will require a
  289. demonstrated ability to responsibly receive, keep confidential and
  290. act on these notifications.
  291. .. admonition:: Security audit and scanning entities
  292. As a policy, we do not add these types of entities to the notification
  293. list.
  294. Requesting notifications
  295. ========================
  296. If you believe that you, or an organization you are authorized to
  297. represent, fall into one of the groups listed above, you can ask to be
  298. added to Django's notification list by emailing
  299. ``security@djangoproject.com``. Please use the subject line "Security
  300. notification request".
  301. Your request **must** include the following information:
  302. * Your full, real name and the name of the organization you represent,
  303. if applicable, as well as your role within that organization.
  304. * A detailed explanation of how you or your organization fit at least
  305. one set of criteria listed above.
  306. * A detailed explanation of why you are requesting security notifications.
  307. Again, please keep in mind that this is *not* simply a list for users of
  308. Django, and the overwhelming majority of users should subscribe to
  309. |django-announce| to receive advanced notice of when a security release will
  310. happen, without the details of the issues, rather than request detailed
  311. notifications.
  312. * The email address you would like to have added to our notification
  313. list.
  314. * An explanation of who will be receiving/reviewing mail sent to that
  315. address, as well as information regarding any automated actions that
  316. will be taken (i.e., filing of a confidential issue in a bug
  317. tracker).
  318. * For individuals, the ID of a public key associated with your address
  319. which can be used to verify email received from you and encrypt
  320. email sent to you, as needed.
  321. Once submitted, your request will be considered by the Django
  322. development team; you will receive a reply notifying you of the result
  323. of your request within 30 days.
  324. Please also bear in mind that for any individual or organization,
  325. receiving security notifications is a privilege granted at the sole
  326. discretion of the Django development team, and that this privilege can
  327. be revoked at any time, with or without explanation.
  328. .. admonition:: Provide all required information
  329. A failure to provide the required information in your initial contact
  330. will count against you when making the decision on whether or not to
  331. approve your request.