Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/onebox/engine/github_issue_onebox.rb
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
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
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
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