Skip to content
Myr

Add security headers notes

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

authored by Lowell Abbott · committed by Lowell Abbott · parent f962720 · Browse files · 1 file+127 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+127 added−0 removed

  • other:+127 added−0 removed

1 file+127 added−0 removed

modified:docs/security.rst+127 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.107108109SSL/HTTPS110---------111112For implementing HTTPS on your server113114Below some packages in suggestion order that implements this protocol:115116* `flask-talisman <https://github.com/GoogleCloudPlatform/flask-talisman>`_117* `flask-sslify <https://github.com/kennethreitz/flask-sslify>`_118* `flask-secure-headers <https://github.com/twaldear/flask-secure-headers>`_119120Security Headers121----------------122123This sections contains sections headers supported by Flask and a list of packages in suggestion order that implements it124125`Content Security Policy <https://csp.withgoogle.com/docs/index.html>`_ (CSP)126-----------------------------------------------------------------------------127128For enhancing security and preventing common web vulnerabilities such as cross-site scripting and MITM related attacks129130Example131132.. sourcecode:: html133 134 Content-Security-Policy: default-src https:; script-src 'nonce-{random}'; object-src 'none'135136137To learn more check `this <https://csp.withgoogle.com/docs/index.html>`_138139* `flask-talisman <https://github.com/GoogleCloudPlatform/flask-talisman>`_140* `flask-csp <https://github.com/twaldear/flask-csp>`_141* `flask-secure-headers <https://github.com/twaldear/flask-secure-headers>`_142143`HTTP Strict Transport Security <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security>`_ (HSTS)144------------------------------------------------------------------------------------------------------------------------------145146147For automatically redirect HTTP to HTTPS on all the website url's and prevent MITM attacks148149Example150151.. sourcecode:: html152 153 Strict-Transport-Security: max-age=<expire-time 154 Strict-Transport-Security: max-age=<expire-time>; includeSubDomains 155 Strict-Transport-Security: max-age=<expire-time>; preload 156157To learn more check `this <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security>`_ 158159160* `flask-talisman <https://github.com/GoogleCloudPlatform/flask-talisman>`_161* `flask-sslify <https://github.com/kennethreitz/flask-sslify>`_162* `flask-secure-headers <https://github.com/twaldear/flask-secure-headers>`_163164`X-FRAME-OPTIONS <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options>`_ (Clickjacking protection)165-------------------------------------------------------------------------------------------------------------------------166Prevents the client clicking page elements outside of the website avoiding hijacking or UI redress attacks167168169.. sourcecode:: html170 171 X-Frame-Options: DENY 172 X-Frame-Options: SAMEORIGIN173 X-Frame-Options: ALLOW-FROM https://example.com/174175To learn more check `this <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security>`_ 176177* `flask-talisman <https://github.com/GoogleCloudPlatform/flask-talisman>`_178* `flask-secure-headers <https://github.com/twaldear/flask-secure-headers>`_179180`X-Content-Type-Options <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options>`_181-------------------------------------------------------------------------------------------------------------182183Prevents XSS by blocking requests on clients and forcing then to read the content type instead of first opening it.184185.. sourcecode:: html186 187 X-Content-Type-Options: nosniff188189To learn more check `this <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options>`_ 190191192* `flask-talisman <https://github.com/GoogleCloudPlatform/flask-talisman>`_193* `flask-secure-headers <https://github.com/twaldear/flask-secure-headers>`_194195`Cookie options <https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#Secure_and_HttpOnly_cookies>`_196----------------------------------------------------------------------------------------------------------197198For setting cookies on client-side storage199200Example201202.. sourcecode:: html203 204 Set-Cookie: [cookie-name]=[cookie-value] 205206To learn more check `this <https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#Secure_and_HttpOnly_cookies>`_207208* `flask-talisman <https://github.com/GoogleCloudPlatform/flask-talisman>`_209* `flask-secure-headers <https://github.com/twaldear/flask-secure-headers>`_210211`HTTP Public Key Pinning <https://developer.mozilla.org/en-US/docs/Web/HTTP/Public_Key_Pinning>`_ (HPKP)212-------------------------------------------------------------------------------------------------------213214For associating clients with web servers throught a certificate key and prevent MITM attacks215216Example217218.. sourcecode:: html219220 Public-Key-Pins: pin-sha256="base64=="; max-age=expireTime [; includeSubDomains][; report-uri="reportURI"] 221222To learn more check `this <https://developer.mozilla.org/en-US/docs/Web/HTTP/Public_Key_Pinning>`_223224* `flask-talisman <https://github.com/GoogleCloudPlatform/flask-talisman>`_225* `flask-secure-headers <https://github.com/twaldear/flask-secure-headers>`_226227References:228-----------229230* https://docs.djangoproject.com/en/1.11/topics/security/231* https://blog.appcanary.com/2017/http-security-headers.html232* https://developer.mozilla.org233* https://csp.withgoogle.com/docs/index.html