Skip to content

Commit c246ffa

Browse files
committed
Limits the schemes that Markdown links can use (#22924).
git-svn-id: http://svn.redmine.org/redmine/trunk@15431 e93f8b46-1217-0410-a6f0-8f06a7374b81
1 parent a682851 commit c246ffa

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

lib/redmine/helpers/url.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Redmine - project management software
2+
# Copyright (C) 2006-2016 Jean-Philippe Lang
3+
#
4+
# This program is free software; you can redistribute it and/or
5+
# modify it under the terms of the GNU General Public License
6+
# as published by the Free Software Foundation; either version 2
7+
# of the License, or (at your option) any later version.
8+
#
9+
# This program is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with this program; if not, write to the Free Software
16+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17+
18+
require 'uri'
19+
20+
module Redmine
21+
module Helpers
22+
module URL
23+
def uri_with_safe_scheme?(uri, schemes = ['http', 'https', 'ftp', 'mailto', nil])
24+
# URLs relative to the current document or document root (without a protocol
25+
# separator, should be harmless
26+
return true unless uri.include? ":"
27+
28+
# Other URLs need to be parsed
29+
schemes.include? URI.parse(uri).scheme
30+
rescue URI::InvalidURIError
31+
false
32+
end
33+
end
34+
end
35+
end

lib/redmine/wiki_formatting/markdown/formatter.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ module WikiFormatting
2222
module Markdown
2323
class HTML < Redcarpet::Render::HTML
2424
include ActionView::Helpers::TagHelper
25+
include Redmine::Helpers::URL
2526

2627
def link(link, title, content)
28+
return nil unless uri_with_safe_scheme?(link)
29+
2730
css = nil
2831
unless link && link.starts_with?('/')
2932
css = 'external'

0 commit comments

Comments
 (0)