A platform for community discussion. Free, open, simple.
SECURITY: Fix staff action log context HTML escaping by invoking allowlist predicate (#45028)
Isaac Janzen6f7a16d338d2
diff --git a/frontend/discourse/admin/templates/admin-logs/staff-action-logs.gjs b/frontend/discourse/admin/templates/admin-logs/staff-action-logs.gjsindex eb28847c68d..17a60404f8b 100644--- a/frontend/discourse/admin/templates/admin-logs/staff-action-logs.gjs+++ b/frontend/discourse/admin/templates/admin-logs/staff-action-logs.gjs@@ -200,7 +200,7 @@ export default <template></div></td><td class="col value context">- {{#if (fn @controller.showHtmlSafeContext item)}}+ {{#if (@controller.showHtmlSafeContext item)}}{{trustHTML item.context}}{{else}}{{item.context}}diff --git a/spec/system/admin_staff_action_logs_spec.rb b/spec/system/admin_staff_action_logs_spec.rbindex 178e67477c1..4cace8948c6 100644--- a/spec/system/admin_staff_action_logs_spec.rb+++ b/spec/system/admin_staff_action_logs_spec.rb@@ -115,6 +115,42 @@ describe "Admin staff action logs" do)end+ it "keeps HTML submitted through self-deletion as context text" do+ attacker = Fabricate(:user, refresh_auto_groups: true)+ payload = %(<img src="https://attacker.invalid/staff-action-log-context">)++ sign_in(attacker)+ visit "/u/#{attacker.username}/preferences/account"++ status = page.evaluate_async_script(<<~JS, "/u/#{attacker.username}.json", payload)+ const [url, context, done] = arguments;+ fetch("/session/csrf.json")+ .then((response) => response.json())+ .then(({ csrf }) =>+ fetch(url, {+ body: JSON.stringify({ context }),+ credentials: "same-origin",+ headers: {+ "Content-Type": "application/json",+ "X-CSRF-Token": csrf,+ },+ method: "DELETE",+ })+ )+ .then((response) => done(response.status));+ JS++ expect(status).to eq(200)++ history = UserHistory.where(action: UserHistory.actions[:delete_user]).last++ sign_in(current_user)+ visit "/admin/logs/staff_action_logs"++ expect(staff_action_logs_page.log_row(history)).to have_no_css(".context img")+ expect(staff_action_logs_page.log_row(history)).to have_css(".context", text: payload)+ end+it "can filter by type of action" dovisit "/admin/logs/staff_action_logs"