A platform for community discussion. Free, open, simple.
SECURITY: Stored XSS via unescaped actor name in post actions
Keegan Georgedd786594ddd0
diff --git a/frontend/discourse/app/components/post-action-description.gjs b/frontend/discourse/app/components/post-action-description.gjsindex 744978debe7..02df2736092 100644--- a/frontend/discourse/app/components/post-action-description.gjs+++ b/frontend/discourse/app/components/post-action-description.gjs@@ -6,6 +6,7 @@ import {} from "discourse/components/post/small-action";import { autoUpdatingRelativeAge } from "discourse/lib/formatter";import { userPath } from "discourse/lib/url";+import { escapeExpression } from "discourse/lib/utilities";import { i18n } from "discourse-i18n";export function actionDescriptionHtml(actionCode, createdAt, username, path) {@@ -17,13 +18,14 @@ export function actionDescriptionHtml(actionCode, createdAt, username, path) {let who = "";if (username) {+ const escapedUsername = escapeExpression(username);if (GROUP_ACTION_CODES.includes(actionCode) ||customGroupActionCodes.includes(actionCode)) {- who = `<a class="mention-group" href="/g/${username}">@${username}</a>`;+ who = `<a class="mention-group" href="/g/${encodeURIComponent(username)}">@${escapedUsername}</a>`;} else {- who = `<a class="mention" href="${userPath(username)}">@${username}</a>`;+ who = `<a class="mention" href="${userPath(encodeURIComponent(username))}">@${escapedUsername}</a>`;}}return trustHTML(i18n(`action_codes.${actionCode}`, { who, when, path }));diff --git a/frontend/discourse/tests/integration/components/post-action-description-test.gjs b/frontend/discourse/tests/integration/components/post-action-description-test.gjsnew file mode 100644index 00000000000..478a655d77c--- /dev/null+++ b/frontend/discourse/tests/integration/components/post-action-description-test.gjs@@ -0,0 +1,28 @@+import { render } from "@ember/test-helpers";+import { module, test } from "qunit";+import PostActionDescription from "discourse/components/post-action-description";+import { setupRenderingTest } from "discourse/tests/helpers/component-test";++module("Integration | Component | PostActionDescription", function (hooks) {+ setupRenderingTest(hooks);++ test("escapes action actor names before trusting action description HTML", async function (assert) {+ this.username = '<img src=x onerror="alert(1)">';++ await render(+ <template>+ <PostActionDescription+ @actionCode="invited_user"+ @username={{this.username}}+ />+ </template>+ );++ assert+ .dom(".excerpt img")+ .doesNotExist("does not render actor name as HTML");+ assert+ .dom(".excerpt .mention")+ .hasText(`@${this.username}`, "shows the actor name as text");+ });+});