Skip to content
Myr

Merge pull request #2309 from aqt01/master

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Add http headers security notes

authored by Kenneth Reitz · committed by GitHub · parents 386ac92, fcfd031 · Browse files · 1 file+91 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+91 added−0 removed

  • other:+91 added−0 removed

1 file+91 added−0 removed

modified:docs/security.rst+91 added
102 unmodified lines
103vulnerabilities104<https://github.com/pallets/flask/issues/248#issuecomment-59934857>`_, so105this behavior was changed and :func:`~flask.jsonify` now supports serializing106arrays.107108Security Headers109----------------110111This section contains a list of HTTP security headers supported by Flask.112To configure HTTPS and handle the headers listed below we suggest the package `flask-talisman <https://github.com/GoogleCloudPlatform/flask-talisman>`_. 113114HTTP Strict Transport Security (HSTS)115-------------------------------------116117Redirects HTTP requests to HTTPS on all URLs, preventing man-in-the-middle (MITM) attacks.118119Example:120121.. sourcecode:: none122 123 Strict-Transport-Security: max-age=<expire-time 124 Strict-Transport-Security: max-age=<expire-time>; includeSubDomains 125 Strict-Transport-Security: max-age=<expire-time>; preload 126127See also `Strict Transport Security <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security>`_. 128129HTTP Public Key Pinning (HPKP)130------------------------------131132This enables your web server to authenticate with a client browser using a specific certificate key to prevent man-in-the-middle (MITM) attacks.133134Example:135136.. sourcecode:: none137138 Public-Key-Pins: pin-sha256="base64=="; max-age=expireTime [; includeSubDomains][; report-uri="reportURI"] 139140See also `Public Key Pinning <https://developer.mozilla.org/en-US/docs/Web/HTTP/Public_Key_Pinning>`_.141142X-Frame-Options (Clickjacking Protection)143-----------------------------------------144145Prevents the client from clicking page elements outside of the website, avoiding hijacking or UI redress attacks.146147.. sourcecode:: none148 149 X-Frame-Options: DENY 150 X-Frame-Options: SAMEORIGIN151 X-Frame-Options: ALLOW-FROM https://example.com/152153See also `X-Frame-Options <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options>`_. 154155X-Content-Type-Options156----------------------157158This 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.159160.. sourcecode:: none161 162 X-Content-Type-Options: nosniff163164See also `X-Content-Type-Options <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options>`_. 165166Content Security Policy (CSP)167-----------------------------168169Enhances security and prevents common web vulnerabilities such as cross-site scripting (XSS) and man-in-the-middle (MITM) related attacks.170171Example:172173.. sourcecode:: none174 175 Content-Security-Policy: default-src https:; script-src 'nonce-{random}'; object-src 'none'176177See also `Content Security Policy <https://csp.withgoogle.com/docs/index.html>`_.178179Cookie Options180--------------181182While these headers are not directly security related, they have important options that may affect your Flask application.183184- ``Secure`` limits your cookies to HTTPS traffic only.185- ``HttpOnly`` protects the contents of your cookie from being visible to XSS.186- ``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. 187188Example:189190.. sourcecode:: none191 192 Set-Cookie: [cookie-name]=[cookie-value] 193194See also:195196- Mozilla guide to `HTTP cookies <https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#Secure_and_HttpOnly_cookies>`_.197- `OWASP HTTP Only <https://www.owasp.org/index.php/HttpOnly>`_.