From f5cca1c43cad41db52f898e65457ae62a8f1436b Mon Sep 17 00:00:00 2001 From: Aigars Silkalns Date: Tue, 1 Dec 2026 15:04:07 +0200 Subject: [PATCH 1/6] Decode raw-JavaScript settings the same way on every PHP version PHP 8.1 changed html_entity_decode()'s default flags from ENT_COMPAT to ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, so on PHP 7.4 and 8.0 an apostrophe stored as ' in a custom expression, extra call or callback stayed encoded and broke the script. The new flags are passed explicitly through mfbfw_decode_js(), which matches what PHP 8.1+ sites already do. Co-Authored-By: Claude Opus 5.5 --- fancybox.php | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/fancybox.php b/fancybox.php index 059dc7a..4a580aa 100644 --- a/fancybox.php +++ b/fancybox.php @@ -455,6 +455,23 @@ function mfbfw_is_enabled() { return (bool) apply_filters( 'mfbfw_is_enabled', $enabled ); } +/** + * Decodes a stored raw-JavaScript setting for output. + * + * The flags are PHP 8.1's defaults, passed explicitly. Before 8.1 the default was + * ENT_COMPAT, which left `'` undecoded, so a custom script containing an + * apostrophe stored as an entity broke on PHP 7.4 and 8.0 while working on 8.1+. + * + * @since 3.4.5 + * + * @param string $js Stored setting value. + * @return string + */ +function mfbfw_decode_js( $js ) { + + return html_entity_decode( (string) $js, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, 'UTF-8' ); +} + /** * Path suffix for minified assets, unless SCRIPT_DEBUG asks for readable sources. * @@ -798,7 +815,7 @@ function mfbfw_gallery_js( array $s ) { JS; case 'custom': - return "\t/* Custom Expression */\n\t" . html_entity_decode( $s['customExpression'] ); + return "\t/* Custom Expression */\n\t" . mfbfw_decode_js( $s['customExpression'] ); case 'all': default: @@ -857,14 +874,14 @@ function mfbfw_build_options( array $s ) { $callback = static function ( $key ) use ( $s, $callbacks_on ) { if ( $callbacks_on && ! empty( $s[ $key ] ) ) { - return html_entity_decode( $s[ $key ] ); + return mfbfw_decode_js( $s[ $key ] ); } return 'function () {}'; }; if ( $callbacks_on && ! empty( $s['callbackOnComplete'] ) ) { - $after_show = html_entity_decode( $s['callbackOnComplete'] ); + $after_show = mfbfw_decode_js( $s['callbackOnComplete'] ); } elseif ( mfbfw_is_on( 'zoomOnClick', $s ) ) { /* * Namespaced and rebound each time, otherwise every slide stacked another @@ -946,7 +963,7 @@ function mfbfw_build_inline_js( array $s ) { : ''; $extra_calls = ( mfbfw_is_on( 'extraCallsEnable', $s ) && ! empty( $s['extraCallsData'] ) ) - ? "\t\t/* Extra Calls */\n\t\t" . html_entity_decode( $s['extraCallsData'] ) . "\n" + ? "\t\t/* Extra Calls */\n\t\t" . mfbfw_decode_js( $s['extraCallsData'] ) . "\n" : ''; // strtr() makes a single pass, so administrator-supplied code that happens to From f4843e101c105a2e3c92af19c947f13908b8c157 Mon Sep 17 00:00:00 2001 From: Aigars Silkalns Date: Tue, 1 Dec 2026 15:04:07 +0200 Subject: [PATCH 2/6] Update DOMPurify to 3.5.0 Security fixes for SAFE_FOR_TEMPLATES, IN_PLACE and custom elements; 3.4.x is no longer maintained. The behaviour changes affect DOM input, hooks and IN_PLACE, none of which the lightbox uses: it only sanitizes strings. Both dist files come from the registry tarball (sha512 verified) with their sourceMappingURL comments removed. Co-Authored-By: Claude Opus 5.5 --- CLAUDE.md | 2 +- assets/js/purify.js | 639 ++++++++++++++++++++++------------------ assets/js/purify.min.js | 6 +- 3 files changed, 358 insertions(+), 289 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 7e8fe13..0f0bbce 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -139,7 +139,7 @@ Field markup follows a consistent pattern — an `.epsilon-toggle` block for boo Releases 3.3.4 – 3.4.0 were dominated by security fixes. The risky code is structural: -- **Caption/title XSS.** DOMPurify (currently **3.4.17**, bundled) is a hard dependency of the `fancybox-for-wp` script handle. The generated `caption`, `afterLoad` and title-copy JS all route user HTML through `jQuery.fancyboxforwp.sanitize()`, which applies the `elementHtmlRules` allow-list and falls back to `jQuery("
").text(x).html()`. Do not go back to DOMPurify's plain `html` profile: it keeps `