From ba683bc611371b54c19356730225581cd4cceb8b Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Mon, 28 Apr 2014 14:43:49 -0400 Subject: [PATCH] FIX: XSS in markdown converter. --- app/assets/javascripts/discourse/dialects/dialect.js | 5 ++--- test/javascripts/lib/markdown_test.js | 2 ++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/discourse/dialects/dialect.js b/app/assets/javascripts/discourse/dialects/dialect.js index 6dfe71cfb..c3071ae35 100644 --- a/app/assets/javascripts/discourse/dialects/dialect.js +++ b/app/assets/javascripts/discourse/dialects/dialect.js @@ -42,7 +42,6 @@ function processTextNodes(node, event, emitter) { for (var j=1; j$/m.exec(n[1])) { + if (n && n.length === 2 && n[0] === "p" && /^$/.exec(n[1])) { // Remove paragraphs around comment-only nodes. tree[i] = n[1]; } else { diff --git a/test/javascripts/lib/markdown_test.js b/test/javascripts/lib/markdown_test.js index e46ebc946..87d891ae2 100644 --- a/test/javascripts/lib/markdown_test.js +++ b/test/javascripts/lib/markdown_test.js @@ -354,6 +354,8 @@ test("sanitize", function() { equal(sanitize("draw me!"), "draw me!"); cooked("[the answer](javascript:alert(42))", "

the answer

", "it prevents XSS"); + + cooked("\n", "


<!-- -->

", "it doesn't circumvent XSS with comments"); }); test("URLs in BBCode tags", function() {