Skip to content

Commit

Permalink
Do not allow images in comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mvz committed Feb 13, 2022
1 parent 44ba63f commit b50df05
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
6 changes: 5 additions & 1 deletion publify_core/app/models/feedback.rb
Expand Up @@ -67,6 +67,10 @@ def self.paginated(page, per_page)
page(page).per(per_page)
end

def self.allowed_tags
@allowed_tags ||= Rails::Html::SafeListSanitizer.allowed_tags - ["img"]
end

def parent
article
end
Expand All @@ -86,7 +90,7 @@ def permalink_url(_anchor = :ignored, only_path = false)

def html_postprocess(_field, html)
helper = ContentTextHelpers.new
helper.sanitize(helper.auto_link(html))
helper.sanitize(helper.auto_link(html), tags: self.class.allowed_tags)
end

def correct_url
Expand Down
23 changes: 23 additions & 0 deletions publify_core/spec/models/comment_spec.rb
Expand Up @@ -268,6 +268,29 @@ def valid_comment(options = {})
end
end

context "with a comment containing some html" do
let(:comment) do
described_class.new do |c|
c.body = "Test <b>foo</b> <img src=\"https://eviloverlord.com/getmyip.jpg\">"
c.author = "Bob"
c.article = build_stubbed(:article, blog: blog)
end
end

["", "textile", "markdown", "smartypants", "markdown smartypants"].each do |filter|
it "rejects images but not formatting with filter '#{filter}'" do
blog.comment_text_filter = filter

html = comment.html(:body)

ActiveSupport::Deprecation.silence do
expect(html).not_to match(/<img/)
expect(html).to match(%r{<b>foo</b>})
end
end
end
end

context "with a markdown comment with italic and bold" do
let(:comment) { build(:comment, body: "Comment body _italic_ **bold**") }
let(:blog) { comment.article.blog }
Expand Down

0 comments on commit b50df05

Please sign in to comment.