@@ -316,5 +316,65 @@ public function testRules()
316316 );
317317 $ this ->assertFalse ($ this ->processor ->launch (false ));
318318 $ this ->alterPayload ();
319+
320+ // Determine if a POST parameter contains a shortcode with a bad attribute.
321+ // Import the WordPress functions.
322+ function get_shortcode_atts_regex () {
323+ return '/([\w-]+)\s*=\s*"([^"]*)"(?:\s|$)|([\w-]+)\s*=\s* \'([^ \']*) \'(?:\s|$)|([\w-]+)\s*=\s*([^\s \'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)| \'([^ \']*) \'(?:\s|$)|(\S+)(?:\s|$)/ ' ;
324+ }
325+
326+ function shortcode_parse_atts ( $ text ) {
327+ $ atts = array ();
328+ $ pattern = get_shortcode_atts_regex ();
329+ $ text = preg_replace ( "/[\x{00a0}\x{200b}]+/u " , ' ' , $ text );
330+ if ( preg_match_all ( $ pattern , $ text , $ match , PREG_SET_ORDER ) ) {
331+ foreach ( $ match as $ m ) {
332+ if ( ! empty ( $ m [1 ] ) ) {
333+ $ atts [ strtolower ( $ m [1 ] ) ] = stripcslashes ( $ m [2 ] );
334+ } elseif ( ! empty ( $ m [3 ] ) ) {
335+ $ atts [ strtolower ( $ m [3 ] ) ] = stripcslashes ( $ m [4 ] );
336+ } elseif ( ! empty ( $ m [5 ] ) ) {
337+ $ atts [ strtolower ( $ m [5 ] ) ] = stripcslashes ( $ m [6 ] );
338+ } elseif ( isset ( $ m [7 ] ) && strlen ( $ m [7 ] ) ) {
339+ $ atts [] = stripcslashes ( $ m [7 ] );
340+ } elseif ( isset ( $ m [8 ] ) && strlen ( $ m [8 ] ) ) {
341+ $ atts [] = stripcslashes ( $ m [8 ] );
342+ } elseif ( isset ( $ m [9 ] ) ) {
343+ $ atts [] = stripcslashes ( $ m [9 ] );
344+ }
345+ }
346+
347+ // Reject any unclosed HTML elements.
348+ foreach ( $ atts as &$ value ) {
349+ if ( false !== strpos ( $ value , '< ' ) ) {
350+ if ( 1 !== preg_match ( '/^[^<]*+(?:<[^>]*+>[^<]*+)*+$/ ' , $ value ) ) {
351+ $ value = '' ;
352+ }
353+ }
354+ }
355+ } else {
356+ $ atts = ltrim ( $ text );
357+ }
358+
359+ return $ atts ;
360+ }
361+
362+ $ this ->setUpFirewallProcessor ([$ this ->rules [20 ]]);
363+ $ this ->alterPayload (
364+ ['POST ' => [
365+ 'content ' => 'This is my post content and a shortcode with bad attribute value. [learn_press_featured_courses order_by="post_date" order="desc"] '
366+ ]]
367+ );
368+ $ this ->assertTrue ($ this ->processor ->launch (false ));
369+ $ this ->alterPayload ();
370+
371+ $ this ->setUpFirewallProcessor ([$ this ->rules [20 ]]);
372+ $ this ->alterPayload (
373+ ['POST ' => [
374+ 'content ' => 'This is my post content with a legitimate shortcode. [learn_press_featured_courses order_by="post_date" order=" \',(select sleep(10))"] '
375+ ]]
376+ );
377+ $ this ->assertFalse ($ this ->processor ->launch (false ));
378+ $ this ->alterPayload ();
319379 }
320380}
0 commit comments