From 607ba4aca7530b71c8df59398cb2ef5a97aa5e12 Mon Sep 17 00:00:00 2001 From: Felix Scheinost Date: Mon, 30 Oct 2017 20:07:03 +0100 Subject: [PATCH 1/2] remove youtube iframes by default as well; add option to still allow them --- index.js | 3 ++- lib/render.js | 6 +++++- lib/sanitize.js | 4 +++- test/sanitize.js | 7 ++++++- test/youtube.js | 2 +- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 19de0f0..984b677 100644 --- a/index.js +++ b/index.js @@ -14,7 +14,8 @@ var defaultOptions = { debug: false, package: null, headingAnchorClass: 'anchor', - headingSvgClass: ['octicon', 'octicon-link'] + headingSvgClass: ['octicon', 'octicon-link'], + allowDeprecatedYoutubeEmbeds: false } var marky = module.exports = function (markdown, options) { diff --git a/lib/render.js b/lib/render.js index 2ff03a3..9daca3c 100644 --- a/lib/render.js +++ b/lib/render.js @@ -81,7 +81,6 @@ render.getParser = function (options) { .use(relaxedLinkRefs) .use(gravatar) .use(github, {package: options.package}) - .use(youtube) .use(packagize, {package: options.package}) .use(htmlHeading) .use(overrideLinkDestinationParser) @@ -92,8 +91,13 @@ render.getParser = function (options) { parser.use(codeWrap) .use(fenceLanguageAliasing) } + if (options.serveImagesWithCDN) parser.use(cdnImages, {package: options.package}) + if (options.allowDeprecatedYoutubeEmbeds) { + parser.use(youtube) + } + return githubLinkify(parser) } diff --git a/lib/sanitize.js b/lib/sanitize.js index d3587cc..dc7d74c 100644 --- a/lib/sanitize.js +++ b/lib/sanitize.js @@ -93,7 +93,9 @@ function getSanitizerConfig (options) { // Allow YouTube iframes if (frame.tag !== 'iframe') return false - return !String(frame.attribs.src).match(/^(https?:)?\/\/(www\.)?youtube\.com/) + + var isYouTube = String(frame.attribs.src).match(/^(https?:)?\/\/(www\.)?youtube\.com/) + return !(isYouTube && options.allowDeprecatedYoutubeEmbeds) }, transformTags: { 'td': sanitizeCellStyle, diff --git a/test/sanitize.js b/test/sanitize.js index 21dc137..56b0007 100644 --- a/test/sanitize.js +++ b/test/sanitize.js @@ -58,10 +58,15 @@ describe('sanitize', function () { assert.equal($('s').text(), 'orange') }) - it('disallows iframes from sources other than youtube', function () { + it('disallows all iframes by default', function () { var $ = cheerio.load(marky(fixtures.basic)) assert(~fixtures.basic.indexOf('