[Rt-commit] rt branch 5.0/reload-scrubber-on-config-changes created. rt-5.0.4-55-g3ae3fcb2a2

BPS Git Server git at git.bestpractical.com
Fri Jul 7 17:36:45 UTC 2023


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".

The branch, 5.0/reload-scrubber-on-config-changes has been created
        at  3ae3fcb2a2a4a6bf3d9edb919c152331c06fb5f8 (commit)

- Log -----------------------------------------------------------------
commit 3ae3fcb2a2a4a6bf3d9edb919c152331c06fb5f8
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sat Jul 8 00:55:12 2023 +0800

    Test scrubber with updated ShowRemoteImages config

diff --git a/t/web/scrubber.t b/t/web/scrubber.t
new file mode 100644
index 0000000000..ea415c75ee
--- /dev/null
+++ b/t/web/scrubber.t
@@ -0,0 +1,33 @@
+use strict;
+use warnings;
+
+use RT::Test tests => undef;
+
+my $ticket = RT::Test->create_ticket(
+    Queue       => 'General',
+    Subject     => 'test scrubber',
+    ContentType => 'text/html',
+    Content     => <<'EOF' );
+Image start
+<img src="https://example.com/test.png">
+Image end
+EOF
+
+my ( $baseurl, $m ) = RT::Test->started_ok;
+ok $m->login, 'logged in';
+
+$m->goto_ticket( $ticket->Id );
+
+$m->content_lacks('<img src="https://example.com/test.png">', 'Remote images are not shown by default');
+
+my $config = RT::Configuration->new( RT->SystemUser );
+my ( $ret, $msg ) = $config->Create(
+    Name    => 'ShowRemoteImages',
+    Content => 1,
+);
+ok( $ret, 'Updated config' );
+
+$m->reload;
+$m->content_contains('<img src="https://example.com/test.png">', 'Remote images are shown with ShowRemoteImages=1');
+
+done_testing;

commit b0aaf5d30b0d0645e91f234cb54a30623867911a
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sat Jul 8 00:02:14 2023 +0800

    Tweak code logic to short-circuit config checks when img rules are pre-defined
    
    No functionalities are changed.

diff --git a/lib/RT/Interface/Web/Scrubber.pm b/lib/RT/Interface/Web/Scrubber.pm
index fd051fc4cc..c816bbccf2 100644
--- a/lib/RT/Interface/Web/Scrubber.pm
+++ b/lib/RT/Interface/Web/Scrubber.pm
@@ -182,7 +182,7 @@ sub new {
     local $RULES{img} unless $RULES{img};
 
     # If we're displaying images, let embedded ones through
-    if (RT->Config->Get('ShowTransactionImages') or RT->Config->Get('ShowRemoteImages')) {
+    if ( !$RULES{'img'} && ( RT->Config->Get('ShowTransactionImages') or RT->Config->Get('ShowRemoteImages') ) ) {
         my @src;
         push @src, qr/^cid:/i
             if RT->Config->Get('ShowTransactionImages');
@@ -190,7 +190,7 @@ sub new {
         push @src, $ALLOWED_ATTRIBUTES{'href'}
             if RT->Config->Get('ShowRemoteImages');
 
-        $RULES{'img'} ||= {
+        $RULES{'img'} = {
             '*' => 0,
             alt => 1,
             src => join("|", @src),

commit 2dfcc073932e684b1e0d757a3557294671f9c0ef
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Jul 7 23:57:21 2023 +0800

    Create a local version of $RULES{img} to update it dynamically based on configs
    
    When pre-defined value is absent, we set $RULES{img} according to
    current configs. By creating a local version, we can update it while not
    worrying about overriding the pre-defined value.

diff --git a/lib/RT/Interface/Web/Scrubber.pm b/lib/RT/Interface/Web/Scrubber.pm
index cb4951889e..fd051fc4cc 100644
--- a/lib/RT/Interface/Web/Scrubber.pm
+++ b/lib/RT/Interface/Web/Scrubber.pm
@@ -175,6 +175,12 @@ sub new {
     $self->deny(qw[*]);
     $self->allow(@ALLOWED_TAGS);
 
+    # If $RULES{'img'} is pre-defined by custom code, we shouldn't touch it. If
+    # it's not pre-defined, img rules could be different depending on configs,
+    # which can be dynamically changed from web UI. Via a local version, we can
+    # update it without worrying about affecting the pre-defined value.
+    local $RULES{img} unless $RULES{img};
+
     # If we're displaying images, let embedded ones through
     if (RT->Config->Get('ShowTransactionImages') or RT->Config->Get('ShowRemoteImages')) {
         my @src;

commit 38f543b32db1523806a27a7abc39b3835b7b4027
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Jul 7 23:46:01 2023 +0800

    Reload scrubber rules for current process that changes configs
    
    In 19327d95ba we reloaded scrubber rules for all the other processes.
    This commit completes it to make the same change to the current process.

diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
index 2cb614f825..8f6ccc15d6 100644
--- a/lib/RT/Config.pm
+++ b/lib/RT/Config.pm
@@ -2987,6 +2987,7 @@ sub ApplyConfigChangeToAllServerProcesses {
 
     # first apply locally
     $self->LoadConfigFromDatabase();
+    $HTML::Mason::Commands::ReloadScrubber = 1;
     $self->PostLoadCheck;
 
     # then notify other servers

-----------------------------------------------------------------------


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list