A platform for community discussion. Free, open, simple.
SECURITY: Stored XSS via unescaped assignee name
Sérgio Saquetim46edb174e237
diff --git a/frontend/discourse/app/components/post/small-action.gjs b/frontend/discourse/app/components/post/small-action.gjsindex 800d5c35101..cf2823260ee 100644--- a/frontend/discourse/app/components/post/small-action.gjs+++ b/frontend/discourse/app/components/post/small-action.gjs@@ -13,6 +13,7 @@ import { autoUpdatingRelativeAge, relativeAge } from "discourse/lib/formatter";import getURL from "discourse/lib/get-url";import { applyValueTransformer } from "discourse/lib/transformer";import { userPath } from "discourse/lib/url";+import { escapeExpression } from "discourse/lib/utilities";import { i18n } from "discourse-i18n";import PostA11yHeading from "./a11y-heading";@@ -109,12 +110,11 @@ export default class PostSmallAction extends Component {let who = "";if (this.who) {+ const escapedWho = escapeExpression(this.who);if (this.isGroupAction) {- who = `<a class="mention-group" href="/g/${this.who}">@${this.who}</a>`;+ who = `<a class="mention-group" href="/g/${encodeURIComponent(this.who)}">@${escapedWho}</a>`;} else {- who = `<a class="mention" href="${userPath(this.who)}">@${- this.who- }</a>`;+ who = `<a class="mention" href="${userPath(this.who)}">@${escapedWho}</a>`;}}diff --git a/plugins/discourse-assign/assets/javascripts/discourse/components/assigned-to-first-post.gjs b/plugins/discourse-assign/assets/javascripts/discourse/components/assigned-to-first-post.gjsindex 2f443098400..64ccfd82e80 100644--- a/plugins/discourse-assign/assets/javascripts/discourse/components/assigned-to-first-post.gjs+++ b/plugins/discourse-assign/assets/javascripts/discourse/components/assigned-to-first-post.gjs@@ -3,6 +3,7 @@ import { service } from "@ember/service";import { trustHTML } from "@ember/template";import icon from "discourse/helpers/d-icon";import { bind } from "discourse/lib/decorators";+import { escapeExpression } from "discourse/lib/utilities";import { i18n } from "discourse-i18n";import {assignedToGroupPath,@@ -65,6 +66,11 @@ export default class AssignedToFirstPost extends Component {: assignee.username;}+ @bind+ escapedPrioritizedAssigneeName(assignee) {+ return escapeExpression(this.prioritizedAssigneeName(assignee));+ }+<template>{{#if this.isAssigned}}<p class="assigned-to">@@ -75,7 +81,9 @@ export default class AssignedToFirstPost extends Component {{{trustHTML(i18n"discourse_assign.assigned_topic_to"- username=(this.prioritizedAssigneeName this.assignedToUser)+ username=(this.escapedPrioritizedAssigneeName+ this.assignedToUser+ )path=(assignedToUserPath this.assignedToUser))}}@@ -89,7 +97,9 @@ export default class AssignedToFirstPost extends Component {{{trustHTML(i18n"discourse_assign.assigned_topic_to"- username=this.assignedToGroup.name+ username=(this.escapedPrioritizedAssigneeName+ this.assignedToGroup+ )path=(assignedToGroupPath this.assignedToGroup))}}diff --git a/plugins/discourse-assign/assets/javascripts/discourse/components/topic-level-assign-menu.js b/plugins/discourse-assign/assets/javascripts/discourse/components/topic-level-assign-menu.jsindex ce2ea7158f9..9069ece2cd3 100644--- a/plugins/discourse-assign/assets/javascripts/discourse/components/topic-level-assign-menu.js+++ b/plugins/discourse-assign/assets/javascripts/discourse/components/topic-level-assign-menu.js@@ -2,6 +2,7 @@ import { getOwner } from "@ember/owner";import { trustHTML } from "@ember/template";import { renderAvatar } from "discourse/helpers/user-avatar";import { iconHTML } from "discourse/lib/icon-library";+import { escapeExpression } from "discourse/lib/utilities";import { i18n } from "discourse-i18n";import EditTopicAssignments from "../components/modal/edit-topic-assignments";@@ -147,7 +148,7 @@ function unassignFromTopicButton(topic, prioritize_full_name_in_ux) {? avatarHtml(topic.assigned_to_user, "small"): iconHTML("user-xmark");const label = i18n("discourse_assign.topic_level_menu.unassign_from_topic", {- username,+ username: escapeExpression(username),});return {@@ -179,14 +180,15 @@ function unassignFromPostButton(postId, assignment) {icon = iconHTML("group-times");}+ const escapedAssignee = escapeExpression(assignee);const label = i18n("discourse_assign.topic_level_menu.unassign_from_post", {- assignee,+ assignee: escapedAssignee,post_number: assignment.post_number,});const dataName = i18n("discourse_assign.topic_level_menu.unassign_from_post_help",{- assignee,+ assignee: escapedAssignee,post_number: assignment.post_number,});diff --git a/plugins/discourse-assign/assets/javascripts/discourse/initializers/extend-for-assigns.js b/plugins/discourse-assign/assets/javascripts/discourse/initializers/extend-for-assigns.jsindex c6128dde65d..2ae757d27c9 100644--- a/plugins/discourse-assign/assets/javascripts/discourse/initializers/extend-for-assigns.js+++ b/plugins/discourse-assign/assets/javascripts/discourse/initializers/extend-for-assigns.js@@ -112,16 +112,16 @@ function registerTopicFooterButtons(api) {if (user) {return trustHTML(- `<span class="unassign-label"><span class="text">${label} </span><span class="username">${+ `<span class="unassign-label"><span class="text">${label} </span><span class="username">${escapeExpression(user.username- }</span></span> ${renderAvatar(user, {+ )}</span></span> ${renderAvatar(user, {imageSize: "small",ignoreTitle: true,})}`);} else if (group) {return trustHTML(- `<span class="unassign-label">${label}</span> @${group.name}`+ `<span class="unassign-label">${label}</span> @${escapeExpression(group.name)}`);}},@@ -418,7 +418,7 @@ function initialize(api) {return `<${tagName} class="assigned-to discourse-tag simple" ${href}>${icon}<span title="${escapeExpression(note- )}">${name}</span></${tagName}>`;+ )}">${escapeExpression(name)}</span></${tagName}>`;};// is there's one assignment just return the tagdiff --git a/plugins/discourse-assign/test/javascripts/acceptance/assigned-topic-test.js b/plugins/discourse-assign/test/javascripts/acceptance/assigned-topic-test.jsindex 1b47298d526..c93a6282fec 100644--- a/plugins/discourse-assign/test/javascripts/acceptance/assigned-topic-test.js+++ b/plugins/discourse-assign/test/javascripts/acceptance/assigned-topic-test.js@@ -262,3 +262,131 @@ acceptance(`Discourse Assign | Reassign topic conditionals`, function (needs) {assert.false(menu.rowByValue("reassign-self").exists());});});++acceptance(`Discourse Assign | Assignee name XSS escaping`, function (needs) {+ const XSS_PAYLOAD = '<img src="xss-test">';++ needs.user();+ needs.settings({+ assign_enabled: true,+ tagging_enabled: true,+ assigns_user_url_path: "/",+ assigns_public: true,+ prioritize_full_name_in_ux: true,+ });++ needs.pretender((server, helper) => {+ server.get("/t/44.json", () => {+ let topic = cloneJSON(topicFixtures["/t/28830/1.json"]);+ topic["assigned_to_user"] = {+ username: "eviltrout",+ name: XSS_PAYLOAD,+ avatar_template:+ "/letter_avatar/eviltrout/{size}/3_f9720745f5ce6dfc2b5641fca999d934.png",+ };+ topic["indirectly_assigned_to"] = {};++ // Add a small action post with XSS payload in action_code_who+ const smallActionPost = {+ id: 999,+ username: "system",+ avatar_template: "/images/avatar.png",+ created_at: "2026-03-10T00:00:00.000Z",+ cooked: "",+ post_number: 3,+ post_type: 3,+ updated_at: "2026-03-10T00:00:00.000Z",+ yours: false,+ topic_id: topic.id,+ topic_slug: topic.slug,+ action_code: "assigned",+ action_code_who: XSS_PAYLOAD,+ };+ topic.post_stream.posts.push(smallActionPost);+ topic.post_stream.stream.push(999);++ return helper.response(topic);+ });++ server.get("/t/45.json", () => {+ let topic = cloneJSON(topicFixtures["/t/28830/1.json"]);+ topic["assigned_to_group"] = {+ name: XSS_PAYLOAD,+ };+ return helper.response(topic);+ });+ });++ test("escapes HTML in user assignee name on first post", async function (assert) {+ updateCurrentUser({ can_assign: true });+ await visit("/t/assignment-topic/44");++ assert+ .dom("#post_1 .assigned-to--user img[src='xss-test']")+ .doesNotExist("does not render injected img from user name");++ assert+ .dom("#post_1 .assigned-to--user")+ .includesText(XSS_PAYLOAD, "renders payload as escaped text");+ });++ test("escapes HTML in user assignee name in topic tag", async function (assert) {+ updateCurrentUser({ can_assign: true });+ await visit("/t/assignment-topic/44");++ assert+ .dom(".discourse-tags .assigned-to img[src='xss-test']")+ .doesNotExist("does not render injected img in topic tag");++ assert+ .dom(".discourse-tags .assigned-to span")+ .includesText(XSS_PAYLOAD, "renders payload as escaped text in tag");+ });++ test("escapes HTML in group assignee name on first post", async function (assert) {+ updateCurrentUser({ can_assign: true });+ await visit("/t/assignment-topic/45");++ assert+ .dom("#post_1 .assigned-to--group img[src='xss-test']")+ .doesNotExist("does not render injected img from group name");++ assert+ .dom("#post_1 .assigned-to--group")+ .includesText(XSS_PAYLOAD, "renders payload as escaped text");+ });++ test("escapes HTML in group assignee name in topic tag", async function (assert) {+ updateCurrentUser({ can_assign: true });+ await visit("/t/assignment-topic/45");++ assert+ .dom(".discourse-tags .assigned-to img[src='xss-test']")+ .doesNotExist("does not render injected img in topic tag");++ assert+ .dom(".discourse-tags .assigned-to span")+ .includesText(XSS_PAYLOAD, "renders payload as escaped text in tag");+ });++ test("escapes HTML in small action description", async function (assert) {+ updateCurrentUser({ can_assign: true });+ await visit("/t/assignment-topic/44");++ assert+ .dom(".small-action .small-action-desc img[src='xss-test']")+ .doesNotExist("does not render injected img in small action");+ });++ test("escapes HTML in topic-level unassign menu", async function (assert) {+ updateCurrentUser({ can_assign: true });+ const menu = selectKit("#topic-footer-dropdown-reassign");++ await visit("/t/assignment-topic/44");+ await menu.expand();++ assert+ .dom("#topic-footer-dropdown-reassign img[src='xss-test']")+ .doesNotExist("does not render injected img in unassign menu");+ });+});