Skip to content

Commit

Permalink
Update videopress shortcode sanitization (#37271)
Browse files Browse the repository at this point in the history
* sanitize preload setting in video blocks overridden by Jetpack

* changelog

* reduce size of diff

* escape attribute

---------

Co-authored-by: John Caruso <[email protected]>
  • Loading branch information
ice9js and jgcaruso committed May 7, 2024
1 parent 04c2977 commit 36695a2
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Sanitize the preload value for video shortcodes and blocks
2 changes: 1 addition & 1 deletion projects/packages/videopress/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-videopress",
"version": "0.23.19",
"version": "0.23.20-alpha",
"description": "VideoPress package",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/packages/videopress/#readme",
"bugs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,14 @@ public static function videopress_embed_shortcode( $atts ) {
}
}

if ( isset( $atts['preload'] ) ) {
if ( isset( $atts['preload'] ) && videopress_is_valid_preload( $atts['preload'] ) ) {
$atts['preloadcontent'] = $atts['preload'];
}

if ( isset( $atts['preloadcontent'] ) && ! videopress_is_valid_preload( $atts['preloadcontent'] ) ) {
unset( $atts['preloadcontent'] );
}

$atts = shortcode_atts( $defaults, $atts, 'videopress' );

$base_url = 'https://videopress.com/embed/' . $guid;
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/videopress/src/class-package-version.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* The Package_Version class.
*/
class Package_Version {
const PACKAGE_VERSION = '0.23.19';
const PACKAGE_VERSION = '0.23.20-alpha';

const PACKAGE_SLUG = 'videopress';

Expand Down
10 changes: 10 additions & 0 deletions projects/packages/videopress/src/utility-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ function videopress_is_valid_guid( $guid ) {
return false;
}

/**
* Validates user-supplied video preload setting.
*
* @param mixed $value the preload value to validate.
* @return bool
*/
function videopress_is_valid_preload( $value ) {
return in_array( strtolower( $value ), array( 'auto', 'metadata', 'none' ), true );
}

/**
* Get details about a specific video by GUID:
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

Sanitize the preload value for video shortcodes and blocks
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,16 @@ private function html5_static() {
wp_enqueue_script( 'videopress' );
$thumbnail = esc_url( $this->video->poster_frame_uri );
$html = "<video id=\"{$this->video_id}\" width=\"{$this->video->calculated_width}\" height=\"{$this->video->calculated_height}\" poster=\"$thumbnail\" controls=\"true\"";

$preload = 'metadata';
if ( isset( $this->options['preloadContent'] ) && videopress_is_valid_preload( $this->options['preloadContent'] ) ) {

Check failure on line 334 in projects/plugins/jetpack/modules/videopress/class.videopress-player.php

View workflow job for this annotation

GitHub Actions / Static analysis

UndefError PhanUndeclaredFunction Call to undeclared function \videopress_is_valid_preload()
$preload = $this->options['preloadContent'];
}

if ( isset( $this->options['autoplay'] ) && $this->options['autoplay'] === true ) {
$html .= ' autoplay="true"';
} else {
$html .= ' preload="' . $this->options['preloadContent'] . '"';
$html .= ' preload="' . esc_attr( $preload ) . '"';
}
if ( isset( $this->video->text_direction ) ) {
$html .= ' dir="' . esc_attr( $this->video->text_direction ) . '"';
Expand Down

0 comments on commit 36695a2

Please sign in to comment.