]> Sergey Matveev's repositories - public-inbox.git/commitdiff
www: prevent '!important' in BOFH-specified CSS
authorEric Wong <e@80x24.org>
Sat, 23 Feb 2019 10:56:38 +0000 (10:56 +0000)
committerEric Wong <e@80x24.org>
Sat, 23 Feb 2019 11:03:00 +0000 (11:03 +0000)
CSS specified by the BOFH must never take precedence over
what a user sets in userContent.css.

lib/PublicInbox/WWW.pm

index cbaf88450ca8548c513abb9bdd85e8da16b2cd65..7ed4f654c69085977fb17a3a0764919624e21418 100644 (file)
@@ -512,8 +512,9 @@ sub stylesheets_prepare ($$) {
                if (defined $attr->{href}) {
                        $inline_ok = 0;
                } else {
-                       open(my $fh, '<', $_) or do {
-                               warn "failed to open $_: $!\n";
+                       my $fn = $_;
+                       open(my $fh, '<', $fn) or do {
+                               warn "failed to open $fn: $!\n";
                                next;
                        };
                        my ($key) = (m!([^/]+?)(?:\.css)?\z!i);
@@ -523,6 +524,13 @@ sub stylesheets_prepare ($$) {
                                $ctime = sprintf('%x',(stat($fh))[10]);
                                $local = $mini->($local);
                        }
+
+                       # do not let BOFHs override userContent.css:
+                       if ($local =~ /!\s*important\b/i) {
+                               warn "ignoring $fn since it uses `!important'\n";
+                               next;
+                       }
+
                        $css_map->{$key} = $local;
                        $attr->{href} = "$upfx$key.css?$ctime";
                        if (defined($attr->{title})) {