Index: /trunk/src/wp-includes/default-filters.php
===================================================================
--- /trunk/src/wp-includes/default-filters.php	(revision 42769)
+++ /trunk/src/wp-includes/default-filters.php	(revision 42770)
@@ -104,4 +104,19 @@
 	add_filter( $filter, 'balanceTags', 50 );
 }
+
+// Add proper rel values for links with target.
+foreach ( array(
+	'title_save_pre',
+	'content_save_pre',
+	'excerpt_save_pre',
+	'content_filtered_save_pre',
+	'pre_comment_content',
+	'pre_term_description',
+	'pre_link_description',
+	'pre_link_notes',
+	'pre_user_description',
+) as $filter ) {
+	add_filter( $filter, 'wp_targeted_link_rel' );
+};
 
 // Format strings for display.
Index: /trunk/src/wp-includes/formatting.php
===================================================================
--- /trunk/src/wp-includes/formatting.php	(revision 42769)
+++ /trunk/src/wp-includes/formatting.php	(revision 42770)
@@ -3025,4 +3025,67 @@
 
 /**
+ * Adds rel noreferrer and noopener to all HTML A elements that have a target.
+ *
+ * @param string $text Content that may contain HTML A elements.
+ * @return string Converted content.
+ */
+function wp_targeted_link_rel( $text ) {
+	// Don't run (more expensive) regex if no links with targets.
+	if ( stripos( $text, 'target' ) !== false && stripos( $text, '<a ' ) !== false ) {
+		$text = preg_replace_callback( '|<a\s([^>]*target\s*=[^>]*)>|i', 'wp_targeted_link_rel_callback', $text );
+	}
+
+	return $text;
+}
+
+/**
+ * Callback to add rel="noreferrer noopener" string to HTML A element.
+ *
+ * Will not duplicate existing noreferrer and noopener values
+ * to prevent from invalidating the HTML.
+ *
+ * @param array $matches Single Match
+ * @return string HTML A Element with rel noreferrer noopener in addition to any existing values
+ */
+function wp_targeted_link_rel_callback( $matches ) {
+	$link_html = $matches[1];
+	$rel_match = array();
+
+	/**
+	 * Filters the rel values that are added to links with `target` attribute.
+	 *
+	 * @since 5.0.0
+	 *
+	 * @param string The rel values.
+	 * @param string $link_html The matched content of the link tag including all HTML attributes.
+	 */
+	$rel = apply_filters( 'wp_targeted_link_rel', 'noopener noreferrer', $link_html );
+
+	// Value with delimiters, spaces around are optional.
+	$attr_regex = '|rel\s*=\s*?(\\\\{0,1}["\'])(.*?)\\1|i';
+	preg_match( $attr_regex, $link_html, $rel_match );
+
+	if ( empty( $rel_match[0] ) ) {
+		// No delimiters, try with a single value and spaces, because `rel =  va"lue` is totally fine...
+		$attr_regex = '|rel\s*=(\s*)([^\s]*)|i';
+		preg_match( $attr_regex, $link_html, $rel_match );
+	}
+
+	if ( ! empty( $rel_match[0] ) ) {
+		$parts = preg_split( '|\s+|', strtolower( $rel_match[2] ) );
+		$parts = array_map( 'esc_attr', $parts );
+		$needed = explode( ' ', $rel );
+		$parts = array_unique( array_merge( $parts, $needed ) );
+		$delimiter = trim( $rel_match[1] ) ? $rel_match[1] : '"';
+		$rel = 'rel=' . $delimiter . trim( implode( ' ', $parts ) ) . $delimiter;
+		$link_html = str_replace( $rel_match[0], $rel, $link_html );
+	} else {
+		$link_html .= " rel=\"$rel\"";
+	}
+
+	return "<a $link_html>";
+}
+
+/**
  * Convert one smiley code to the icon graphic file equivalent.
  *
Index: /trunk/tests/phpunit/tests/formatting/WPTargetedLinkRel.php
===================================================================
--- /trunk/tests/phpunit/tests/formatting/WPTargetedLinkRel.php	(revision 42770)
+++ /trunk/tests/phpunit/tests/formatting/WPTargetedLinkRel.php	(revision 42770)
@@ -0,0 +1,74 @@
+<?php
+
+/**
+ * @group formatting
+ * @ticket 43187
+ */
+class Tests_Targeted_Link_Rel extends WP_UnitTestCase {
+
+	public function test_add_to_links_with_target_blank() {
+		$content  = '<p>Links: <a href="/" target="_blank">No rel</a></p>';
+		$expected = '<p>Links: <a href="/" target="_blank" rel="noopener noreferrer">No rel</a></p>';
+		$this->assertEquals( $expected, wp_targeted_link_rel( $content ) );
+	}
+
+	public function test_add_to_links_with_target_foo() {
+		$content  = '<p>Links: <a href="/" target="foo">No rel</a></p>';
+		$expected = '<p>Links: <a href="/" target="foo" rel="noopener noreferrer">No rel</a></p>';
+		$this->assertEquals( $expected, wp_targeted_link_rel( $content ) );
+	}
+
+	public function test_target_as_first_attribute() {
+		$content  = '<p>Links: <a target="_blank" href="#">No rel</a></p>';
+		$expected = '<p>Links: <a target="_blank" href="#" rel="noopener noreferrer">No rel</a></p>';
+		$this->assertEquals( $expected, wp_targeted_link_rel( $content ) );
+	}
+
+	public function test_add_to_existing_rel() {
+		$content  = '<p>Links: <a href="/" rel="existing values" target="_blank">Existing rel</a></p>';
+		$expected = '<p>Links: <a href="/" rel="existing values noopener noreferrer" target="_blank">Existing rel</a></p>';
+		$this->assertEquals( $expected, wp_targeted_link_rel( $content ) );
+	}
+
+	public function test_no_duplicate_values_added() {
+		$content  = '<p>Links: <a href="/" rel="existing noopener values" target="_blank">Existing rel</a></p>';
+		$expected = '<p>Links: <a href="/" rel="existing noopener values noreferrer" target="_blank">Existing rel</a></p>';
+		$this->assertEquals( $expected, wp_targeted_link_rel( $content ) );
+	}
+
+	public function test_rel_with_single_quote_delimiter() {
+		$content  = '<p>Links: <a href="/" rel=\'existing values\' target="_blank">Existing rel</a></p>';
+		$expected = '<p>Links: <a href="/" rel=\'existing values noopener noreferrer\' target="_blank">Existing rel</a></p>';
+		$this->assertEquals( $expected, wp_targeted_link_rel( $content ) );
+	}
+
+	public function test_rel_with_no_delimiter() {
+		$content  = '<p>Links: <a href="/" rel=existing target="_blank">Existing rel</a></p>';
+		$expected = '<p>Links: <a href="/" rel="existing noopener noreferrer" target="_blank">Existing rel</a></p>';
+		$this->assertEquals( $expected, wp_targeted_link_rel( $content ) );
+	}
+
+	public function test_rel_value_spaced_and_no_delimiter() {
+		$content  = '<p>Links: <a href="/" rel = existing target="_blank">Existing rel</a></p>';
+		$expected = '<p>Links: <a href="/" rel="existing noopener noreferrer" target="_blank">Existing rel</a></p>';
+		$this->assertEquals( $expected, wp_targeted_link_rel( $content ) );
+	}
+
+	public function test_rel_value_spaced_and_no_delimiter_and_values_to_escape() {
+		$content  = '<p>Links: <a href="/" rel = existing"value target="_blank">Existing rel</a></p>';
+		$expected = '<p>Links: <a href="/" rel="existing&quot;value noopener noreferrer" target="_blank">Existing rel</a></p>';
+		$this->assertEquals( $expected, wp_targeted_link_rel( $content ) );
+	}
+
+	public function test_escaped_quotes() {
+		$content  = '<p>Links: <a href=\"/\" rel=\"existing values\" target=\"_blank\">Existing rel</a></p>';
+		$expected = '<p>Links: <a href=\"/\" rel=\"existing values noopener noreferrer\" target=\"_blank\">Existing rel</a></p>';
+		$this->assertEquals( $expected, wp_targeted_link_rel( $content ) );
+	}
+
+	public function test_ignore_links_with_no_target() {
+		$content  = '<p>Links: <a href="/" target="_blank">Change me</a> <a href="/">Do not change me</a></p>';
+		$expected = '<p>Links: <a href="/" target="_blank" rel="noopener noreferrer">Change me</a> <a href="/">Do not change me</a></p>';
+		$this->assertEquals( $expected, wp_targeted_link_rel( $content ) );
+	}
+}
Index: /trunk/tests/phpunit/tests/rest-api/rest-attachments-controller.php
===================================================================
--- /trunk/tests/phpunit/tests/rest-api/rest-attachments-controller.php	(revision 42769)
+++ /trunk/tests/phpunit/tests/rest-api/rest-attachments-controller.php	(revision 42770)
@@ -1016,10 +1016,10 @@
 					),
 					'description' => array(
-						'raw'      => '<a href="#" target="_blank">link</a>',
-						'rendered' => '<p><a href="#" target="_blank">link</a></p>',
+						'raw'      => '<a href="#" target="_blank" rel="noopener noreferrer">link</a>',
+						'rendered' => '<p><a href="#" target="_blank" rel="noopener noreferrer">link</a></p>',
 					),
 					'caption'     => array(
-						'raw'      => '<a href="#" target="_blank">link</a>',
-						'rendered' => '<p><a href="#" target="_blank">link</a></p>',
+						'raw'      => '<a href="#" target="_blank" rel="noopener noreferrer">link</a>',
+						'rendered' => '<p><a href="#" target="_blank" rel="noopener noreferrer">link</a></p>',
 					),
 				),
Index: /trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php
===================================================================
--- /trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php	(revision 42769)
+++ /trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php	(revision 42770)
@@ -3186,10 +3186,10 @@
 					),
 					'content' => array(
-						'raw'      => '<a href="#" target="_blank">link</a>',
-						'rendered' => '<p><a href="#" target="_blank">link</a></p>',
+						'raw'      => '<a href="#" target="_blank" rel="noopener noreferrer">link</a>',
+						'rendered' => '<p><a href="#" target="_blank" rel="noopener noreferrer">link</a></p>',
 					),
 					'excerpt' => array(
-						'raw'      => '<a href="#" target="_blank">link</a>',
-						'rendered' => '<p><a href="#" target="_blank">link</a></p>',
+						'raw'      => '<a href="#" target="_blank" rel="noopener noreferrer">link</a>',
+						'rendered' => '<p><a href="#" target="_blank" rel="noopener noreferrer">link</a></p>',
 					),
 				),
