Plugin Directory

Changeset 3356450


Ignore:
Timestamp:
09/05/2025 05:45:58 AM (6 months ago)
Author:
intelchip
Message:

Addressed security concerns raised after closure of plugin

Location:
osm-map-elementor/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • osm-map-elementor/trunk/constants.php

    r3107495 r3356450  
    22define('OSM_MAP_SLUG', 'osm-map-elementor');
    33define('OSM_PLUGIN_FOLDER', basename(__DIR__) != 'trunk' ? basename(__DIR__) : OSM_MAP_SLUG);
    4 define('OSM_MAP_VERSION', '1.3.0');
     4define('OSM_MAP_VERSION', '1.3.1');
  • osm-map-elementor/trunk/osm-map-elementor.php

    r3107495 r3356450  
    55 * Author:          Plugin Contributors
    66 * Author URI:      https://github.com/flopperj/osm-map-elementor/graphs/contributors
    7  * Version:         1.3.0
     7 * Version:         1.3.1
    88 */
    99
     
    3535
    3636        // queue admin styles
    37         wp_register_style('osm-map-admin', plugins_url('/' . OSM_PLUGIN_FOLDER . '/assets/css/admin.css'));
     37        wp_register_style('osm-map-admin', plugins_url('/' . OSM_PLUGIN_FOLDER . '/assets/css/admin.css'), [], OSM_MAP_VERSION);
    3838        wp_enqueue_style('osm-map-admin');
    3939
     
    4141
    4242        // grab settings, sanitize, validate and save them
    43         if (!empty($action) && $action == 'save_settings' && isset($_REQUEST['osm_widget']) && is_array($_REQUEST['osm_widget'])) {
    44 
     43        if (!empty($action) && $action == 'save_settings' && isset($_REQUEST['osm_widget']) && is_array($_REQUEST['osm_widget']) && wp_verify_nonce($_REQUEST['osm_settings_nonce'], 'osm_settings_action')) {
    4544            $input = isset($_REQUEST['osm_widget']) ? $_REQUEST['osm_widget'] : [];
    4645
     
    6059
    6160            // redirect to form with confirmation alert message
    62             wp_redirect($_SERVER['HTTP_REFERER'] . '&action=settings_saved');
     61            $redirect_url = admin_url('options-general.php');
     62            wp_redirect(add_query_arg([
     63                'page' => 'osm-map-elementor',
     64                'action' => 'settings_saved',
     65            ], $redirect_url));
    6366        }
    6467
     
    7073            <?php if (!empty($_REQUEST['action']) && sanitize_key($_REQUEST['action']) == 'settings_saved'): ?>
    7174                <div style="background-color: rgb(255, 251, 204);" id="alert-message" class="updated"><p>
    72                         <strong><?php echo __('Settings saved') ?>.</strong></p></div>
     75                        <strong><?php echo esc_html(__('Settings saved')) ?>.</strong></p></div>
    7376            <?php endif; ?>
    74             <form action="<?php echo $_SERVER['REQUEST_URI'] . '&action=save_settings'; ?>" method="post">
     77            <form action="<?php
     78            $form_action_url = admin_url('options-general.php');
     79            echo esc_url(add_query_arg([
     80                'page' => 'osm-map-elementor',
     81                'action' => 'save_settings',
     82            ], $form_action_url));
     83            ?>" method="post">
     84                <?php wp_nonce_field('osm_settings_action', 'osm_settings_nonce'); ?>
    7585                <div class="form-group">
    7686                    <div class="card">
     
    189199add_action('init', function () {
    190200    add_filter('wp_enqueue_scripts', function () {
    191         wp_enqueue_script('jquery', false, [], false, false);
     201        wp_enqueue_script('jquery', false, [], OSM_MAP_VERSION, false);
    192202    }, 1);
    193203}, 1);
  • osm-map-elementor/trunk/osm-map.php

    r3107495 r3356450  
    261261                'type' => Controls_Manager::SELECT,
    262262                'options' => [
    263                         '_self' => 'Same Window',
    264                         '_blank' => 'New Window/Tab'
     263                    '_self' => 'Same Window',
     264                    '_blank' => 'New Window/Tab'
    265265                ],
    266266                'default' => '_blank',
     
    10591059            ]
    10601060        );
    1061        
     1061
    10621062        $this->add_control(
    10631063            'title_color',
     
    14461446        $settings['breakpoints'] = \Elementor\Plugin::$instance->breakpoints->get_breakpoints();
    14471447
    1448         if (0 === absint($settings['zoom']['size'])) {
     1448        // Ensure zoom settings exist and have proper defaults
     1449        if (!isset($settings['zoom']) || !is_array($settings['zoom'])) {
     1450            $settings['zoom'] = ['size' => 10];
     1451        } elseif (!isset($settings['zoom']['size']) || 0 === absint($settings['zoom']['size'])) {
    14491452            $settings['zoom']['size'] = 10;
    14501453        }
    14511454
    1452         if (0 === absint($settings['height']['size'])) {
     1455        // Ensure height settings exist and have proper defaults
     1456        if (!isset($settings['height']) || !is_array($settings['height'])) {
     1457            $settings['height'] = ['size' => 200];
     1458        } elseif (!isset($settings['height']['size']) || 0 === absint($settings['height']['size'])) {
    14531459            $settings['height']['size'] = 200;
    14541460        }
     
    14561462        // get all marker coords to help calculate center
    14571463        $coords = [];
    1458         foreach ($markers as $marker) {
    1459 
    1460             // hide markers that have been toggled off
    1461             if (isset($marker['marker_visible']) && empty($marker['marker_visible'])) {
    1462                 continue;
    1463             }
    1464 
    1465             $loc = explode(',', $marker['marker_coords']);
    1466             if (!empty($loc) && sizeof($loc) == 2) {
    1467                 $coords[] = [
    1468                     'marker' => $marker,
    1469                     'lat' => $loc[0],
    1470                     'lng' => $loc[1]
    1471                 ];
     1464        if (is_array($markers)) {
     1465            foreach ($markers as $marker) {
     1466
     1467                // hide markers that have been toggled off
     1468                if (isset($marker['marker_visible']) && empty($marker['marker_visible'])) {
     1469                    continue;
     1470                }
     1471
     1472                $loc = explode(',', $marker['marker_coords']);
     1473                if (!empty($loc) && sizeof($loc) == 2) {
     1474                    $coords[] = [
     1475                        'marker' => $marker,
     1476                        'lat' => $loc[0],
     1477                        'lng' => $loc[1]
     1478                    ];
     1479                }
    14721480            }
    14731481        }
     
    14781486        echo '<div id="' . esc_attr('osm-map-' . $this->get_id()) . '"
    14791487        class="osm-map-container"
    1480         data-center="' . implode(',', $center_coords) . '"></div>';
     1488        data-center="' . esc_attr(implode(',', $center_coords)) . '"></div>';
    14811489
    14821490        ?>
     
    14891497                "use strict";
    14901498                const displaySettings = <?php echo wp_json_encode($settings); ?>;
    1491                 const mapId = '<?php echo 'osm-map-' . $this->get_id(); ?>';
     1499                const mapId = '<?php echo esc_js('osm-map-' . $this->get_id()); ?>';
    14921500                const mapContainer = jQuery('#' + mapId);
    14931501                const center = mapContainer.data('center');
     1502
     1503                // Security: HTML escaping functions to prevent XSS
     1504                const escapeHtml = function (text) {
     1505                    if (!text) return '';
     1506                    const map = {
     1507                        '&': '&amp;',
     1508                        '<': '&lt;',
     1509                        '>': '&gt;',
     1510                        '"': '&quot;',
     1511                        "'": '&#039;'
     1512                    };
     1513                    return text.toString().replace(/[&<>"']/g, function (m) {
     1514                        return map[m];
     1515                    });
     1516                };
     1517
     1518                // Security: URL escaping function to prevent XSS in href attributes
     1519                const escapeUrl = function (url) {
     1520                    if (!url) return '#';
     1521                    // Basic URL validation and escaping
     1522                    try {
     1523                        // If it's a valid URL, return it
     1524                        new URL(url);
     1525                        return url;
     1526                    } catch (e) {
     1527                        // If not a valid URL, escape it and return as javascript:void(0)
     1528                        return 'javascript:void(0)';
     1529                    }
     1530                };
    14941531                const hasDesktopZoomLevel = displaySettings && displaySettings.hasOwnProperty('zoom') && displaySettings.zoom && displaySettings.zoom.hasOwnProperty('size');
    14951532                const hasTabletZoomLevel = displaySettings && displaySettings.hasOwnProperty('zoom_tablet') && displaySettings.zoom_tablet && displaySettings.zoom_tablet.hasOwnProperty('size');
     
    15321569                    map.setView(centerCoords, zoomLevel);
    15331570                }
    1534                
     1571
    15351572                <?php if(empty($settings['geoapify_tile']) || $settings['geoapify_tile'] == 'osm-carto'):?>
    15361573                L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
     
    16071644
    16081645                L.mapboxGL({
    1609                     style: 'https://maps.geoapify.com/v1/styles/<?php echo $settings['geoapify_tile']; ?>/style.json?apiKey=<?php echo !empty($global_settings['geoapify_key']) ? esc_textarea(__($global_settings['geoapify_key'], 'your-slug')) : null; ?>',
     1646                    style: 'https://maps.geoapify.com/v1/styles/<?php echo esc_js($settings['geoapify_tile']); ?>/style.json?apiKey=<?php echo !empty($global_settings['geoapify_key']) ? esc_textarea(__($global_settings['geoapify_key'], 'your-slug')) : null; ?>',
    16101647                    accessToken: '<?php echo !empty($global_settings['mapbox_token']) ? esc_textarea(__($global_settings['mapbox_token'], 'your-slug')) : 'no-token'; ?>'
    16111648                }).addTo(map);
     
    17361773                        // add marker title
    17371774                        if (this.marker.marker_title) {
    1738                             tooltipContent += `<div class="marker-title"><h5 class="elementor-heading-title elementor-size-default">${this.marker.marker_title}</h5></div>`;
     1775                            tooltipContent += `<div class="marker-title"><h5 class="elementor-heading-title elementor-size-default">${escapeHtml(this.marker.marker_title)}</h5></div>`;
    17391776                        }
    17401777
     
    17441781                        // add marker description
    17451782                        if (this.marker.marker_description) {
    1746                             tooltipContent += `<div class="marker-description">${this.marker.marker_description}</div>`;
     1783                            tooltipContent += `<div class="marker-description">${escapeHtml(this.marker.marker_description)}</div>`;
    17471784                        }
    17481785
    17491786                        // add marker button
    17501787                        if (this.marker.show_button === 'yes' && this.marker.button_text) {
    1751                             let button_url_target = this.marker.hasOwnProperty('button_url_target') && this.marker.button_url_target ? this.marker.button_url_target : '_blank';
     1788                            let button_url_target = this.marker.hasOwnProperty('button_url_target') && this.marker.button_url_target ? escapeHtml(this.marker.button_url_target) : '_blank';
     1789                            let button_url = this.marker.button_url ? escapeUrl(this.marker.button_url) : '#';
    17521790                            tooltipContent += `<div class="marker-button elementor-button-wrapper">
    1753                                                 <a class="elementor-button elementor-button-link" target="${button_url_target}" href='${this.marker.button_url}' role="button">
     1791                                                <a class="elementor-button elementor-button-link" target="${button_url_target}" href="${button_url}" role="button">
    17541792                                                    <span class="elementor-button-content-wrapper">
    17551793                                                        <span class="elementor-button-text">
    1756                                                             ${this.marker.button_text}
     1794                                                            ${escapeHtml(this.marker.button_text)}
    17571795                                                        </span>
    17581796                                                    </span>
     
    17731811
    17741812                                case 'static_close_on':
    1775                                     marker.bindPopup(tooltipContent,{closeOnClick: false, autoClose: false, closeOnEscapeKey: false}).openPopup();
     1813                                    marker.bindPopup(tooltipContent, {
     1814                                        closeOnClick: false,
     1815                                        autoClose: false,
     1816                                        closeOnEscapeKey: false
     1817                                    }).openPopup();
    17761818                                    break;
    1777                                
     1819
    17781820                                case 'static_close_off':
    1779                                     marker.bindPopup(tooltipContent,{closeOnClick: false, autoClose: false, closeButton: false, closeOnEscapeKey: false}).openPopup();
     1821                                    marker.bindPopup(tooltipContent, {
     1822                                        closeOnClick: false,
     1823                                        autoClose: false,
     1824                                        closeButton: false,
     1825                                        closeOnEscapeKey: false
     1826                                    }).openPopup();
    17801827                                    break;
    1781                                    
     1828
    17821829                                case 'tooltip':
    17831830
     
    18501897            // echo out the markers script while in admin mode.
    18511898            // all required scripts will be loaded in header
    1852             echo is_admin() ? $markers_script : null;
     1899            if (is_admin()) {
     1900                // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- This is intentionally JavaScript output
     1901                echo $markers_script;
     1902            }
    18531903            ?>
    18541904        </script>
     
    18881938
    18891939        foreach ($styles as $handle => $path) {
    1890             wp_register_style($handle, $path);
     1940            wp_register_style($handle, $path, [], self::$ver);
    18911941            wp_enqueue_style($handle);
    18921942        }
     
    19071957            $dependencies = ['jquery'];
    19081958            foreach ($admin_scripts as $handle => $path) {
    1909                 wp_register_script($handle, $path, $dependencies, self::$ver);
     1959                wp_register_script($handle, $path, $dependencies, self::$ver, true);
    19101960                wp_enqueue_script($handle);
    19111961                $dependencies[] = $handle;
     
    19221972        $deps = [];
    19231973        foreach ($scripts as $handle => $path) {
    1924             wp_register_script($handle, $path, $deps, self::$ver);
     1974            wp_register_script($handle, $path, $deps, self::$ver, true);
    19251975            wp_enqueue_script($handle);
    19261976            $deps[] = $handle;
     
    19502000                return;
    19512001            // Print script & mark it as included.
     2002            // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- This is intentionally JavaScript output
    19522003            echo "<script type=\"text/javascript\" id=\"js-$handle\">\n$js\n</script>\n";
    19532004            global $wp_scripts;
     
    20262077        if ($showFrom) {
    20272078            $calledFrom = debug_backtrace();
    2028             echo '<strong>' . substr($calledFrom[0]['file'], 1) . '</strong>';
    2029             echo ' (line <strong>' . $calledFrom[0]['line'] . '</strong>)';
     2079            echo '<strong>' . esc_html(substr($calledFrom[0]['file'], 1)) . '</strong>';
     2080            echo ' (line <strong>' . esc_html($calledFrom[0]['line']) . '</strong>)';
    20302081        }
    20312082        echo "\n<pre class=\"fi-debug\">\n";
     
    20352086            $var = str_replace('<', '&lt;', str_replace('>', '&gt;', $var));
    20362087        }
    2037         echo $var . "\n</pre>\n";
     2088        echo esc_html($var) . "\n</pre>\n";
    20382089    }
    20392090}
  • osm-map-elementor/trunk/readme.txt

    r3107495 r3356450  
    11=== OSM Map Widget for Elementor ===
    22Plugin Name: OSM Map Widget for Elementor
    3 Version: 1.3.0
     3Version: 1.3.1
    44Author: Plugin Contributors
    55Author URI: https://github.com/flopperj/osm-map-elementor/graphs/contributors
     
    77Tags: elementor, elementor widget, map widget, open street map, addons
    88Requires at least: 6.0
    9 Tested up to: 6.5.4
     9Tested up to: 6.8.2
    1010Requires PHP: 7.3
    11 Stable tag: 1.3.0
     11Stable tag: 1.3.1
    1212License: GPLv3
    1313License URI: https://www.gnu.org/licenses/gpl-3.0.html
Note: See TracChangeset for help on using the changeset viewer.