Plugin Directory

Changeset 3406443


Ignore:
Timestamp:
12/01/2025 05:16:19 AM (11 months ago)
Author:
aravindajith
Message:

Version 2.7.11 , FIX: Enhanced sanitization of document embed attributes to prevent XSS.

Location:
embed-any-document
Files:
73 added
4 edited

Legend:

Unmodified
Added
Removed
  • embed-any-document/trunk/awsm-embed.php

    r3399946 r3406443  
    44 * Plugin URI: http://awsm.in/embed-any-documents
    55 * Description: Embed Any Document WordPress plugin lets you upload and embed your documents easily in your WordPress website without any additional browser plugins like Flash or Acrobat reader. The plugin lets you choose between Google Docs Viewer and Microsoft Office Online to display your documents.
    6  * Version: 2.7.10
     6 * Version: 2.7.11
    77 * Author: Awsm Innovations
    88 * Author URI: https://awsm.in
    … …  
    2020
    2121if ( ! defined( 'AWSM_EMBED_VERSION' ) ) {
    22         define( 'AWSM_EMBED_VERSION', '2.7.8' );
     22        define( 'AWSM_EMBED_VERSION', '2.7.11' );
    2323}
    2424
    … …  
    563563        }
    564564
     565        /**
     566         * Sanitizes the ead-document wrapper to remove unsafe attributes and prevent XSS.
     567         *
     568         * @param string $content The post content being filtered.
     569         * @return string The sanitized post content.
     570         */
    565571        public function sanitize_pdf_src( $content ) {
    566                 $pattern = '/(<div[^>]*class=["\']?ead-document[^>]*data-pdf-src=)(["\'])(.*?)\2([^>]*>)/i';
    567 
    568                 $content = preg_replace_callback(
     572                if ( stripos( $content, 'ead-document' ) === false ) {
     573                        return $content; }
     574
     575                // Match any <div> with class containing 'ead-document'.
     576                $pattern = '/(<div\b[^>]*?\bclass\s*=\s*["\'][^"\']*\bead-document\b[^"\']*["\'][^>]*>)/is';
     577
     578                return preg_replace_callback(
    569579                        $pattern,
    570                         function ( $matches ) {
    571                                 $prefix = $matches[1];
    572                                 $quote  = $matches[2];
    573                                 $src    = $matches[3];
    574                                 $suffix = $matches[4];
    575 
    576                                 if ( ! preg_match( '#^https?://#i', $src ) ) {
    577                                         $clean_src = '';
    578                                 } else {
    579                                         $clean_src = esc_url_raw( $src );
    580                                 }
    581 
    582                                 return $prefix . $quote . $clean_src . $quote . $suffix;
     580                        function( $matches ) {
     581                                $full_tag = $matches[1];
     582
     583                                // ---------------------------------------------------
     584                                // Remove on* js events (onclick, onload, onfocus, etc.)
     585                                // ---------------------------------------------------
     586                                $full_tag = preg_replace(
     587                                        '/\s+on\w+\s*=\s*(["\'])[^"\']*\1/i',
     588                                        '',
     589                                        $full_tag
     590                                );
     591
     592                                // ---------------------------------------------------
     593                                // Remove action / formaction
     594                                // ---------------------------------------------------
     595                                $full_tag = preg_replace(
     596                                        '/\s+(action|formaction)\s*=\s*(["\'])[^"\']*\2/i',
     597                                        '',
     598                                        $full_tag
     599                                );
     600
     601                                // ---------------------------------------------------
     602                                // Remove dangerous boolean attributes
     603                                // ---------------------------------------------------
     604                                $full_tag = preg_replace(
     605                                        '/\s+(autofocus|autoplay|formnovalidate)(?=\s|>|\/)/i',
     606                                        '',
     607                                        $full_tag
     608                                );
     609
     610                                // ---------------------------------------------------
     611                                // Remove tabindex that could be used with autofocus
     612                                // ---------------------------------------------------
     613                                $full_tag = preg_replace(
     614                                        '/\s+tabindex\s*=\s*(["\'])[^"\']*\1/i',
     615                                        '',
     616                                        $full_tag
     617                                );
     618
     619                                // ---------------------------------------------------
     620                                // Sanitize style=""
     621                                // ---------------------------------------------------
     622                                $full_tag = preg_replace_callback(
     623                                        '/\s+style\s*=\s*(["\'])([^"\']*)\1/i',
     624                                        function( $m ) {
     625                                                $clean_style = safecss_filter_attr( $m[2] );
     626                                                return $clean_style ? ' style="' . $clean_style . '"' : '';
     627                                        },
     628                                        $full_tag
     629                                );
     630
     631                                // ---------------------------------------------------
     632                                // Specifically sanitize data-pdf-src if present
     633                                // ---------------------------------------------------
     634                                $full_tag = preg_replace_callback(
     635                                        '/(\s+data-pdf-src\s*=\s*)(["\'])([^"\']*)\2/i',
     636                                        function( $m ) {
     637                                                $prefix = $m[1];
     638                                                $quote  = $m[2];
     639                                                $src    = $m[3];
     640
     641                                                // Only allow http/https URLs.
     642                                                if ( ! preg_match( '#^https?://#i', $src ) ) {
     643                                                        $clean_src = '';
     644                                                } else {
     645                                                        $clean_src = esc_url_raw( $src );
     646                                                }
     647
     648                                                return $prefix . $quote . $clean_src . $quote;
     649                                        },
     650                                        $full_tag
     651                                );
     652
     653                                // ---------------------------------------------------
     654                                // Remove any malformed attributes (like class="ead-document=a")
     655                                // ---------------------------------------------------
     656                                $full_tag = preg_replace_callback(
     657                                        '/\bclass\s*=\s*(["\'])([^"\']*=+[^"\']*)\1/i',
     658                                        function( $m ) {
     659                                                $quote = $m[1];
     660                                                // Keep only the part before any '=' character.
     661                                                $class_value = preg_replace( '/=.*$/', '', $m[2] );
     662                                                $class_value = trim( $class_value );
     663                                                return $class_value ? 'class=' . $quote . esc_attr( $class_value ) . $quote : '';
     664                                        },
     665                                        $full_tag
     666                                );
     667
     668                                return $full_tag;
    583669                        },
    584670                        $content
    585671                );
    586 
    587                 return $content;
    588672        }
    589673
  • embed-any-document/trunk/js/embed-public.js

    r3370262 r3406443  
    7171        });
    7272
    73     $(document).on('click', '.ead-reload-btn', function(e) {
     73    $(document).on('click', '.ead-reload-btn', function(e) { 
    7474        e.preventDefault();
    7575        var $wrapper = $(this).parents('.ead-document');
  • embed-any-document/trunk/language/embed-any-document.pot

    r3399946 r3406443  
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: Embed Any Document 2.7.7\n"
     5"Project-Id-Version: Embed Any Document 2.7.11\n"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/embed-any-document\n"
    77"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
    … …  
    1010"Content-Type: text/plain; charset=UTF-8\n"
    1111"Content-Transfer-Encoding: 8bit\n"
    12 "POT-Creation-Date: 2025-05-02T04:22:46+00:00\n"
     12"POT-Creation-Date: 2025-11-28T05:10:04+00:00\n"
    1313"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    1414"X-Generator: WP-CLI 2.6.0\n"
    … …  
    1616
    1717#. Plugin Name of the plugin
    18 #: awsm-embed.php:567
     18#: awsm-embed.php:678
    1919#: blocks/document/main.js:144
    2020msgid "Embed Any Document"
    … …  
    3737msgstr ""
    3838
    39 #: awsm-embed.php:145
     39#: awsm-embed.php:147
    4040#: inc/popup.php:18
    4141msgid "Add Document"
    4242msgstr ""
    4343
    44 #: awsm-embed.php:158
     44#: awsm-embed.php:160
    4545msgid "Settings"
    4646msgstr ""
    4747
    48 #: awsm-embed.php:197
    49 #: awsm-embed.php:405
     48#: awsm-embed.php:199
     49#: awsm-embed.php:407
    5050msgid "Download"
    5151msgstr ""
    5252
    53 #: awsm-embed.php:204
     53#: awsm-embed.php:206
    5454msgid "Nothing to insert"
    5555msgstr ""
    5656
    57 #: awsm-embed.php:205
     57#: awsm-embed.php:207
    5858msgid "Invalid URL"
    5959msgstr ""
    6060
    61 #: awsm-embed.php:206
     61#: awsm-embed.php:208
    6262#: inc/popup.php:39
    6363msgid "Add URL"
    6464msgstr ""
    6565
    66 #: awsm-embed.php:207
     66#: awsm-embed.php:209
    6767msgid "Verifying..."
    6868msgstr ""
    6969
    70 #: awsm-embed.php:208
     70#: awsm-embed.php:210
    7171msgid "From URL"
    7272msgstr ""
    7373
    74 #: awsm-embed.php:209
     74#: awsm-embed.php:211
    7575msgid "Select"
    7676msgstr ""
    7777
    78 #: awsm-embed.php:259
     78#: awsm-embed.php:261
    7979msgid "Loader"
    8080msgstr ""
    8181
    82 #: awsm-embed.php:260
     82#: awsm-embed.php:262
    8383#: inc/popup.php:117
    8484msgid "Loading..."
    8585msgstr ""
    8686
    87 #: awsm-embed.php:265
     87#: awsm-embed.php:267
    8888msgid "EAD Logo"
    8989msgstr ""
    9090
    91 #: awsm-embed.php:266
     91#: awsm-embed.php:268
    9292msgid "Taking too long?"
    9393msgstr ""
    9494
    95 #: awsm-embed.php:270
     95#: awsm-embed.php:272
    9696msgid "Reload"
    9797msgstr ""
    9898
    99 #: awsm-embed.php:270
     99#: awsm-embed.php:272
    100100msgid "Reload document"
    101101msgstr ""
    102102
    103 #: awsm-embed.php:274
     103#: awsm-embed.php:276
    104104msgid "Open"
    105105msgstr ""
    106106
    107 #: awsm-embed.php:274
     107#: awsm-embed.php:276
    108108msgid "Open in new tab"
    109109msgstr ""
    110110
    111 #: awsm-embed.php:347
     111#: awsm-embed.php:349
    112112#: blocks/document/modules/inspector.js:43
    113113msgid "Google Docs Viewer"
    114114msgstr ""
    115115
    116 #: awsm-embed.php:348
     116#: awsm-embed.php:350
    117117#: blocks/document/modules/inspector.js:51
    118118msgid "Browser Based"
    119119msgstr ""
    120120
    121 #: awsm-embed.php:349
     121#: awsm-embed.php:351
    122122#: blocks/document/modules/inspector.js:46
    123123msgid "Microsoft Office Online"
    124124msgstr ""
    125125
    126 #: awsm-embed.php:538
     126#: awsm-embed.php:540
    127127msgid "Embedded Document"
    128128msgstr ""
    129129
    130 #: awsm-embed.php:547
     130#: awsm-embed.php:549
    131131msgid "No Url Found"
    132132msgstr ""
    133133
    134 #: awsm-embed.php:623
     134#: awsm-embed.php:734
    135135msgid "The third party tools we are using to display your documents easily may use cookies or similar technologies for technical purposes.These third-party services may set their own cookies on your device to provide additional functionality or integrate certain features.The use of third-party cookies is subject to the respective third party privacy and cookie policies."
    136136msgstr ""
    137137
    138 #: awsm-embed.php:694
     138#: awsm-embed.php:805
    139139msgid "Unsupported file content detected. Sorry, you are not allowed to upload this file."
    140140msgstr ""
    141141
    142 #: awsm-embed.php:708
     142#: awsm-embed.php:819
    143143msgid "Buy Pro Version"
    144144msgstr ""
    145145
    146146#. translators: %1$s: Service provider
    147 #: awsm-embed.php:711
     147#: awsm-embed.php:822
    148148msgid "Add From %1$s"
    149149msgstr ""
  • embed-any-document/trunk/readme.txt

    r3399946 r3406443  
    44Author URI: http://awsm.in
    55Requires at least: 4.0
    6 Tested up to: 6.8.2
     6Tested up to: 6.8.3
    77Stable tag: trunk
    88License: GPLv2
    … …  
    114114== Changelog ==
    115115
     116= V 2.7.11 - 2025-11-28 =
     117* FIX: Enhanced sanitization of document embed attributes to prevent XSS.
     118* Code improvements.
     119
    116120= V 2.7.8 - 2025-09-30 =
    117121* FIX: Security vulnerability in PDF embed sanitized.
    118122
    119123= V 2.7.7 - 2025-05-02 =
    120 * Vulnerbility fix.
     124* Vulnerability fix.
    121125* Corrected load_plugin_textdomain() for compatibility with WP 6.8+.
    122126* Code improvements.
    … …  
    129133* Security fixes and code improvements.
    130134
    131 = V 2.7.4 - 2023-08-07 =
    132 * Added: Cookie Policy section.
    133 * Code improvements.
    134 
    135 = V 2.7.3 - 2023-07-12 =
    136 * Improved security.
    137 * Code improvements.
    138 
    139135[See changelog of previous versions](https://raw.githubusercontent.com/awsmin/Embed-Any-Documents/master/CHANGELOG.md)
    140136
    141137== Upgrade Notice ==
    142138
    143 = 2.7.6 =
    144 Improved security and code improvements.
     139= 2.7.11 =
     140Enhanced sanitization of document embed attributes to prevent XSS and code improvements.
    145141
Note: See TracChangeset for help on using the changeset viewer.