Skip to content

Commit fe6d81c

Browse files
committed
Editor: Prevent adding javascript: and data: URLs through the inline link dialog.
Merge of [41393] to the 4.4 branch. git-svn-id: https://develop.svn.wordpress.org/branches/4.4@41404 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 70c05ee commit fe6d81c

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

src/wp-includes/js/tinymce/plugins/wplink/plugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
renderHtml: function() {
55
return (
66
'<div id="' + this._id + '" class="wp-link-preview">' +
7-
'<a href="' + this.url + '" target="_blank" tabindex="-1">' + this.url + '</a>' +
7+
'<a href="' + this.url + '" target="_blank" rel="noopener" tabindex="-1">' + this.url + '</a>' +
88
'</div>'
99
);
1010
},

src/wp-includes/js/wplink.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ var wpLink;
278278
var html = '<a href="' + attrs.href + '"';
279279

280280
if ( attrs.target ) {
281-
html += ' target="' + attrs.target + '"';
281+
html += ' rel="noopener" target="' + attrs.target + '"';
282282
}
283283

284284
return html + '>';
@@ -303,6 +303,13 @@ var wpLink;
303303
attrs = wpLink.getAttrs();
304304
text = inputs.text.val();
305305

306+
var parser = document.createElement( 'a' );
307+
parser.href = attrs.href;
308+
309+
if ( 'javascript:' === parser.protocol || 'data:' === parser.protocol ) { // jshint ignore:line
310+
attrs.href = '';
311+
}
312+
306313
// If there's no href, return.
307314
if ( ! attrs.href ) {
308315
return;
@@ -359,6 +366,13 @@ var wpLink;
359366
editor.selection.moveToBookmark( editor.windowManager.bookmark );
360367
}
361368

369+
var parser = document.createElement( 'a' );
370+
parser.href = attrs.href;
371+
372+
if ( 'javascript:' === parser.protocol || 'data:' === parser.protocol ) { // jshint ignore:line
373+
attrs.href = '';
374+
}
375+
362376
if ( ! attrs.href ) {
363377
editor.execCommand( 'unlink' );
364378
return;

0 commit comments

Comments
 (0)