Skip to content

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

SECURITY: Encode action_code_who in mention URLs

Isaac Janzen66653c484cfb
diff --git a/frontend/discourse/app/components/modal/nested-activity-log/item.gjs b/frontend/discourse/app/components/modal/nested-activity-log/item.gjs
index eb517c2cabc..e927408b3d0 100644
--- a/frontend/discourse/app/components/modal/nested-activity-log/item.gjs
+++ b/frontend/discourse/app/components/modal/nested-activity-log/item.gjs
@@ -41,7 +41,7 @@ function mentionLinkFor(code, who) {
) {
return `<a class="mention-group" href="${groupPath(encodeURIComponent(who))}">@${escaped}</a>`;
}
- return `<a class="mention" href="${userPath(who)}">@${escaped}</a>`;
+ return `<a class="mention" href="${userPath(encodeURIComponent(who))}">@${escaped}</a>`;
}
export default class NestedActivityLogItem extends Component {
diff --git a/frontend/discourse/app/components/post/small-action.gjs b/frontend/discourse/app/components/post/small-action.gjs
index d116ae739b8..4013cbc85d3 100644
--- a/frontend/discourse/app/components/post/small-action.gjs
+++ b/frontend/discourse/app/components/post/small-action.gjs
@@ -114,7 +114,7 @@ export default class PostSmallAction extends Component {
if (this.isGroupAction) {
who = `<a class="mention-group" href="${groupPath(encodeURIComponent(this.who))}">@${escapedWho}</a>`;
} else {
- who = `<a class="mention" href="${userPath(this.who)}">@${escapedWho}</a>`;
+ who = `<a class="mention" href="${userPath(encodeURIComponent(this.who))}">@${escapedWho}</a>`;
}
}
diff --git a/frontend/discourse/tests/integration/components/post/small-action-test.gjs b/frontend/discourse/tests/integration/components/post/small-action-test.gjs
index c0b90f8ae95..909791cb10c 100644
--- a/frontend/discourse/tests/integration/components/post/small-action-test.gjs
+++ b/frontend/discourse/tests/integration/components/post/small-action-test.gjs
@@ -165,9 +165,8 @@ module("Integration | Component | Post | PostSmallAction", function (hooks) {
this.post.action_code = "some_code";
this.post.action_code_who = "somegroup";
- I18n.translations[I18n.locale].js.action_codes = {
- some_code: "Some %{who} Code Action",
- };
+ I18n.translations[I18n.locale].js.action_codes.some_code =
+ "Some %{who} Code Action";
await renderComponent(this.post);
@@ -187,6 +186,23 @@ module("Integration | Component | Post | PostSmallAction", function (hooks) {
);
});
+ test("encodes action actor names in user mention hrefs", async function (assert) {
+ const xssPayload = '"><img src=x>';
+ const actionCode = "test_encoded_mention";
+ I18n.translations[I18n.locale].js.action_codes[actionCode] =
+ "Action %{who}";
+ this.post.action_code = actionCode;
+ this.post.action_code_who = xssPayload;
+
+ await renderComponent(this.post);
+
+ assert.dom(".small-action-desc img").doesNotExist();
+ assert
+ .dom(".small-action-desc a.mention")
+ .hasAttribute("href", `/u/${encodeURIComponent(xssPayload)}`)
+ .hasText(`@${xssPayload}`);
+ });
+
test("api.addPostSmallActionIcon", async function (assert) {
withPluginApi((api) => {
api.addPostSmallActionIcon("open_topic", "far-circle-check");
@@ -381,6 +397,38 @@ module(
await click(".nested-activity-log-modal__post .small-action-delete");
});
+ test("encodes synthetic action actor names in user mention hrefs", async function (assert) {
+ const xssPayload = '"><img src=x>';
+ const actionCode = "test_encoded_mention";
+ I18n.translations[I18n.locale].js.action_codes[actionCode] =
+ "Action %{who}";
+ const syntheticAction = {
+ synthetic: true,
+ action_code: actionCode,
+ action_code_who: xssPayload,
+ created_at: "2025-09-23T16:10:28.695Z",
+ user_id: 42,
+ username: "activity-author",
+ avatar_template: "/letter_avatar_proxy/v4/letter/a/13edae/{size}.png",
+ };
+
+ await render(
+ <template>
+ <ul>
+ <NestedActivityLogItem @action={{syntheticAction}} @topicId={{1}} />
+ </ul>
+ </template>
+ );
+
+ assert
+ .dom(".nested-activity-log-modal__desc img[src='x']")
+ .doesNotExist();
+ assert
+ .dom(".nested-activity-log-modal__desc a.mention")
+ .hasAttribute("href", `/u/${encodeURIComponent(xssPayload)}`)
+ .hasText(`@${xssPayload}`);
+ });
+
test("keeps the synthetic topic-created row read-only", async function (assert) {
const syntheticAction = {
synthetic: true,
diff --git a/plugins/discourse-assign/test/javascripts/acceptance/assigned-topic-test.js b/plugins/discourse-assign/test/javascripts/acceptance/assigned-topic-test.js
index fe99603b248..102a9b6dd0a 100644
--- a/plugins/discourse-assign/test/javascripts/acceptance/assigned-topic-test.js
+++ b/plugins/discourse-assign/test/javascripts/acceptance/assigned-topic-test.js
@@ -265,6 +265,7 @@ acceptance("Reassign topic conditionals", function (needs) {
acceptance("Assignee name XSS escaping", function (needs) {
const XSS_PAYLOAD = '<img src="xss-test">';
+ const SMALL_ACTION_XSS_PAYLOAD = '"><img src=x>';
needs.user();
needs.settings({
@@ -300,7 +301,7 @@ acceptance("Assignee name XSS escaping", function (needs) {
topic_id: topic.id,
topic_slug: topic.slug,
action_code: "assigned",
- action_code_who: XSS_PAYLOAD,
+ action_code_who: SMALL_ACTION_XSS_PAYLOAD,
};
topic.post_stream.posts.push(smallActionPost);
topic.post_stream.stream.push(999);
@@ -369,13 +370,21 @@ acceptance("Assignee name XSS escaping", function (needs) {
.includesText(XSS_PAYLOAD, "renders payload as escaped text in tag");
});
- test("escapes HTML in small action description", async function (assert) {
+ test("encodes user assignee names in small action mention hrefs", 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");
+ .dom(".small-action .small-action-desc img[src='x']")
+ .doesNotExist("does not render an injected image in the small action");
+ assert
+ .dom(".small-action .small-action-desc a.mention")
+ .hasAttribute(
+ "href",
+ `/u/${encodeURIComponent(SMALL_ACTION_XSS_PAYLOAD)}`,
+ "keeps the payload in one encoded href attribute"
+ )
+ .hasText(`@${SMALL_ACTION_XSS_PAYLOAD}`);
});
test("escapes HTML in topic-level unassign menu", async function (assert) {