From 1cd281f0643ef613dc1d36847d4c6cbb22501d91 Mon Sep 17 00:00:00 2001 From: Jammerware Date: Sat, 2 Nov 2019 14:58:07 -0400 Subject: [PATCH] fix(openLinksInNewWindow): add rel="noopener noreferrer" to links Add rel="noreferrer" to links when openLinksInNewWindow is on. Also add noopener when openLinksInNewWindow is on. target="_blank" without also adding rel="noopener noreferrer" creates a vulnerability (since the site you're linking to has access to the window.opener by default. This adds rel="noopener noreferrer" to links generated by the makeHtml converter when openLinksInNewWindow is true. Closes #670 --- dist/showdown.js | Bin 159266 -> 159344 bytes dist/showdown.js.map | Bin 450238 -> 450427 bytes dist/showdown.min.js | Bin 75596 -> 75674 bytes dist/showdown.min.js.map | Bin 86981 -> 86981 bytes src/subParsers/anchors.js | 4 ++-- src/subParsers/autoLinks.js | 2 +- ...penLinksInNewWindow-breaks-em-markdup.html | 4 ++-- .../openLinksInNewWindow/simple-cases.html | 4 ++-- .../features/openLinksInNewWindow/simple.html | 4 ++-- .../simplifiedAutoLink.html | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/dist/showdown.js b/dist/showdown.js index bf3bc44c18f0d5b424a8757e6df104b83877f4f7..a7c15ff69898757e99b368ba2de30e4a34356687 100644 GIT binary patch delta 121 zcmZ24p}@Elf3r(;p-8BVoY3<50pqwUm(lEKkXp1$Yg;9 zoZJ0un6x?2Ok*sVe*83(!sL5NoRb|gxlv6MnI7;LXe8V;0aqsF=?a^f;T8x_R+z!k zKEag4p}@Elf3rlMn1h ObYjM>Vzc8K?rH#|4=ZQ@ delta 28 mcmV+%0OS9f&jifQ1hDp{vk<290+SG?7qc{}LIbmqtO|S4qYYjF diff --git a/dist/showdown.min.js.map b/dist/showdown.min.js.map index e20c108286a1479a24bea5084eb3645df8f51998..07f509c7b69fb7829405923afef55e041317d0ad 100644 GIT binary patch delta 33 kcmX@Qob~8()(u)GnX+9r>zw?`2%?owi!gy`%dzw?`2%?owi!gy`%d'; @@ -87,7 +87,7 @@ showdown.subParser('anchors', function (text, options, globals) { var lnk = options.ghMentionsLink.replace(/\{u}/g, username), target = ''; if (options.openLinksInNewWindow) { - target = ' target="¨E95Eblank"'; + target = ' rel="noopener noreferrer" target="¨E95Eblank"'; } return st + '' + mentions + ''; }); diff --git a/src/subParsers/autoLinks.js b/src/subParsers/autoLinks.js index f75e97e..fa49b52 100644 --- a/src/subParsers/autoLinks.js +++ b/src/subParsers/autoLinks.js @@ -22,7 +22,7 @@ var simpleURLRegex = /([*~_]+|\b)(((https?|ftp|dict):\/\/|www\.)[^'">\s]+?\.[^' append = trailingPunctuation; } if (options.openLinksInNewWindow) { - target = ' target="¨E95Eblank"'; + target = ' rel="noopener noreferrer" target="¨E95Eblank"'; } return lmc + '' + lnkTxt + '' + append + tmc; }; diff --git a/test/features/#379.openLinksInNewWindow-breaks-em-markdup.html b/test/features/#379.openLinksInNewWindow-breaks-em-markdup.html index ab837e3..9d22dee 100644 --- a/test/features/#379.openLinksInNewWindow-breaks-em-markdup.html +++ b/test/features/#379.openLinksInNewWindow-breaks-em-markdup.html @@ -1,2 +1,2 @@ -

My link is important

-

My link is important

+

My link is important

+

My link is important

diff --git a/test/features/openLinksInNewWindow/simple-cases.html b/test/features/openLinksInNewWindow/simple-cases.html index c62a155..f20e2af 100644 --- a/test/features/openLinksInNewWindow/simple-cases.html +++ b/test/features/openLinksInNewWindow/simple-cases.html @@ -1,2 +1,2 @@ -

foo

-

a link http://www.google.com

+

foo

+

a link http://www.google.com

diff --git a/test/features/openLinksInNewWindow/simple.html b/test/features/openLinksInNewWindow/simple.html index c62a155..f20e2af 100644 --- a/test/features/openLinksInNewWindow/simple.html +++ b/test/features/openLinksInNewWindow/simple.html @@ -1,2 +1,2 @@ -

foo

-

a link http://www.google.com

+

foo

+

a link http://www.google.com

diff --git a/test/features/openLinksInNewWindow/simplifiedAutoLink.html b/test/features/openLinksInNewWindow/simplifiedAutoLink.html index c23bf68..6dff350 100644 --- a/test/features/openLinksInNewWindow/simplifiedAutoLink.html +++ b/test/features/openLinksInNewWindow/simplifiedAutoLink.html @@ -1 +1 @@ -

this is http://www.google.com autolink

+

this is http://www.google.com autolink