A platform for community discussion. Free, open, simple.
FIX: skip iframe URLs with relative paths in pretty text sanitizer. (#21714)
Vinoth Kannanded6ea66a5f2
diff --git a/app/assets/javascripts/pretty-text/addon/sanitizer.js b/app/assets/javascripts/pretty-text/addon/sanitizer.jsindex 0800dd41ae5..d765b8889de 100644--- a/app/assets/javascripts/pretty-text/addon/sanitizer.js+++ b/app/assets/javascripts/pretty-text/addon/sanitizer.js@@ -127,6 +127,7 @@ export function sanitize(text, allowLister) {hrefAllowed(value, extraHrefMatchers)) ||(tag === "iframe" &&name === "src" &&+ !value.match(/\/\.+\//) &&allowedIframes.some((i) => {return value.toLowerCase().startsWith((i || "").toLowerCase());}))diff --git a/spec/lib/pretty_text_spec.rb b/spec/lib/pretty_text_spec.rbindex d64cd9a2a11..3dc294aca2d 100644--- a/spec/lib/pretty_text_spec.rb+++ b/spec/lib/pretty_text_spec.rb@@ -2367,6 +2367,21 @@ HTMLexpect(cooked).to eq(html.strip)end+ it "can skip relative paths in allowlist iframes" do+ SiteSetting.allowed_iframes = "https://bob.com/abc/def"+ raw = <<~HTML+ <iframe src='https://bob.com/abc/def'></iframe>+ <iframe src='https://bob.com/abc/def/../ghi'></iframe>+ <iframe src='https://bob.com/abc/def/ghi/../../jkl'></iframe>+ HTML++ html = <<~HTML+ <iframe src="https://bob.com/abc/def"></iframe>+ HTML++ expect(PrettyText.cook(raw).strip).to eq(html.strip)+ end+it "You can disable linkify" domd = "www.cnn.com test.it http://test.com https://test.ab https://a"cooked = PrettyText.cook(md)