Add helper to build CSP host list (#2513)

This commit is contained in:
Maxime Besson 2021-04-22 17:47:50 +02:00
parent 82620525ba
commit 5ba0c11b58

View File

@ -15,6 +15,7 @@ package Lemonldap::NG::Portal::Main;
use strict;
use URI::Escape;
use URI;
use JSON;
use Lemonldap::NG::Common::Util qw(getPSessionID);
@ -1198,4 +1199,16 @@ sub loadTemplate {
return $tpl->output;
}
# This method extracts the scheme://host:port part of a URL for use in
# Content-Security-Polity header
sub cspGetHost {
my ( $self, $url ) = @_;
my $uri = $url // "";
unless ( $uri->isa("URI") ) {
$uri = URI->new($uri);
}
return (
$uri->scheme . "://" . ( $uri->_port ? $uri->host_port : $uri->host ) );
}
1;