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
Provenance
- Commit
3acec5f- Tree
4c5f77a- Author
Kenneth Reitz <me@kennethreitz.org>- Committer
GitHub <noreply@github.com>- Parent 1
386ac92- Parent 2
fcfd031
1 file changed+91 added−0 removed
modified:docs/security.rst+91 added
102 unmodified lines103 vulnerabilities104 <https://github.com/pallets/flask/issues/248#issuecomment-59934857>`_, so105 this behavior was changed and :func:`~flask.jsonify` now supports serializing106 arrays.107+108+Security Headers109+----------------110+111+This section contains a list of HTTP security headers supported by Flask.112+To configure HTTPS and handle the headers listed below we suggest the package `flask-talisman <https://github.com/GoogleCloudPlatform/flask-talisman>`_. 113+114+HTTP Strict Transport Security (HSTS)115+-------------------------------------116+117+Redirects HTTP requests to HTTPS on all URLs, preventing man-in-the-middle (MITM) attacks.118+119+Example:120+121+.. 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 126+127+See also `Strict Transport Security <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security>`_. 128+129+HTTP Public Key Pinning (HPKP)130+------------------------------131+132+This enables your web server to authenticate with a client browser using a specific certificate key to prevent man-in-the-middle (MITM) attacks.133+134+Example:135+136+.. sourcecode:: none137+138+ Public-Key-Pins: pin-sha256="base64=="; max-age=expireTime [; includeSubDomains][; report-uri="reportURI"] 139+140+See also `Public Key Pinning <https://developer.mozilla.org/en-US/docs/Web/HTTP/Public_Key_Pinning>`_.141+142+X-Frame-Options (Clickjacking Protection)143+-----------------------------------------144+145+Prevents the client from clicking page elements outside of the website, avoiding hijacking or UI redress attacks.146+147+.. sourcecode:: none148+ 149+ X-Frame-Options: DENY 150+ X-Frame-Options: SAMEORIGIN151+ X-Frame-Options: ALLOW-FROM https://example.com/152+153+See also `X-Frame-Options <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options>`_. 154+155+X-Content-Type-Options156+----------------------157+158+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.159+160+.. sourcecode:: none161+ 162+ X-Content-Type-Options: nosniff163+164+See also `X-Content-Type-Options <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options>`_. 165+166+Content Security Policy (CSP)167+-----------------------------168+169+Enhances security and prevents common web vulnerabilities such as cross-site scripting (XSS) and man-in-the-middle (MITM) related attacks.170+171+Example:172+173+.. sourcecode:: none174+ 175+ Content-Security-Policy: default-src https:; script-src 'nonce-{random}'; object-src 'none'176+177+See also `Content Security Policy <https://csp.withgoogle.com/docs/index.html>`_.178+179+Cookie Options180+--------------181+182+While these headers are not directly security related, they have important options that may affect your Flask application.183+184+- ``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. 187+188+Example:189+190+.. sourcecode:: none191+ 192+ Set-Cookie: [cookie-name]=[cookie-value] 193+194+See also:195+196+- 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>`_.