Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/photoblocks-grid-gallery/admin/class-photoblocks-admin.php
+++ b/photoblocks-grid-gallery/admin/class-photoblocks-admin.php
@@ -119,6 +119,15 @@
}
/**
+ * Capability required to manage galleries
+ *
+ * @since 1.3.9
+ */
+ public function capability() {
+ return apply_filters( 'photoblocks_capability', 'edit_others_posts' );
+ }
+
+ /**
* Save gallery
*
* @since 1.0.0
@@ -127,7 +136,7 @@
global $wpdb;
//error_reporting(E_ALL);
//ini_set('display_errors', 'On');
- if ( !current_user_can( 'edit_posts' ) ) {
+ if ( !current_user_can( $this->capability() ) ) {
exit( 0 );
}
if ( check_admin_referer( 'photoblocks', 'photoblocks' ) ) {
@@ -289,7 +298,7 @@
*/
public function init() {
global $wpdb;
- if ( !current_user_can( 'edit_posts' ) || !isset( $_GET['_wpnonce'] ) || !wp_verify_nonce( $_GET['_wpnonce'], 'photoblocks-action-valid' ) ) {
+ if ( !current_user_can( $this->capability() ) || !isset( $_GET['_wpnonce'] ) || !wp_verify_nonce( $_GET['_wpnonce'], 'photoblocks-action-valid' ) ) {
return;
}
if ( isset( $_GET['action'] ) ) {
@@ -443,7 +452,7 @@
$this->dashboard_page = add_menu_page(
'Dashboard - PhotoBlocks',
'PhotoBlocks',
- 'edit_posts',
+ $this->capability(),
$this->plugin_name,
array($this, 'dashboard'),
plugin_dir_url( __FILE__ ) . '/icon.png'
@@ -452,7 +461,7 @@
$this->plugin_name,
__( 'Add new', 'photoblocks' ) . ' - PhotoBlocks',
__( 'Add new', 'photoblocks' ),
- 'edit_posts',
+ $this->capability(),
$this->plugin_name . '-edit',
array($this, 'edit')
);
@@ -460,7 +469,7 @@
$this->plugin_name,
__( 'Troubleshooting', 'photoblocks' ) . ' - PhotoBlocks',
__( 'Troubleshooting', 'photoblocks' ),
- 'edit_posts',
+ $this->capability(),
$this->plugin_name . '-troubleshooting',
array($this, 'troubleshooting')
);
@@ -499,6 +508,10 @@
public function load_gallery() {
global $wpdb;
+ if ( !current_user_can( $this->capability() ) ) {
+ exit( 0 );
+ }
+ check_ajax_referer( 'photoblocks', 'photoblocks' );
$data = null;
if ( isset( $_POST['id'] ) && !empty( $_POST['id'] ) ) {
$data = $wpdb->get_row( $wpdb->prepare( 'SELECT * FROM ' . $wpdb->photoblocks . ' WHERE id=%d', intval( $_POST['id'] ) ), ARRAY_A );
--- a/photoblocks-grid-gallery/admin/partials/photoblocks-dashboard.php
+++ b/photoblocks-grid-gallery/admin/partials/photoblocks-dashboard.php
@@ -29,7 +29,7 @@
<?php echo esc_html( $g->name ); ?></a>
<div class="row-actions">
<span class="edit"><a href="<?php echo esc_url( $this->generate_admin_action_link( $g->id ) ); ?>" aria-label="Edit">Edit</a></span>
- <?php if( current_user_can( 'edit_posts' ) ): ?>
+ <?php if( current_user_can( $this->capability() ) ): ?>
<span class="clone"> | <a href="<?php echo esc_url( $this->generate_admin_action_link( $g->id , 'clone' ) ); ?>" data-id="<?php echo esc_attr( $g->id ); ?>" aria-label="Clone">Clone</a></span>
<span class="trash"> | <a href="<?php echo esc_url( $this->generate_admin_action_link( $g->id , 'delete' ) ); ?>" data-id="<?php echo esc_attr( $g->id ); ?>" class="submitdelete" aria-label="Delete">Delete</a></span>
<?php endif;?>
--- a/photoblocks-grid-gallery/includes/class-photoblock.php
+++ b/photoblocks-grid-gallery/includes/class-photoblock.php
@@ -238,6 +238,11 @@
}
}
+ // Lightboxes insert the decoded attribute as HTML, so entities must stay encoded after decoding.
+ public function get_lightbox_caption_attr() {
+ return htmlspecialchars( wp_kses_post( (string) $this->get_lightbox_caption() ), ENT_QUOTES, 'UTF-8' );
+ }
+
public function has_custom_overlay() {
return ! empty( $this->caption->background->color );
}
@@ -396,12 +401,12 @@
}
if ( $this->lightbox() == 'fancybox' ) {
- $attrs [] = 'data-fancybox="gallery-' . $this->gallery['id'] . '"';
- $attrs [] = 'data-thumb="' . $this->get_link() . '"';
+ $attrs [] = 'data-fancybox="gallery-' . absint( $this->gallery['id'] ) . '"';
+ $attrs [] = 'data-thumb="' . esc_url( (string) $this->get_link() ) . '"';
}
if ( $this->lightbox() == 'magnific' ) {
- $attrs [] = 'data-magnific="gallery-' . $this->gallery['id'] . '"';
+ $attrs [] = 'data-magnific="gallery-' . absint( $this->gallery['id'] ) . '"';
}
return implode( ' ', $attrs );
--- a/photoblocks-grid-gallery/photoblocks.php
+++ b/photoblocks-grid-gallery/photoblocks.php
@@ -4,7 +4,7 @@
* Plugin Name: Gallery PhotoBlocks
* Plugin URI: https://photoblocks.io/
* Description: Build your unique photo gallery
- * Version: 1.3.8
+ * Version: 1.3.9
* Author: WPChill
* Author URI: https://wpchill.com
* Requires: 5.2 or higher
@@ -15,7 +15,7 @@
* Domain Path: /languages
* Tested up to: 7.2
* Requires PHP: 5.6
- * Stable tag: 1.3.8
+ * Stable tag: 1.3.9
* Copyright 2018-2019 GreenTreeLabs diego@greentreelabs.net
* Copyright 2019-2020 MachoThemes office@machothemes.com
* SVN commit with proof of ownership transfer: https://plugins.trac.wordpress.org/changeset/2163480/photoblocks-grid-gallery
@@ -33,7 +33,7 @@
if ( !function_exists( 'photoblocks_starter' ) ) {
function photoblocks_starter() {
if ( !defined( 'PHOTOBLOCKS_V' ) ) {
- define( 'PHOTOBLOCKS_V', '1.3.8' );
+ define( 'PHOTOBLOCKS_V', '1.3.9' );
}
// If this file is called directly, abort.
if ( !defined( 'WPINC' ) ) {
--- a/photoblocks-grid-gallery/public/partials/photoblocks-public-display.php
+++ b/photoblocks-grid-gallery/public/partials/photoblocks-public-display.php
@@ -194,7 +194,7 @@
}
?>
pb-type-<?php
- echo $block->type;
+ echo esc_attr( $block->type );
?>
<?php
echo ( $block->type == "post" ? "pb-type-image" : "" );
@@ -206,16 +206,16 @@
<?php
?>
data-colspan="<?php
- echo $block->colspan();
+ echo absint( $block->colspan() );
?>"
data-rowspan="<?php
- echo $block->rowspan();
+ echo absint( $block->rowspan() );
?>"
data-col="<?php
- echo $block->col();
+ echo absint( $block->col() );
?>"
data-row="<?php
- echo $block->row();
+ echo absint( $block->row() );
?>"
<?php
if ( $block->type == "image" || $block->type == "post" ) {
@@ -230,10 +230,10 @@
}
?>
data-type="<?php
- echo $block->type;
+ echo esc_attr( $block->type );
?>"
data-ratio="<?php
- echo $block->ratio();
+ echo floatval( $block->ratio() );
?>">
<?php
@@ -245,13 +245,13 @@
?>"
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg=="
data-pb-source="<?php
- echo $block->get_image_url();
+ echo esc_url( (string) $block->get_image_url() );
?>"
alt="<?php
echo $block->get_alt();
?>">
<noscript><img src="<?php
- echo $block->image->url;
+ echo esc_url( (string) $block->image->url );
?>" alt="<?php
echo $block->get_alt();
?>"></noscript>
@@ -262,7 +262,7 @@
if ( $block->has_link_or_lightbox() ) {
?>
<a class="pb-link <?php
- echo $block->mfp_iframe_class();
+ echo esc_attr( $block->mfp_iframe_class() );
?>
<?php
echo esc_attr( $block->get_link_class() );
@@ -271,7 +271,7 @@
echo $block->get_lightbox_attrs();
?>
data-caption="<?php
- echo wp_kses_post( $block->get_lightbox_caption() );
+ echo $block->get_lightbox_caption_attr();
?>"
rel="<?php
echo esc_attr( $block->click->rel );
@@ -286,7 +286,7 @@
}
?>
href="<?php
- echo esc_attr( $block->get_link() );
+ echo esc_url( (string) $block->get_link() );
?>">
<?php
}
@@ -417,13 +417,13 @@
?>,
on: {
before: function () { <?php
-echo $gallery['custom_event_before'];
+echo ( isset( $gallery['custom_event_before'] ) ? $gallery['custom_event_before'] : '' );
?> },
after: function () { <?php
-echo $gallery['custom_event_after'];
+echo ( isset( $gallery['custom_event_after'] ) ? $gallery['custom_event_after'] : '' );
?> },
refresh: function () { <?php
-echo $gallery['custom_event_refresh'];
+echo ( isset( $gallery['custom_event_refresh'] ) ? $gallery['custom_event_refresh'] : '' );
?> }
},
<?php