From f72b21af23da6b6d54208e5c1d65ececdaa109c8 Mon Sep 17 00:00:00 2001
From: Nikolay Bachiyski <nb@nikolay.bg>
Date: Mon, 14 Sep 2015 22:47:23 +0000
Subject: [PATCH] Shortcodes: don't allow unclosed HTML elements in attributes

Merges [34134] for 4.3 branch

Built from https://develop.svn.wordpress.org/branches/4.3@34144


git-svn-id: http://core.svn.wordpress.org/branches/4.3@34112 1a063a9b-81f0-0310-95a4-ce76da25c4cd

v2: Backport to Wordpress 3.6.1, Mike Gabriel <mike.gabriel@das-netzwerkteam.de>
---
 wp-includes/media.php      | 2 ++
 wp-includes/shortcodes.php | 9 +++++++++
 2 files changed, 11 insertions(+)

--- a/wp-includes/media.php
+++ b/wp-includes/media.php
@@ -633,6 +633,8 @@
 			$content = $matches[1];
 			$attr['caption'] = trim( $matches[2] );
 		}
+	} elseif ( strpos( $attr['caption'], '<' ) !== false ) {
+			$attr['caption'] = wp_kses( $attr['caption'], 'post' );
 	}
 
 	// Allow plugins/themes to override the default caption template.
--- a/wp-includes/shortcodes.php
+++ b/wp-includes/shortcodes.php
@@ -458,6 +458,15 @@
 			elseif (isset($m[8]))
 				$atts[] = stripcslashes($m[8]);
 		}
+
+		// Reject any unclosed HTML elements
+		foreach( $atts as &$value ) {
+			if ( false !== strpos( $value, '<' ) ) {
+				if ( 1 !== preg_match( '/^[^<]*+(?:<[^>]*+>[^<]*+)*+$/', $value ) ) {
+					$value = '';
+				}
+			}
+		}
 	} else {
 		$atts = ltrim($text);
 	}
