From 35f5e36838952a20693c8d6fa2a926648739a975 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 28 Dec 2008 13:38:34 +0000 Subject: [PATCH] Disable textile inline styles to prevent XSS attacks (#2377). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2192 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- lib/redcloth3.rb | 3 +-- lib/redmine/wiki_formatting/textile/formatter.rb | 1 + test/unit/helpers/application_helper_test.rb | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/redcloth3.rb b/lib/redcloth3.rb index 69332395..ae17f676 100644 --- a/lib/redcloth3.rb +++ b/lib/redcloth3.rb @@ -470,8 +470,7 @@ class RedCloth3 < String style << "vertical-align:#{ v_align( $& ) };" if text =~ A_VLGN end - style << "#{ htmlesc $1 };" if not filter_styles and - text.sub!( /\{([^}]*)\}/, '' ) + style << "#{ htmlesc $1 };" if text.sub!( /\{([^}]*)\}/, '' ) && !filter_styles lang = $1 if text.sub!( /\[([^)]+?)\]/, '' ) diff --git a/lib/redmine/wiki_formatting/textile/formatter.rb b/lib/redmine/wiki_formatting/textile/formatter.rb index 1a198233..b55287ba 100644 --- a/lib/redmine/wiki_formatting/textile/formatter.rb +++ b/lib/redmine/wiki_formatting/textile/formatter.rb @@ -30,6 +30,7 @@ module Redmine super self.hard_breaks=true self.no_span_caps=true + self.filter_styles=true end def to_html(*rules, &block) diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb index 261614d3..5f1a5893 100644 --- a/test/unit/helpers/application_helper_test.rb +++ b/test/unit/helpers/application_helper_test.rb @@ -69,7 +69,8 @@ class ApplicationHelperTest < HelperTestCase '!http://foo.bar/image.jpg!' => '', 'floating !>http://foo.bar/image.jpg!' => 'floating
', 'with class !(some-class)http://foo.bar/image.jpg!' => 'with class ', - 'with style !{width:100px;height100px}http://foo.bar/image.jpg!' => 'with style ', + # inline styles should be stripped + 'with style !{width:100px;height100px}http://foo.bar/image.jpg!' => 'with style ', 'with title !http://foo.bar/image.jpg(This is a title)!' => 'with title This is a title', 'with title !http://foo.bar/image.jpg(This is a double-quoted "title")!' => 'with title This is a double-quoted "title"', }