Skip to content

Commit

Permalink
[!] Sanitize incoming classlist properly (mastodon#6162)
Browse files Browse the repository at this point in the history
* Sanitize classlist properly

* Actually properly sanitize every class after the first

* Improve Formatter spec to check for multiple classes and non-space whitespace
  • Loading branch information
puckipedia authored and Gargron committed Jan 3, 2018
1 parent dbcd5b8 commit 3a63f16
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions app/lib/sanitize_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ module Config

CLASS_WHITELIST_TRANSFORMER = lambda do |env|
node = env[:node]
class_list = node['class']&.split(' ')
class_list = node['class']&.split(/[\t\n\f\r ]/)

return unless class_list

class_list.keep_if do |e|
return true if e =~ /^(h|p|u|dt|e)-/ # microformats classes
return true if e =~ /^(mention|hashtag)$/ # semantic classes
return true if e =~ /^(ellipsis|invisible)$/ # link formatting classes
next true if e =~ /^(h|p|u|dt|e)-/ # microformats classes
next true if e =~ /^(mention|hashtag)$/ # semantic classes
next true if e =~ /^(ellipsis|invisible)$/ # link formatting classes
end

node['class'] = class_list.join(' ')
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@
end

context 'contains malicious classes' do
let(:text) { '<span class="status__content__spoiler-link">Show more</span>' }
let(:text) { '<span class="mention status__content__spoiler-link">Show more</span>' }

it 'strips malicious classes' do
is_expected.to_not include 'status__content__spoiler-link'
Expand Down

0 comments on commit 3a63f16

Please sign in to comment.