Skip to content

Commit

Permalink
Add option forbidden_inline_options
Browse files Browse the repository at this point in the history
It is sometimes necessary to restrict the options that can be set
inline, ie. using the {::options ...} extensions.

By default, the template option is now forbidden to avoid possible
security problems. This addresses CVE-2020-14001.
  • Loading branch information
gettalong committed Jun 27, 2020
1 parent dd1bab4 commit 1b8fd33
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/kramdown/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,16 @@ def self.simple_hash_validator(val, name)
Used by: HTML converter
EOF

define(:forbidden_inline_options, Object, %w[template], <<~EOF) do |val|
Defines the options that may not be set using the {::options} extension
Default: template
Used by: HTML converter
EOF
val.map! {|item| item.kind_of?(String) ? str_to_sym(item) : item }
simple_array_validator(val, :forbidden_inline_options)
end

end

end
6 changes: 6 additions & 0 deletions lib/kramdown/parser/kramdown/extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ def handle_extension(name, opts, body, type, line_no = nil)
opts.select do |k, v|
k = k.to_sym
if Kramdown::Options.defined?(k)
if @options[:forbidden_inline_options].include?(k) ||
k == :forbidden_inline_options
warning("Option #{k} may not be set inline")
next false
end

begin
val = Kramdown::Options.parse(k, v)
@options[k] = val
Expand Down
2 changes: 2 additions & 0 deletions test/testcases/block/12_extension/options.text
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ some <span>*para*</span>
Some text[^ab].

[^ab]: Some text.

{::options template="/etc/passwd" /}

0 comments on commit 1b8fd33

Please sign in to comment.