A platform for community discussion. Free, open, simple.
FIX: allowed href scheme link can start with a + (#5537)
Maja Komel330912e1e5cf
diff --git a/app/assets/javascripts/pretty-text/sanitizer.js.es6 b/app/assets/javascripts/pretty-text/sanitizer.js.es6index 512e3328465..3729dfa6e9a 100644--- a/app/assets/javascripts/pretty-text/sanitizer.js.es6+++ b/app/assets/javascripts/pretty-text/sanitizer.js.es6@@ -73,6 +73,9 @@ export function sanitize(text, whiteLister) {if (allowedHrefSchemes && allowedHrefSchemes.length > 0) {extraHrefMatchers = [new RegExp('^(' + allowedHrefSchemes.join('|') + '):\/\/[\\w\\.\\-]+','i')];+ if (allowedHrefSchemes.includes('tel')) {+ extraHrefMatchers.push(new RegExp('^tel:\/\/\\+?[\\w\\.\\-]+','i'));+ }}let result = xss(text, {diff --git a/spec/components/pretty_text_spec.rb b/spec/components/pretty_text_spec.rbindex 918056cc42f..6e0ee7e0458 100644--- a/spec/components/pretty_text_spec.rb+++ b/spec/components/pretty_text_spec.rb@@ -811,6 +811,17 @@ describe PrettyText doexpect(cooked).to eq(n expected)end+ it 'allows only tel URL scheme to start with a plus character' do+ SiteSetting.allowed_href_schemes = "tel|steam"+ cooked = cook("[Tel URL Scheme](tel://+452530579785)")+ expected = '<p><a href="tel://+452530579785" rel="nofollow noopener">Tel URL Scheme</a></p>'+ expect(cooked).to eq(n expected)++ cooked2 = cook("[Steam URL Scheme](steam://+store/452530)")+ expected2 = '<p><a>Steam URL Scheme</a></p>'+ expect(cooked2).to eq(n expected2)+ end+it "produces hashtag links" docategory = Fabricate(:category, name: 'testing')category2 = Fabricate(:category, name: 'known')