Plugin Directory

Changeset 3261089


Ignore:
Timestamp:
03/24/2025 08:16:12 PM (12 months ago)
Author:
redpixelstudios
Message:
  • Update sanitization handling of submitted shortcode attribute values.
  • Sanitize output of more text to prevent potential code injection.
  • Bump version.
Location:
rps-include-content/tags/1.2.2
Files:
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • rps-include-content/tags/1.2.2/readme.txt

    r3130091 r3261089  
    44Tags: duplicate content, copy content, include, include content, includes, multisite, nested content, pull content, red pixel, red pixel studios, redpixelstudios, rps, same content
    55Requires at least: 5.0
    6 Tested up to: 6.6.1
    7 Stable tag: 1.2.1
     6Tested up to: 6.7.2
     7Stable tag: 1.2.2
    88License: GPL3
    99
     
    154154== Upgrade Notice ==
    155155
     156= 1.2.2 =
     157* Update sanitization handling of submitted shortcode attribute values.
     158* Sanitize output of more text to prevent potential code injection.
     159
    156160= 1.2.1 =
    157161* Silenced a couple of notices related to variables being undefined.
  • rps-include-content/tags/1.2.2/rps-include-content.php

    r3130093 r3261089  
    44Plugin URI: http://redpixel.com/
    55Description: Adds the ability to include content on the current post or page from another.
    6 Version: 1.2.1
     6Version: 1.2.2
    77Author: Red Pixel Studios
    88Author URI: http://redpixel.com/
     
    3232 * @package rps-include-content
    3333 * @author Red Pixel Studios
    34  * @version 1.2.1
     34 * @version 1.2.2
    3535 */
    3636 
     
    4545     * @since 1.0
    4646     */
    47     const PLUGIN_VERSION = '1.2.1';
     47    const PLUGIN_VERSION = '1.2.2';
    4848   
    4949    /**
     
    129129    }
    130130
     131    /**
     132     * Helper to sanitize boolean shortcode values.
     133     *
     134     * @since 1.2.2
     135     */
     136    private static function sanitize_bool_attr( $val, $default = false ) {
     137        $bool = filter_var( $val, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE );
     138        return is_null( $bool ) ? $default : $bool;
     139    }
     140
     141    /**
     142     * Sanitize a value and fallback to a default if it's not in the allowed list.
     143     *
     144     * @since 1.2.2
     145     *
     146     * @param string   $value       The input value.
     147     * @param callable $sanitize_cb A sanitization callback (e.g., 'sanitize_key', 'sanitize_html_class').
     148     * @param array    $allowed     Array of allowed values.
     149     * @param mixed    $default     Fallback value if input is not allowed.
     150     * @return mixed
     151     */
     152    private static function sanitize_enum_attr( $value, $sanitize_cb, array $allowed, $default ) {
     153        $sanitized = call_user_func( $sanitize_cb, $value );
     154        return in_array( $sanitized, $allowed, true ) ? $sanitized : $default;
     155    }
     156
    131157    public function cb_include_shortcode( $atts, $content = null ) {
    132158        global $shortcode_tags;
    133        
    134         // specify allowed values for shortcode attributes
    135         $allowed_titletag = array(
    136             'h1',
    137             'h2',
    138             'h3',
    139             'h4',
    140             'h5',
    141             'h6'
    142         );
    143 
    144         $allowed_content = array(
    145             'content',
    146             'excerpt',
    147             'lede',
    148             'full',
    149             'none'
    150         );
    151        
     159               
    152160        $current_blog_id = get_current_blog_id();
    153161       
     
    180188        extract( shortcode_atts( $defaults, $atts ) );
    181189       
    182         // convert string values to lowercase and trim
    183         $title = trim( strtolower( $title ) );
    184         $titletag = trim( strtolower( $titletag ) );
    185         $content = trim( strtolower( $content ) );
    186         $allow_shortcodes = trim( strtolower( $allow_shortcodes ) );
    187         $allow_shortcodes_array = ( ! empty( $allow_shortcodes ) ) ? explode( ',', $allow_shortcodes ) : array();
    188         $allow_shortcodes_array = array_map( 'trim', $allow_shortcodes_array );
    189 
    190         // type cast strings as necessary
     190        //sanitize shortcode atts
    191191        $blog = absint( $blog );
    192192        $post = absint( $post );
    193193        $page = absint( $page );
    194         $title = ( $title == 'true' ) ? true : false;
    195         $titlelink = ( $titlelink == 'true' ) ? true : false;
    196         $filter = ( $filter == 'true' ) ? true : false;
    197         $embeds = ( $embeds == 'true' ) ? true : false;
    198         $shortcodes = ( $shortcodes == 'true' ) ? true : false;
    199         $length = ( $length == '0' || $length == '' ) ? 55 : absint( $length );
    200         $hover = ( $hover == 'true' ) ? true : false;
    201         $private = ( $private == 'true' ) ? true : false;
    202         $featured_image = ( $featured_image == 'true' ) ? true : false;
    203         $featured_image_wrap = ( $featured_image_wrap == 'true' ) ? true : false;
    204        
     194        $title = self::sanitize_bool_attr( $title );
     195        $titletag = self::sanitize_enum_attr( $titletag, 'sanitize_html_class', ['h1','h2','h3','h4','h5','h6'], $defaults['titletag'] );
     196        $titlelink = self::sanitize_bool_attr( $titlelink );
     197        $content = self::sanitize_enum_attr( $content, 'sanitize_key', ['content', 'excerpt', 'lede', 'full', 'none'], $defaults['content'] );
     198        $filter = self::sanitize_bool_attr( $filter );
     199        $shortcodes = self::sanitize_bool_attr( $shortcodes );
     200        $embeds = self::sanitize_bool_attr( $embeds );
     201        $more_text = sanitize_text_field( $more_text );
     202        $length = absint( $length );
     203        if ( $length <= 0 ) {
     204            $length = $defaults['length'];
     205        }       
     206        $allow_shortcodes_array = ! empty( $allow_shortcodes )
     207            ? array_map( 'trim', explode( ',', strtolower( sanitize_text_field( $allow_shortcodes ) ) ) )
     208            : array();
     209        $hover = self::sanitize_bool_attr( $hover );
     210        $private = self::sanitize_bool_attr( $private );
     211        $featured_image = self::sanitize_bool_attr( $featured_image );
     212        $featured_image_size = sanitize_key( $featured_image_size );
     213        $featured_image_wrap = self::sanitize_bool_attr( $featured_image_wrap );
     214        $featured_image_wrap_class = sanitize_html_class( $featured_image_wrap_class, '' );
     215
    205216        // handle if page attribute used instead of post
    206217        $post = ( $post === 0 && $page !== 0 ) ? $page : $post;
    207 
    208         // test for allowed values and sanitize as necessary
    209         if ( !in_array( $titletag, $allowed_titletag ) ) $titletag = $defaults['titletag'];
    210         if ( !in_array( $content, $allowed_content ) ) $content = $defaults['content'];
    211         $featured_image_size = sanitize_text_field( $featured_image_size );
    212         $featured_image_wrap_class = sanitize_html_class( $featured_image_wrap_class, '' );
    213 
    214218        if ( $post === 0 )
    215219            return $this->error_msg( __( 'Post must be a non-zero integer.', 'rps-include-content' ), $hover );
     
    221225        endif;
    222226       
    223 
    224227        $the_post = ( is_multisite() ) ? get_blog_post( $blog, $post ) : get_post( $post );
    225228
     
    299302        endif;
    300303       
    301         $more_link = '<p class="more-link-container"><a href="'. $the_permalink .'#more-' . $the_post->ID . '" class="more-link">' . $more_text . '</a></p>';
     304        $more_link = '<p class="more-link-container"><a href="'. $the_permalink .'#more-' . $the_post->ID . '" class="more-link">' . esc_html( $more_text ) . '</a></p>';
    302305       
    303306        /**
Note: See TracChangeset for help on using the changeset viewer.