This section contains a list of HTTP security headers supported by Flask.
Browsers recognize various response headers in order to control security. We
To configure HTTPS and handle the headers listed below we suggest the package `flask-talisman <https://github.com/GoogleCloudPlatform/flask-talisman>`_.
recommend reviewing each of the headers below for use in your application.
The `Flask-Talisman`_ extension can be used to manage HTTPS and the security
This header prevents Cross-site scripting (XSS) by blocking requests on clients and forcing them to first read and validate the content-type before reading any of the contents of the request.
X-XSS-Protection
~~~~~~~~~~~~~~~~
..sourcecode:: none
The browser will try to prevent reflected XSS attacks by not loading the page
iftherequestcontains something that looks like JavaScript and the response
X-Content-Type-Options: nosniff
contains the same data. ::
See also `X-Content-Type-Options <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options>`_.
- ``HttpOnly`` protects the contents of your cookie from being visible to XSS.
- ``SameSite`` ensures that cookies can only be requested from the same domain that created them but this feature is not yet fully supported across all browsers.
Example:
HTTP Public Key Pinning (HPKP)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
..sourcecode:: none
This tells the browser to authenticate with the server using only the specific
certificate key to prevent MITM attacks.
Set-Cookie: [cookie-name]=[cookie-value]
See also:
..warning::
Be careful when enabling this, as it is very difficult to undo if you set up
or upgrade your key incorrectly.
- Mozilla guide to `HTTP cookies <https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#Secure_and_HttpOnly_cookies>`_.