Skip to content

Commit

Permalink
Editor: Prevent adding javascript: and data: URLs through the inl…
Browse files Browse the repository at this point in the history
…ine link dialog.

Built from https://develop.svn.wordpress.org/trunk@41393


git-svn-id: http://core.svn.wordpress.org/trunk@41226 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
ocean90 committed Sep 19, 2017
1 parent f6a26be commit c2ead9d
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 5 deletions.
9 changes: 8 additions & 1 deletion wp-includes/js/tinymce/plugins/wplink/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
renderHtml: function() {
return (
'<div id="' + this._id + '" class="wp-link-preview">' +
'<a href="' + this.url + '" target="_blank" tabindex="-1">' + this.url + '</a>' +
'<a href="' + this.url + '" target="_blank" rel="noopener" tabindex="-1">' + this.url + '</a>' +
'</div>'
);
},
Expand Down Expand Up @@ -249,6 +249,13 @@
text = inputInstance.getLinkText();
editor.focus();

var parser = document.createElement( 'a' );
parser.href = href;

if ( 'javascript:' === parser.protocol || 'data:' === parser.protocol ) { // jshint ignore:line
href = '';
}

if ( ! href ) {
editor.dom.remove( linkNode, true );
return;
Expand Down
2 changes: 1 addition & 1 deletion wp-includes/js/tinymce/plugins/wplink/plugin.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified wp-includes/js/tinymce/wp-tinymce.js.gz
Binary file not shown.
16 changes: 15 additions & 1 deletion wp-includes/js/wplink.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ var wpLink;
var html = '<a href="' + attrs.href + '"';

if ( attrs.target ) {
html += ' target="' + attrs.target + '"';
html += ' rel="noopener" target="' + attrs.target + '"';
}

return html + '>';
Expand All @@ -337,6 +337,13 @@ var wpLink;
attrs = wpLink.getAttrs();
text = inputs.text.val();

var parser = document.createElement( 'a' );
parser.href = attrs.href;

if ( 'javascript:' === parser.protocol || 'data:' === parser.protocol ) { // jshint ignore:line
attrs.href = '';
}

// If there's no href, return.
if ( ! attrs.href ) {
return;
Expand Down Expand Up @@ -390,6 +397,13 @@ var wpLink;
var attrs = wpLink.getAttrs(),
$link, text, hasText, $mceCaret;

var parser = document.createElement( 'a' );
parser.href = attrs.href;

if ( 'javascript:' === parser.protocol || 'data:' === parser.protocol ) { // jshint ignore:line
attrs.href = '';
}

if ( ! attrs.href ) {
editor.execCommand( 'unlink' );
wpLink.close();
Expand Down
Loading

0 comments on commit c2ead9d

Please sign in to comment.