Enable setting of security http headers
authorMagnus Hagander <magnus@hagander.net>
Thu, 20 Dec 2018 15:50:24 +0000 (16:50 +0100)
committerMagnus Hagander <magnus@hagander.net>
Fri, 21 Dec 2018 20:46:28 +0000 (21:46 +0100)
commitd36ea4a9857e5fd142a87af43d96e54247470dc0
treeeb125bcb55828601a16a26b538803ca11e8cf10a
parent48db40f71e2858e3442b9433bc826b46e8922884
Enable setting of security http headers

The following security policy headers are set:

X-XSS-Protection: 1; mode=block -- always set

X-Frame-Options: DENY is set for all pages except for the documentation
  pages, primarily because pgadmin4 loads them in an iframe which would
  break.

Content-Security-Policy: <x>-src
  Is set to allow the default of self only, then allowing scripts for
  google analytics and fonts for google fonts. Images are allowed from everywhere.
  frame-ancestors 'none' is set by the same rules as X-Frame-Options

This also adds a decorator for @script_sources to have a single view
allow extra sources, and this is used for recaptcha. A generic decorator
is also made for other types of exclusions, though we don't have any at
this point.

If the setting SECURITY_POLICY_REPORT_ONLY is set to True then the policy
will be report-only and not enforced (for testing), otherwise enforcing
mode is enabled.

The setting SECURITY_POLICY_REPORT_URI sets where to send security
policy reports, if any.
pgweb/account/views.py
pgweb/docs/views.py
pgweb/util/decorators.py
pgweb/util/middleware.py