Skip to content

A platform for community discussion. Free, open, simple.

FIX: Allow sanitized-HTML in GH issues and categories oneboxes. (#25374)

Roman Rizzia709b7e86147
diff --git a/lib/onebox/engine/github_issue_onebox.rb b/lib/onebox/engine/github_issue_onebox.rb
index 385c8cbce48..145df704f0e 100644
--- a/lib/onebox/engine/github_issue_onebox.rb
+++ b/lib/onebox/engine/github_issue_onebox.rb
@@ -40,7 +40,10 @@ module Onebox
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,
diff --git a/lib/onebox/templates/discourse_category_onebox.mustache b/lib/onebox/templates/discourse_category_onebox.mustache
index 001f02fbf54..9e6814e4f1e 100644
--- a/lib/onebox/templates/discourse_category_onebox.mustache
+++ b/lib/onebox/templates/discourse_category_onebox.mustache
@@ -12,7 +12,7 @@
{{#description}}
<div>
<span class="description">
- <p>{{description}}</p>
+ <p>{{{description}}}</p>
</span>
</div>
{{/description}}
diff --git a/lib/oneboxer.rb b/lib/oneboxer.rb
index 5349b8a1d05..40e2b1c76aa 100644
--- a/lib/oneboxer.rb
+++ b/lib/oneboxer.rb
@@ -486,7 +486,7 @@ module Oneboxer
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 } },
diff --git a/spec/lib/onebox/engine/github_issue_onebox_spec.rb b/spec/lib/onebox/engine/github_issue_onebox_spec.rb
index d2507e8f9bd..c79c1eb4438 100644
--- a/spec/lib/onebox/engine/github_issue_onebox_spec.rb
+++ b/spec/lib/onebox/engine/github_issue_onebox_spec.rb
@@ -16,7 +16,7 @@ RSpec.describe Onebox::Engine::GithubIssueOnebox do
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