Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop adding “noreferrer” to external links. #26968

Open
wants to merge 13 commits into
base: trunk
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const LINK_DESTINATION_NONE = 'none';
const LINK_DESTINATION_CUSTOM = 'custom';
const LINK_DESTINATION_MEDIA = 'media';
const LINK_DESTINATION_ATTACHMENT = 'attachment';
const NEW_TAB_REL = [ 'noreferrer', 'noopener' ];
const NEW_TAB_REL = [ 'noopener' ];

const icon = (
<SVG viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/button/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { createBlock } from '@wordpress/blocks';
import ColorEdit from './color-edit';
import getColorAndStyleProps from './color-props';

const NEW_TAB_REL = 'noreferrer noopener';
const NEW_TAB_REL = 'noopener';
const MIN_BORDER_RADIUS_VALUE = 0;
const MAX_BORDER_RADIUS_VALUE = 50;
const INITIAL_BORDER_RADIUS_POSITION = 5;
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/categories/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default function CategoriesEdit( {
const { id, link, count, name } = category;
return (
<li key={ id }>
<a href={ link } target="_blank" rel="noreferrer noopener">
<a href={ link } target="_blank" rel="noopener">
{ renderCategoryName( name ) }
</a>
{ showPostCounts && (
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/file/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function save( { attributes } ) {
<a
href={ textLinkHref }
target={ textLinkTarget }
rel={ textLinkTarget ? 'noreferrer noopener' : false }
rel={ textLinkTarget ? 'noopener' : false }
>
<RichText.Content value={ fileName } />
</a>
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/image/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ export const LINK_DESTINATION_NONE = 'none';
export const LINK_DESTINATION_MEDIA = 'media';
export const LINK_DESTINATION_ATTACHMENT = 'attachment';
export const LINK_DESTINATION_CUSTOM = 'custom';
export const NEW_TAB_REL = [ 'noreferrer', 'noopener' ];
export const NEW_TAB_REL = [ 'noopener' ];
export const ALLOWED_MEDIA_TYPES = [ 'image' ];
export const DEFAULT_SIZE_SLUG = 'large';
6 changes: 3 additions & 3 deletions packages/block-library/src/latest-posts/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ export default function LatestPostsEdit( { attributes, setAttributes } ) {
<a
href={ post.link }
target="_blank"
rel="noopener noreferrer"
rel="noopener"
>
{ __( 'Read more' ) }
</a>
Expand All @@ -530,7 +530,7 @@ export default function LatestPostsEdit( { attributes, setAttributes } ) {
<a
href={ post.link }
target="_blank"
rel="noreferrer noopener"
rel="noopener"
>
{ featuredImage }
</a>
Expand All @@ -542,7 +542,7 @@ export default function LatestPostsEdit( { attributes, setAttributes } ) {
<a
href={ post.link }
target="_blank"
rel="noreferrer noopener"
rel="noopener"
>
{ titleTrimmed ? (
<RawHTML>{ titleTrimmed }</RawHTML>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default function phrasingContentReducer( node, doc ) {
// In jsdom-jscore, 'node.target' can be null.
// TODO: Explore fixing this by patching jsdom-jscore.
if ( node.target && node.target.toLowerCase() === '_blank' ) {
node.rel = 'noreferrer noopener';
node.rel = 'noopener';
} else {
node.removeAttribute( 'target' );
node.removeAttribute( 'rel' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe( 'phrasingContentReducer', () => {
const input =
'<a href="https://wordpress.org" target="_blank">WordPress</a>';
const output =
'<a href="https://wordpress.org" target="_blank" rel="noreferrer noopener">WordPress</a>';
'<a href="https://wordpress.org" target="_blank" rel="noopener">WordPress</a>';
expect(
deepFilterHTML( input, [ phrasingContentReducer ], {} )
).toEqual( output );
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/external-link/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function ExternalLink(
ref
) {
rel = uniq(
compact( [ ...rel.split( ' ' ), 'external', 'noreferrer', 'noopener' ] )
compact( [ ...rel.split( ' ' ), 'external', 'noopener' ] )
).join( ' ' );
const classes = classnames( 'components-external-link', className );
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import LinkRelIcon from './link-rel';

import styles from './style.scss';

const NEW_TAB_REL = 'noreferrer noopener';
const NEW_TAB_REL = 'noopener';

function LinkSettings( {
// Control link settings `BottomSheet` visibility
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export function MoreExamplesStory() {
className="navigation-story__wordpress-icon"
href="https://wordpress.org/"
target="_blank"
rel="noreferrer"
rel="noopener"
>
<Icon icon={ wordpress } />
<em>Custom Content</em>
Expand Down
526 changes: 263 additions & 263 deletions packages/e2e-tests/assets/large-post.html

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<!-- wp:file {"href":"http://localhost:8888/wp-content/uploads/2018/05/keycodes.js","showDownloadButton":true} -->
<div class="wp-block-file"><a href="http://localhost:8888/wp-content/uploads/2018/05/keycodes.js" target="_blank" rel="noreferrer noopener">6546</a><a href="http://localhost:8888/wp-content/uploads/2018/05/keycodes.js" class="wp-block-file__button" download>Download</a></div>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a deprecation is needed, the practice here is to keep the old markup in a fixture called packages/e2e-tests/fixtures/blocks/core__file__deprecated-1.html which will add test coverage ensuring the deprecation works. The new fixture can be added as well alongside it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, will do.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @talldan - finally getting back to this :)

Since there is now already a core__file__new-window__deprecated-1.html I assume I need to create core__file__new-window__deprecated-2.html? do I then leave the original and first deprecation untouched?

<div class="wp-block-file"><a href="http://localhost:8888/wp-content/uploads/2018/05/keycodes.js" target="_blank" rel="noopener">6546</a><a href="http://localhost:8888/wp-content/uploads/2018/05/keycodes.js" class="wp-block-file__button" download>Download</a></div>
<!-- /wp:file -->
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"downloadButtonText": "Download"
},
"innerBlocks": [],
"originalContent": "<div class=\"wp-block-file\"><a href=\"http://localhost:8888/wp-content/uploads/2018/05/keycodes.js\" target=\"_blank\" rel=\"noreferrer noopener\">6546</a><a href=\"http://localhost:8888/wp-content/uploads/2018/05/keycodes.js\" class=\"wp-block-file__button\" download>Download</a></div>"
"originalContent": "<div class=\"wp-block-file\"><a href=\"http://localhost:8888/wp-content/uploads/2018/05/keycodes.js\" target=\"_blank\" rel=\"noopener\">6546</a><a href=\"http://localhost:8888/wp-content/uploads/2018/05/keycodes.js\" class=\"wp-block-file__button\" download>Download</a></div>"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"showDownloadButton": true
},
"innerBlocks": [],
"innerHTML": "\n<div class=\"wp-block-file\"><a href=\"http://localhost:8888/wp-content/uploads/2018/05/keycodes.js\" target=\"_blank\" rel=\"noreferrer noopener\">6546</a><a href=\"http://localhost:8888/wp-content/uploads/2018/05/keycodes.js\" class=\"wp-block-file__button\" download>Download</a></div>\n",
"innerHTML": "\n<div class=\"wp-block-file\"><a href=\"http://localhost:8888/wp-content/uploads/2018/05/keycodes.js\" target=\"_blank\" rel=\"noopener\">6546</a><a href=\"http://localhost:8888/wp-content/uploads/2018/05/keycodes.js\" class=\"wp-block-file__button\" download>Download</a></div>\n",
"innerContent": [
"\n<div class=\"wp-block-file\"><a href=\"http://localhost:8888/wp-content/uploads/2018/05/keycodes.js\" target=\"_blank\" rel=\"noreferrer noopener\">6546</a><a href=\"http://localhost:8888/wp-content/uploads/2018/05/keycodes.js\" class=\"wp-block-file__button\" download>Download</a></div>\n"
"\n<div class=\"wp-block-file\"><a href=\"http://localhost:8888/wp-content/uploads/2018/05/keycodes.js\" target=\"_blank\" rel=\"noopener\">6546</a><a href=\"http://localhost:8888/wp-content/uploads/2018/05/keycodes.js\" class=\"wp-block-file__button\" download>Download</a></div>\n"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<!-- wp:file {"href":"http://localhost:8888/wp-content/uploads/2018/05/keycodes.js"} -->
<div class="wp-block-file"><a href="http://localhost:8888/wp-content/uploads/2018/05/keycodes.js" target="_blank" rel="noreferrer noopener">6546</a><a href="http://localhost:8888/wp-content/uploads/2018/05/keycodes.js" class="wp-block-file__button" download>Download</a></div>
<div class="wp-block-file"><a href="http://localhost:8888/wp-content/uploads/2018/05/keycodes.js" target="_blank" rel="noopener">6546</a><a href="http://localhost:8888/wp-content/uploads/2018/05/keycodes.js" class="wp-block-file__button" download>Download</a></div>
<!-- /wp:file -->
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ exports[`Links can be created by selecting text and using keyboard shortcuts 1`]

exports[`Links can be created by selecting text and using keyboard shortcuts 2`] = `
"<!-- wp:paragraph -->
<p>This is <a href=\\"https://wordpress.org/gutenberg\\" target=\\"_blank\\" rel=\\"noreferrer noopener\\">Gutenberg</a></p>
<p>This is <a href=\\"https://wordpress.org/gutenberg\\" target=\\"_blank\\" rel=\\"noopener\\">Gutenberg</a></p>
<!-- /wp:paragraph -->"
`;

Expand Down Expand Up @@ -62,7 +62,7 @@ exports[`Links can be removed 1`] = `

exports[`Links should contain a label when it should open in a new tab 1`] = `
"<!-- wp:paragraph -->
<p>This is <a href=\\"http://w.org\\" target=\\"_blank\\" rel=\\"noreferrer noopener\\">WordPress</a></p>
<p>This is <a href=\\"http://w.org\\" target=\\"_blank\\" rel=\\"noopener\\">WordPress</a></p>
<!-- /wp:paragraph -->"
`;

Expand Down
2 changes: 1 addition & 1 deletion packages/edit-post/src/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ registerPlugin( 'edit-post', {
'https://wordpress.org/support/article/wordpress-editor/'
) }
target="_blank"
rel="noopener noreferrer"
rel="noopener"
>
{ __( 'Help' ) }
<VisuallyHidden as="span">
Expand Down
2 changes: 1 addition & 1 deletion packages/format-library/src/link/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export function createLinkFormat( { url, type, id, opensInNewWindow } ) {

if ( opensInNewWindow ) {
format.attributes.target = '_blank';
format.attributes.rel = 'noreferrer noopener';
format.attributes.rel = 'noopener';
}

return format;
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-editor/src/initial-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default `
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p><strong>Bold</strong> <em>Italic</em> <s>Striked</s> Superscript<sup>(1)</sup> Subscript<sub>(2)</sub> <a href="http://www.wordpress.org" target="_blank" rel="noreferrer noopener">Link</a></p>
<p><strong>Bold</strong> <em>Italic</em> <s>Striked</s> Superscript<sup>(1)</sup> Subscript<sub>(2)</sub> <a href="http://www.wordpress.org" target="_blank" rel="noopener">Link</a></p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":4} -->
Expand Down