aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/Cobrand/Default.pm
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2019-11-25 13:59:08 +0000
committerMatthew Somerville <matthew@mysociety.org>2019-11-25 13:59:08 +0000
commite64110f3ee50f6d8f4b3e04df7ed6cd6443c114f (patch)
tree473064952ce207e8c3852d6d1e953888d0498dc7 /perllib/FixMyStreet/Cobrand/Default.pm
parent3936729479271dc84edf01e0ff840125a61eeb84 (diff)
parenta1b76bb7873c002a987132280395093d03992b13 (diff)
Merge branch 'csp-uk'
Diffstat (limited to 'perllib/FixMyStreet/Cobrand/Default.pm')
-rw-r--r--perllib/FixMyStreet/Cobrand/Default.pm17
1 files changed, 17 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm
index 620183078..1f2e48994 100644
--- a/perllib/FixMyStreet/Cobrand/Default.pm
+++ b/perllib/FixMyStreet/Cobrand/Default.pm
@@ -14,6 +14,7 @@ use Digest::MD5 qw(md5_hex);
use Carp;
use mySociety::PostcodeUtil;
+use mySociety::Random;
=head1 The default cobrand
@@ -74,6 +75,22 @@ sub feature {
return $features->{$feature}->{$self->moniker};
}
+sub csp_config {
+ FixMyStreet->config('CONTENT_SECURITY_POLICY');
+}
+
+sub add_response_headers {
+ my $self = shift;
+ # uncoverable branch true
+ return if $self->{c}->debug;
+ if (my $csp_domains = $self->csp_config) {
+ $csp_domains = '' if $csp_domains eq '1';
+ $csp_domains = join(' ', @$csp_domains) if ref $csp_domains;
+ my $csp_nonce = $self->{c}->stash->{csp_nonce} = unpack('h*', mySociety::Random::random_bytes(16, 1));
+ $self->{c}->res->header('Content-Security-Policy', "script-src 'self' 'unsafe-inline' 'nonce-$csp_nonce' $csp_domains; object-src 'none'; base-uri 'none'")
+ }
+}
+
=item password_minimum_length
Returns the minimum length a password can be set to.