| 1 |
Configuration |
| 2 |
============= |
| 3 |
|
| 4 |
========================== ===================================================== |
| 5 |
``WTF_CSRF_ENABLED`` Set to ``False`` to disable all CSRF protection. |
| 6 |
Default is ``True``. |
| 7 |
``WTF_CSRF_CHECK_DEFAULT`` When using the CSRF protection extension, this |
| 8 |
controls whether every view is protected by default. |
| 9 |
Default is ``True``. |
| 10 |
``WTF_CSRF_SECRET_KEY`` Random data for generating secure tokens. If this is |
| 11 |
not set then ``SECRET_KEY`` is used. |
| 12 |
``WTF_CSRF_METHODS`` HTTP methods to protect from CSRF. Default is |
| 13 |
``{'POST', 'PUT', 'PATCH', 'DELETE'}``. |
| 14 |
``WTF_CSRF_FIELD_NAME`` Name of the form field and session key that holds the |
| 15 |
CSRF token. Default is ``csrf_token``. |
| 16 |
``WTF_CSRF_HEADERS`` HTTP headers to search for CSRF token when it is not |
| 17 |
provided in the form. Default is |
| 18 |
``['X-CSRFToken', 'X-CSRF-Token']``. |
| 19 |
``WTF_CSRF_META_NAME`` Value of the ``name`` attribute rendered by |
| 20 |
:func:`~flask_wtf.csrf.csrf_meta_tag`. Default is |
| 21 |
``csrf-token``. |
| 22 |
``WTF_CSRF_TIME_LIMIT`` Max age in seconds for CSRF tokens. Default is |
| 23 |
``3600``. If set to ``None``, the CSRF token is valid |
| 24 |
for the life of the session. |
| 25 |
If your webserver has a cache policy, make sure it is |
| 26 |
configured with at maximum this value, so user browsers |
| 27 |
won't display pages with expired CSRF tokens. |
| 28 |
``WTF_CSRF_SSL_STRICT`` Whether to enforce the same origin policy by checking |
| 29 |
that the referrer matches the host. Only applies to |
| 30 |
HTTPS requests. Default is ``True``. |
| 31 |
``WTF_I18N_ENABLED`` Set to ``False`` to disable Flask-Babel I18N support. |
| 32 |
Also set to ``False`` if you want to use WTForms's |
| 33 |
built-in messages directly, see more info `here`_. |
| 34 |
Default is ``True``. |
| 35 |
========================== ===================================================== |
| 36 |
|
| 37 |
.. _here: https://wtforms.readthedocs.io/en/stable/i18n.html#using-the-built-in-translations-provider |
| 38 |
|
| 39 |
Recaptcha |
| 40 |
--------- |
| 41 |
|
| 42 |
=========================== ============================================== |
| 43 |
``RECAPTCHA_PUBLIC_KEY`` **required** A public key. |
| 44 |
``RECAPTCHA_PRIVATE_KEY`` **required** A private key. |
| 45 |
https://www.google.com/recaptcha/admin |
| 46 |
``RECAPTCHA_ENABLED`` Set to ``False`` to disable recaptcha widgets |
| 47 |
and always validate recaptcha fields as |
| 48 |
valid. Default is ``True``. |
| 49 |
``RECAPTCHA_PARAMETERS`` **optional** A dict of configuration options. |
| 50 |
``RECAPTCHA_HTML`` **optional** Override default HTML template |
| 51 |
for Recaptcha. |
| 52 |
``RECAPTCHA_DATA_ATTRS`` **optional** A dict of ``data-`` attrs to use |
| 53 |
for Recaptcha div |
| 54 |
``RECAPTCHA_SCRIPT`` **optional** Override the default captcha |
| 55 |
script URI in case an alternative service to |
| 56 |
reCAPtCHA, e.g. hCaptcha is used. Default is |
| 57 |
``'https://www.google.com/recaptcha/api.js'`` |
| 58 |
``RECAPTCHA_DIV_CLASS`` **optional** Override the default class of the |
| 59 |
captcha div in case an alternative captcha |
| 60 |
service is used. Default is |
| 61 |
``'g-recaptcha'`` |
| 62 |
``RECAPTCHA_VERIFY_SERVER`` **optional** Override the default verification |
| 63 |
server in case an alternative service is used. |
| 64 |
Default is |
| 65 |
``'https://www.google.com/recaptcha/api/siteverify'`` |
| 66 |
|
| 67 |
=========================== ============================================== |
| 68 |
|
| 69 |
Per-instance HTML attributes can also be passed when rendering the field. |
| 70 |
Any keyword argument given to the widget is forwarded to the captcha |
| 71 |
``<div>``, following the standard WTForms naming convention (``class_`` |
| 72 |
becomes ``class``, ``data_foo`` becomes ``data-foo``, ``aria_label`` |
| 73 |
becomes ``aria-label``). Kwargs take precedence over ``RECAPTCHA_DIV_CLASS`` |
| 74 |
and ``RECAPTCHA_DATA_ATTRS``. The ``id`` attribute defaults to the field |
| 75 |
id and can be overridden the same way:: |
| 76 |
|
| 77 |
{{ form.recaptcha(class_="my-captcha", data_theme="dark", aria_label="Captcha") }} |
| 78 |
|
| 79 |
Logging |
| 80 |
------- |
| 81 |
|
| 82 |
CSRF errors are logged at the ``INFO`` level to the ``flask_wtf.csrf`` logger. |
| 83 |
You still need to configure logging in your application in order to see these |
| 84 |
messages. |