From 2faadcba8b1afa1716fb5de65c8b411ab4e47360 Mon Sep 17 00:00:00 2001 From: Marius Balteanu Date: Mon, 26 Sep 2022 22:35:48 +0000 Subject: [PATCH] Allow select custom CSS properties (#37237). MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Patch by Jens Krämer. git-svn-id: https://svn.redmine.org/redmine/trunk@21850 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- .../common_mark/sanitization_filter.rb | 15 +++++++++++++++ .../common_mark/sanitization_filter_test.rb | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/lib/redmine/wiki_formatting/common_mark/sanitization_filter.rb b/lib/redmine/wiki_formatting/common_mark/sanitization_filter.rb index 7fef35bfa..b1f1cfe01 100644 --- a/lib/redmine/wiki_formatting/common_mark/sanitization_filter.rb +++ b/lib/redmine/wiki_formatting/common_mark/sanitization_filter.rb @@ -27,6 +27,18 @@ module Redmine "a" => %w(href).freeze, }.freeze + ALLOWED_CSS_PROPERTIES = %w[ + color background-color + width + height + padding padding-left padding-right padding-top padding-bottom + margin margin-left margin-right margin-top margin-bottom + border border-left border-right border-top border-bottom border-radius border-style border-collapse border-spacing + font font-style font-variant font-weight font-stretch font-size line-height font-family + text-align + float + ].freeze + def allowlist @allowlist ||= customize_allowlist(super.deep_dup) end @@ -40,6 +52,9 @@ module Redmine allowlist[:attributes][:all].delete("name") allowlist[:attributes]["a"].push("name") + allowlist[:attributes][:all].push("style") + allowlist[:css] = { properties: ALLOWED_CSS_PROPERTIES } + # allow class on code tags (this holds the language info from fenced # code bocks and has the format language-foo) allowlist[:attributes]["code"] = %w(class) diff --git a/test/unit/lib/redmine/wiki_formatting/common_mark/sanitization_filter_test.rb b/test/unit/lib/redmine/wiki_formatting/common_mark/sanitization_filter_test.rb index 8cd6074ee..063727413 100644 --- a/test/unit/lib/redmine/wiki_formatting/common_mark/sanitization_filter_test.rb +++ b/test/unit/lib/redmine/wiki_formatting/common_mark/sanitization_filter_test.rb @@ -93,6 +93,10 @@ if Object.const_defined?(:CommonMarker) # samples taken from the Sanitize test suite # rubocop:disable Layout/LineLength STRINGS = [ + [ + 'hello"', + 'hello"' + ], [ 'Lorem ipsum dolor sit
amet ', 'Lorem ipsum dolor sit
amet .foo { color: #fff; } ' -- 2.39.5