A platform for community discussion. Free, open, simple.
SECURITY: Sanitize category hashtag `data-style-type`/`data-id` values before decorator... (#43869)
Samb1016b1bfb35
diff --git a/frontend/discourse/app/lib/hashtag-decorator.js b/frontend/discourse/app/lib/hashtag-decorator.jsindex 3be4a85fb47..8b622c1dee7 100644--- a/frontend/discourse/app/lib/hashtag-decorator.js+++ b/frontend/discourse/app/lib/hashtag-decorator.js@@ -106,9 +106,13 @@ export function decorateHashtags(element, site) {if (iconPlaceholderEl && hashtagTypeClass) {let opts = {icon: site.hashtag_icons[hashtagType],- id: hashtagEl.dataset.id,+ id: parseInt(hashtagEl.dataset.id, 10),slug: hashtagEl.dataset.slug,- style_type: hashtagEl.dataset?.styleType || "square",+ style_type: ["square", "icon", "emoji"].includes(+ hashtagEl.dataset.styleType+ )+ ? hashtagEl.dataset.styleType+ : "square",};if (opts.style_type === "icon") {diff --git a/spec/system/category_hashtag_decoration_spec.rb b/spec/system/category_hashtag_decoration_spec.rbnew file mode 100644index 00000000000..fe269501d28--- /dev/null+++ b/spec/system/category_hashtag_decoration_spec.rb@@ -0,0 +1,29 @@+# frozen_string_literal: true++RSpec.describe "Category hashtag decoration" do+ fab!(:author) { Fabricate(:user, trust_level: TrustLevel[1]) }+ fab!(:viewer, :user)+ fab!(:category)++ let(:topic_page) { PageObjects::Pages::Topic.new }+ let(:composer) { PageObjects::Components::Composer.new }++ it "does not turn hostile category hashtag attributes into viewer-visible HTML" do+ sign_in(author)+ topic_page.open_new_topic+ composer.fill_title("Hostile category hashtag attributes")+ composer.fill_content(<<~HTML)+ <a class="hashtag-cooked" data-type="category" data-id="#{category.id}" data-style-type='"><img class="style-type-injected-image">'><span class="hashtag-icon-placeholder"></span>#{category.name}</a>+ <a class="hashtag-cooked" data-type="category" data-id='#{category.id}"><img class="id-injected-image">' data-style-type="square"><span class="hashtag-icon-placeholder"></span>#{category.name}</a>+ HTML+ composer.create++ topic = Topic.find_by!(title: "Hostile category hashtag attributes")+ sign_in(viewer)+ topic_page.visit_topic(topic)++ expect(page).to have_css("#post_1 .hashtag-cooked", count: 2)+ expect(page).to have_no_css("#post_1 .style-type-injected-image")+ expect(page).to have_no_css("#post_1 .id-injected-image")+ end+end