From 5ba0c11b58c68f8930b9c5bb8d3fc3fe500da964 Mon Sep 17 00:00:00 2001 From: Maxime Besson Date: Thu, 22 Apr 2021 17:47:50 +0200 Subject: [PATCH] Add helper to build CSP host list (#2513) --- .../lib/Lemonldap/NG/Portal/Main/Run.pm | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm index 5474826a0..ef6309d59 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm @@ -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;