Skip to content

Commit

Permalink
FIX: Allow sanitized-HTML in GH issues and categories oneboxes. (disc…
Browse files Browse the repository at this point in the history
  • Loading branch information
romanrizzi authored Jan 22, 2024
1 parent a37d26f commit a709b7e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion lib/onebox/engine/github_issue_onebox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ def data
body, excerpt = compute_body(raw["body"])
ulink = URI(link)

labels = raw["labels"].map { |l| { name: Emoji.codes_to_img(CGI.escapeHTML(l["name"])) } }
labels =
raw["labels"].map do |l|
{ name: Emoji.codes_to_img(Onebox::Helpers.sanitize(l["name"])) }
end

{
link: @url,
Expand Down
2 changes: 1 addition & 1 deletion lib/onebox/templates/discourse_category_onebox.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{{#description}}
<div>
<span class="description">
<p>{{description}}</p>
<p>{{{description}}}</p>
</span>
</div>
{{/description}}
Expand Down
2 changes: 1 addition & 1 deletion lib/oneboxer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ def self.local_category_html(url, route)
name: category.name,
color: category.color,
logo_url: category.uploaded_logo&.url,
description: category.description,
description: Onebox::Helpers.sanitize(category.description),
has_subcategories: category.subcategories.present?,
subcategories:
category.subcategories.collect { |sc| { name: sc.name, color: sc.color, url: sc.url } },
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/onebox/engine/github_issue_onebox_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
describe "#to_html" do
it "sanitizes the input and transform the emoji into an img tag" do
sanitized_label =
'Test <img src="/images/emoji/twitter/+1.png?v=12" title="+1" class="emoji" alt="+1" loading="lazy" width="20" height="20"> &lt;style&gt;body {display: none}&lt;/style&gt;'
'Test <img src="/images/emoji/twitter/+1.png?v=12" title="+1" class="emoji" alt="+1" loading="lazy" width="20" height="20">'

expect(html).to include(sanitized_label)
end
Expand Down

0 comments on commit a709b7e

Please sign in to comment.