From 09e80c7752b0d9080688e4597c7495dd109e0963 Mon Sep 17 00:00:00 2001 From: Martin Gruner Date: Tue, 4 Sep 2018 11:09:30 +0200 Subject: [PATCH] Improved HTML filter. --- Kernel/System/HTMLUtils.pm | 20 +++++- scripts/test/HTMLUtils/Safety.t | 110 ++++++++++++++++++++++++++++++++ 2 files changed, 129 insertions(+), 1 deletion(-) diff --git a/Kernel/System/HTMLUtils.pm b/Kernel/System/HTMLUtils.pm index 27437e7c1b3..381713f39e3 100644 --- a/Kernel/System/HTMLUtils.pm +++ b/Kernel/System/HTMLUtils.pm @@ -1163,10 +1163,28 @@ sub Safety { }egsxim; } + # Remove malicious CSS content + $Tag =~ s{ + (\s)style=("|') (.*?) \2 + } + { + my ($Space, $Delimiter, $Content) = ($1, $2, $3); + + if ( + ($Param{NoIntSrcLoad} && $Content =~ m{url\(}) + || ($Param{NoExtSrcLoad} && $Content =~ m/(http|ftp|https):\//i)) { + $Replaced = 1; + ''; + } + else { + "${Space}style=${Delimiter}${Content}${Delimiter}"; + } + }egsxim; + # remove load tags if ($Param{NoIntSrcLoad} || $Param{NoExtSrcLoad}) { $Tag =~ s{ - ($TagStart (.+?) (?: \s | /) src=(.+?) (\s.+?|) $TagEnd) + ($TagStart (.+?) (?: \s | /) (?:src|poster)=(.+?) (\s.+?|) $TagEnd) } { my $URL = $3; diff --git a/scripts/test/HTMLUtils/Safety.t b/scripts/test/HTMLUtils/Safety.t index 62462ed9396..3f0098c9a34 100644 --- a/scripts/test/HTMLUtils/Safety.t +++ b/scripts/test/HTMLUtils/Safety.t @@ -816,6 +816,116 @@ You should be able to continue reading these lessons, however. Replace => 0, }, }, + { + Name => 'Safety - remote poster attribute, forbidden', + Input => '