File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -111,9 +111,11 @@ validated::
111111 return JsonResponse(status=200)
112112 return JsonResponse(form.errors, status=400)
113113
114- Similarly, as Django's raw SQL constructs (such as :meth:`~.QuerySet.extra` and
115- :class:`.RawSQL` expression) provide developers with full control over the
116- query, they are insecure if user input is not properly handled. As explained in
114+ Similarly, as Django's raw SQL constructs (such as :meth:`~.QuerySet.extra`,
115+ :class:`.RawSQL`, and :ref:`keyword arguments to database functions
116+ <avoiding-sql-injection-in-query-expressions>`) provide developers with full
117+ control over the query, they are insecure if user input is not properly
118+ handled. As explained in
117119our :ref:`security documentation <sql-injection-protection>`, it is the
118120developer's responsibility to safely process user input for these functions.
119121
Original file line number Diff line number Diff line change @@ -9,7 +9,8 @@ The classes documented below provide a way for users to use functions provided
99by the underlying database as annotations, aggregations, or filters in Django.
1010Functions are also :doc:`expressions </ref/models/expressions>`, so they can be
1111used and combined with other expressions like :ref:`aggregate functions
12- <aggregation-functions>`.
12+ <aggregation-functions>`. See the :class:`~django.db.models.Func` documentation
13+ for security considerations.
1314
1415We'll be using the following model in examples of each function::
1516
Original file line number Diff line number Diff line change @@ -434,6 +434,16 @@ replace the attributes of the same name without having to define your own
434434class. :ref:`output_field<output-field>` can be used to define the expected
435435return type.
436436
437+ .. admonition:: Sanitize input used to configure a query expression
438+
439+ Built-in database functions (such as
440+ :class:`~django.db.models.functions.Cast`) vary in whether arguments such
441+ as ``output_field`` can be supplied positionally or only by keyword. For
442+ ``output_field`` and several other cases, the input ultimately reaches
443+ ``Func()`` as a keyword argument, so the advice to avoid constructing
444+ keyword arguments from untrusted user input applies as equally to these
445+ arguments as it does to ``**extra``.
446+
437447``Aggregate()`` expressions
438448---------------------------
439449
You can’t perform that action at this time.
0 commit comments