Skip to content

Fixed XSS vulnerability report via Gallery shortcode - #8

Merged
PGeorgiev merged 4 commits into
masterfrom
xss-shortcode
May 29, 2026
Merged

Fixed XSS vulnerability report via Gallery shortcode#8
PGeorgiev merged 4 commits into
masterfrom
xss-shortcode

Conversation

@PGeorgiev

Copy link
Copy Markdown
Contributor

Asana task [Easy Image Gallery: Closure Notice - Security: Easy Image Gallery]

  • Security: Escape gallery IDs in lightbox HTML attributes (fancybox, prettyPhoto, luminous) to prevent stored XSS via shortcode or post meta.
  • Security: Sanitize gallery IDs on save and in the [easy_image_gallery] shortcode.
  • Tested up with WordPress 7.0 beta versions

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a reported stored XSS vector by ensuring gallery/shortcode IDs are sanitized (digits-only) and safely escaped before being used in lightbox-related HTML attributes and selectors, and when saved/consumed via the [easy_image_gallery] shortcode.

Changes:

  • Added easy_image_gallery_sanitize_gallery_id() and applied it across shortcode parsing and gallery ID comparisons.
  • Escaped lightbox grouping attributes (prettyPhoto/fancybox/luminous) and tightened URL escaping in gallery output.
  • Bumped plugin version/readme stable tag and added a 1.5.5 security changelog entry.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
readme.txt Updates stable tag and adds 1.5.5 security changelog notes.
includes/template-functions.php Adds gallery ID sanitization + uses it for lightbox attributes/selectors and shortcode handling.
includes/metabox.php Sanitizes gallery SHORTCODE values in the metabox UI and on save.
easy-image-gallery.php Bumps plugin header version to 1.5.5.
Comments suppressed due to low confidence (1)

includes/metabox.php:425

  • When sanitizing SHORTCODE on save, the fallback to wp_rand( 100, 999 ) risks collisions because the range is small. A collision could make two galleries share an ID, breaking shortcode targeting and lightbox grouping. Consider generating a larger/unique numeric ID and ensuring it does not duplicate any existing SHORTCODE values in $galleries for this post before saving.
			if ( isset( $gallery['SHORTCODE'] ) ) {
				$gallery['SHORTCODE'] = easy_image_gallery_sanitize_gallery_id( $gallery['SHORTCODE'] );
				if ( '' === $gallery['SHORTCODE'] ) {
					$gallery['SHORTCODE'] = (string) wp_rand( 100, 999 );
				}
			}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread includes/template-functions.php Outdated
Comment on lines +443 to +450
if ( $gallery_id == 'old_db' ) {
$gallery_id = easy_image_gallery_sanitize_gallery_id( $gallery['SHORTCODE'] );
} else {
$gallery_id = easy_image_gallery_sanitize_gallery_id( $gallery_id );
}

if ( '' === $gallery_id ) {
continue;
Comment thread includes/metabox.php

@metodiew metodiew left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PGeorgiev Copilot suggestions make sense, let's update them and we'll run one more review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

Comment thread includes/template-functions.php Outdated
Comment thread includes/template-functions.php
Comment thread readme.txt
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@PGeorgiev
PGeorgiev merged commit b2a37ca into master May 29, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants