Skip to content

Commit fdd2c84

Browse files
authored
Merge pull request #458 from cloudinary/fix/insecure-replacements
check if is synced
2 parents 8c4137e + 36cf974 commit fdd2c84

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

php/class-delivery.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Cloudinary\Component\Setup;
1111
use Cloudinary\Media\Filter;
1212
use Cloudinary\Media\Global_Transformations;
13+
use Cloudinary\Sync;
1314
use Cloudinary\String_Replace;
1415
use Cloudinary\UI\Component\HTML;
1516
use WP_Post;
@@ -40,6 +41,13 @@ class Delivery implements Setup {
4041
*/
4142
protected $filter;
4243

44+
/**
45+
* Holds the Sync component.
46+
*
47+
* @var Sync
48+
*/
49+
protected $sync;
50+
4351
/**
4452
* Hold the Post ID.
4553
*
@@ -118,6 +126,8 @@ public function get_current_post_id() {
118126
*/
119127
public function setup() {
120128
$this->filter = $this->media->filter;
129+
$this->sync = $this->media->sync;
130+
121131
// Add filters.
122132
add_action( 'save_post', array( $this, 'remove_replace_cache' ) );
123133
add_action( 'cloudinary_string_replace', array( $this, 'catch_urls' ) );
@@ -218,7 +228,9 @@ public function find_attachment_size_urls( $urls ) {
218228
$results = $wpdb->get_results( $sql ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared
219229
if ( $results ) {
220230
foreach ( $results as $result ) {
221-
$found = array_merge( $found, $this->get_attachment_size_urls( $result->post_id ) );
231+
if ( $this->sync->is_synced( $result->post_id ) ) {
232+
$found = array_merge( $found, $this->get_attachment_size_urls( $result->post_id ) );
233+
}
222234
}
223235
}
224236
$cached = $found;
@@ -251,7 +263,7 @@ public function convert_tags( $content ) {
251263
$attachment_id = $this->filter->get_id_from_tag( $element );
252264
$this->current_post_id = $this->filter->get_id_from_tag( $element, 'wp-post-' );
253265

254-
if ( empty( $attachment_id ) ) {
266+
if ( empty( $attachment_id ) || ! $this->sync->is_synced( $attachment_id ) ) {
255267
continue;
256268
}
257269
// Register replacement.

0 commit comments

Comments
 (0)