[Rt-commit] rt branch, 5.0/reload-scrubber-on-config-change, created. rt-5.0.1-544-g46741ae84c
Jim Brandt
jbrandt at bestpractical.com
Thu Jun 24 16:53:42 EDT 2021
The branch, 5.0/reload-scrubber-on-config-change has been created
at 46741ae84c2a01e764193757482db49c9ae1f3b6 (commit)
- Log -----------------------------------------------------------------
commit 46741ae84c2a01e764193757482db49c9ae1f3b6
Author: Jim Brandt <jbrandt at bestpractical.com>
Date: Thu Jun 24 16:37:58 2021 -0400
Reload scrubber rules when web config changes are made
RT's HTML scrubber loads its rules in the constructor and
the scrubber object is persistent via the 'state' pragma.
Some RT config options can change the rules, so if config
is changed, we need to reload.
state variables can only be modified in the scope where
they are declared, so create a flag to tell us to reload
when necessary.
Before this change, updating the ShowRemoteImages config
option would not take effect immediately in the running
RT.
diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
index c03bc2fffd..a8e4539c65 100644
--- a/lib/RT/Config.pm
+++ b/lib/RT/Config.pm
@@ -2742,6 +2742,7 @@ sub RefreshConfigFromDatabase {
my $needs_update = RT->System->ConfigCacheNeedsUpdate;
if ($needs_update > $database_config_cache_time) {
$self->LoadConfigFromDatabase();
+ $HTML::Mason::Commands::ReloadScrubber = 1;
$database_config_cache_time = $needs_update;
}
}
diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index d9d6bd7a6c..d6597fab61 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -4678,8 +4678,21 @@ Removes unsafe and undesired HTML from the passed content
=cut
+# The scrubber loads its rules in the constructor and some RT
+# config options can change the rules. If config is changed,
+# this flag tells us to reload the state-ful scrubber.
+
+our $ReloadScrubber;
+
sub ScrubHTML {
state $scrubber = RT::Interface::Web::Scrubber->new;
+
+ if ( $HTML::Mason::Commands::ReloadScrubber ) {
+ undef $scrubber;
+ $scrubber = RT::Interface::Web::Scrubber->new;
+ $HTML::Mason::Commands::ReloadScrubber = 0;
+ }
+
return $scrubber->scrub(@_);
}
-----------------------------------------------------------------------
More information about the rt-commit
mailing list