Plugin Directory

Changeset 3832013


Ignore:
Timestamp:
11/28/2026 06:59:30 PM (14 hours ago)
Author:
bozdoz
Message:

Merge pull request #310 from bozdoz/fix/cve-2026-92093

Fix shortcode popup XSS

Location:
leaflet-map
Files:
20 edited
1 copied

Legend:

Unmodified
Added
Removed
  • leaflet-map/tags/3.4.8/README.md

    r3483997 r3832013  
    191191`layer` for the layer name and `crs` for the coordination system (only supported by
    192192leaflet: EPSG:3857 and EPSG:4326).
     193
     194The default source is [NASA GIBS](https://nasa-gibs.github.io/gibs-api-docs/access-basics/),
     195using Blue Marble imagery with shaded relief and bathymetry.
     196
    193197```
    194198[leaflet-wms source="https://your/wms/service?" layer="yourLayer" crs="EPSG:3857" zoom=1]
    … …  
    199203| Option            | Default                                   |
    200204| ----------------- | ----------------------------------------- |
    201 | `src`             | https://ows.mundialis.de/services/service? |
    202 | `layer `          | TOPO-OSM-WMS                              |
     205| `src`             | https://gibs.earthdata.nasa.gov/wms/epsg3857/best/wms.cgi? |
     206| `layer `          | BlueMarble_ShadedRelief_Bathymetry          |
    203207| `crs `            | EPSG:3857                                 |
    204208| `zoom`            | 12                                        |
    … …  
    211215| `min_zoom`        | 0                                         |
    212216| `max_zoom`        | 20                                        |
    213 | `attribution`     | ©Leaflet ©OpenStreetMap                  |
     217| `attribution`     | NASA GIBS (for the default source and layer) |
    214218| `lat`             | 0                                         |
    215219| `lng`             | 0                                         |
    … …  
    327331`[leaflet-geojson]Field A = {field_a}[/leaflet-geojson]`.
    328332
     333Popup HTML in shortcode content is filtered through WordPress's `wp_kses_post()`.
     334Feature properties, including `popup_property` and table values, are displayed as text.
     335To display an image from a feature property, use a template such as
     336`[leaflet-geojson]<img src="{photo_url}" alt="{title}" width="50" height="50">[/leaflet-geojson]`.
     337Image URL substitutions accept HTTP(S) and relative URLs; event handlers are removed.
     338
    329339### [leaflet-kml]
    330340
  • leaflet-map/tags/3.4.8/class.leaflet-map.php

    r3519096 r3832013  
    211211        if (defined('WP_DEBUG') && WP_DEBUG) {
    212212            $minified = '';
     213            $script_version = LEAFLET_MAP__PLUGIN_VERSION . '.' . filemtime(LEAFLET_MAP__PLUGIN_DIR . 'scripts/construct-leaflet-map.js');
    213214        } else {
    214215            $minified = '.min';
     216            $script_version = LEAFLET_MAP__PLUGIN_VERSION;
    215217        }
    216218
    … …  
    220222       
    221223        /* run a construct function in the document head for subsequent functions to use (it is lightweight) */
    222         wp_register_script('wp_leaflet_map', plugins_url(sprintf('scripts/construct-leaflet-map%s.js', $minified), __FILE__), Array('leaflet_js'), LEAFLET_MAP__PLUGIN_VERSION, false);
     224        wp_register_script('wp_leaflet_map', plugins_url(sprintf('scripts/construct-leaflet-map%s.js', $minified), __FILE__), Array('leaflet_js'), $script_version, false);
    223225    }
    224226
    … …  
    358360
    359361    /**
     362     * Sanitize popup HTML and encode it for an inline JavaScript value.
     363     *
     364     * @param string $content Popup HTML.
     365     * @return string JSON-encoded, sanitized HTML.
     366     */
     367    public function encode_popup_html($content)
     368    {
     369        return wp_json_encode(
     370            wp_kses_post($content),
     371            JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT
     372        ) ?: '""';
     373    }
     374
     375    /**
    360376     * Add Popups to Shapes
    361377     *
    … …  
    393409
    394410        $message = str_replace(array("\r\n", "\n", "\r"), '<br>', $message);
    395         $message = wp_kses_post( $message );
    396         $message = esc_html( $message );
    397 
    398         $message = "window.WPLeafletMapPlugin.unescape('{$message}')";
     411        $message = $this->encode_popup_html($message);
    399412
    400413        // use with: add_filter('leaflet_map_popup_message', 'example_callback', 10, 3);
  • leaflet-map/tags/3.4.8/leaflet-map.php

    r3659792 r3832013  
    99 * Text Domain: leaflet-map
    1010 * Domain Path: /languages/
    11  * Version: 3.4.7
     11 * Version: 3.4.8
    1212 * License: GPL2
    1313 * Leaflet Map is free software: you can redistribute it and/or modify
    … …  
    3030}
    3131
    32 define('LEAFLET_MAP__PLUGIN_VERSION', '3.4.7');
     32define('LEAFLET_MAP__PLUGIN_VERSION', '3.4.8');
    3333define('LEAFLET_MAP__PLUGIN_FILE', __FILE__);
    3434define('LEAFLET_MAP__PLUGIN_DIR', plugin_dir_path(__FILE__));
  • leaflet-map/tags/3.4.8/readme.txt

    r3659792 r3832013  
    77Tags: leaflet, map, openstreetmap, mapquest, interactive
    88Requires at least: 4.6
    9 Tested up to: 7.1
    10 Version: 3.4.7
    11 Stable tag: 3.4.7
     9Tested up to: 7.2
     10Version: 3.4.8
     11Stable tag: 3.4.8
    1212License: GPLv2
    1313License URI: https://www.gnu.org/licenses/gpl-2.0.html
    … …  
    120120
    121121Sure. Use the same attributes as leaflet-map, but use the `[leaflet-wms]` shortcode; attributes include: `src`, `layer`, and `crs`.
     122
     123By default, it uses NASA GIBS Blue Marble imagery with shaded relief and bathymetry.
    122124
    123125= Can I add a message to a marker? =
    … …  
    157159
    158160== Changelog ==
     161
     162= 3.4.8 =
     163* [Security] Fix stored cross-site scripting in shortcode popup content.
     164* [Bugfix] Replace the unavailable default WMS source with NASA GIBS Blue Marble imagery.
     165* Tested with WordPress 7.2
    159166
    160167= 3.4.7 =
  • leaflet-map/tags/3.4.8/scripts/construct-leaflet-map.js

    r3043427 r3832013  
    177177    };
    178178
     179    function escapeHTML(value) {
     180      return String(value).replace(/[&<>"']/g, function (character) {
     181        return {
     182          '&': '&amp;',
     183          '<': '&lt;',
     184          '>': '&gt;',
     185          '"': '&quot;',
     186          "'": '&#39;',
     187        }[character];
     188      });
     189    }
     190
     191    /** Remote property HTML is data, never markup. */
     192    this.textPopup = function (value) {
     193      var container = document.createElement('div');
     194      container.textContent = value == null ? '' : String(value);
     195      return container;
     196    };
     197
     198    /**
     199     * The template has already passed through wp_kses_post() in PHP.
     200     * Parse it inertly, then insert feature values without parsing them as HTML.
     201     */
     202    this.templatePopup = function (html, data) {
     203      var template = document.createElement('template');
     204      var container = document.createElement('div');
     205      if (!('content' in template)) {
     206        container.textContent = interpolate(html, data);
     207        return container;
     208      }
     209      template.innerHTML = html;
     210
     211      function fill(node) {
     212        if (node.nodeType === 3) {
     213          node.textContent = interpolate(node.textContent, data);
     214        } else if (node.nodeType === 1) {
     215          // Only these attributes accept feature substitutions. In particular,
     216          // never substitute into CSS, event handlers or attribute names.
     217          var attributes = Array.prototype.slice.call(node.attributes);
     218          for (var i = 0; i < attributes.length; i++) {
     219            var attribute = attributes[i];
     220            var name = attribute.name;
     221            if (attribute.value.search(templateRe) === -1) {
     222              continue;
     223            }
     224            if (!/^(alt|title|width|height|href|src)$/.test(name)) {
     225              node.removeAttribute(name);
     226              continue;
     227            }
     228            var value = interpolate(attribute.value, data);
     229            if (name === 'href' || name === 'src') {
     230              // Resolve relative URLs and normalize obfuscated schemes before
     231              // checking. Escaping quotes alone cannot stop javascript: URLs.
     232              var url = document.createElement('a');
     233              url.href = value;
     234              var allowed =
     235                name === 'src' ? /^(https?:)$/i : /^(https?:|mailto:|tel:)$/i;
     236              if (!allowed.test(url.protocol)) {
     237                node.removeAttribute(name);
     238                continue;
     239              }
     240            }
     241            node.setAttribute(name, value);
     242          }
     243        }
     244        for (var child = node.firstChild; child; child = child.nextSibling) {
     245          fill(child);
     246        }
     247      }
     248
     249      fill(template.content);
     250      container.appendChild(template.content);
     251      return container;
     252    };
     253
    179254    /** Adds all properties as a table-view for GeoJSON popups */
    180255    this.propsToTable = function (props) {
    … …  
    192267      for (var i = 0, len = keys.length; i < len; i++) {
    193268        var key = keys[i];
    194         output += '<tr><td>' + key + '</td>';
    195         output += '<td>' + props[key] + '</td></tr>';
     269        output += '<tr><td>' + escapeHTML(key) + '</td>';
     270        output += '<td>' + escapeHTML(props[key]) + '</td></tr>';
    196271      }
    197272
    … …  
    224299
    225300    var unescape = (this.unescape = function (str) {
    226       var div = document.createElement('div');
    227       div.innerHTML = str;
    228       return div.innerText || str;
     301      // Decode entities in template keys without parsing them as markup.
     302      var textarea = document.createElement('textarea');
     303      textarea.innerHTML = str.replace(/</g, '&lt;');
     304      return textarea.value;
    229305    });
    230306
    … …  
    239315     * @param {object} data e.g. feature.properties
    240316     */
    241     this.template = function (str, data) {
     317    function interpolate(str, data, escapeValues) {
    242318      if (data == null) {
    243319        return str;
    … …  
    250326          return obj.default || match;
    251327        }
    252         return value;
     328        return escapeValues ? escapeHTML(value) : String(value);
    253329      });
     330    }
     331
     332    this.template = function (str, data) {
     333      return interpolate(str, data, true);
    254334    };
    255335
  • leaflet-map/tags/3.4.8/scripts/construct-leaflet-map.min.js

    r3659792 r3832013  
    1 (function(){function y(){var m="v3.4.7";this.VERSION=m;function v(t){try{t()}catch(n){console.log("-- version --",m),console.error(n)}}var g=!1,f=[];this.push=function(t){g?v(t):f.push(t)},this.unshift=function(t){g?v(t):f.unshift(t)},this.init=function(){g=!0;for(var t=0,n=f.length;t<n;t++)v(f[t])},this.createMap=function(t){var n=document.getElementsByClassName("WPLeafletMap"),e=this.maps.length,i=n[e],r=L.map(i,t);return t.fitBounds&&(r._shouldFitBounds=!0),t.attribution&&T(t.attribution,r),this.maps.push(r),r},this.createImageMap=function(t){var n=this.createMap(t);return n.is_image_map=!0,this.images.push(n),n},this.getCurrentMap=function(){return this.maps[this.maps.length-1]},this.getCurrentGroup=function(){var t=this.maps.length;return this.markergroups[t]||(this.markergroups[t]=this.newMarkerGroup(this.maps[t-1])),this.markergroups[t]},this.getCurrentMarkerGroup=this.getCurrentGroup,this.getGroup=function(t){return new L.FeatureGroup().addTo(t)},this.newMarkerGroup=function(t){var n=this.getGroup(t);return n.timeout=null,t._shouldFitBounds&&n.on("layeradd",function(e){e.layer instanceof L.FeatureGroup&&e.layer.on("ready",function(){t.fitBounds(n.getBounds())}),window.clearTimeout(this.timeout),this.timeout=window.setTimeout(function(){try{t.fitBounds(n.getBounds())}catch{}},100)},n),n},this.propsToTable=function(t){var n,e=[];for(n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.push(n);e=e.sort();for(var i="<table>",r=0,a=e.length;r<a;r++){var o=e[r];i+="<tr><td>"+o+"</td>",i+="<td>"+t[o]+"</td></tr>"}return i+="</table>",i};function P(t){return t.trim()}function T(t,n){if(t)for(var e=t.split(";"),i=L.control.attribution({prefix:!1}).addTo(n),r=0,a=e.length;r<a;r++){var o=P(e[r]);i.addAttribution(o)}}var b=this.unescape=function(t){var n=document.createElement("div");return n.innerHTML=t,n.innerText||t},G=/\{ *(.*?) *\}/g;this.template=function(t,n){return n==null?t:t.replace(G,function(e,i){var r=E(i),a=k(n,r.key);return a??(r.default||e)})};var A=/[.‘’'“”"\[\]]+/g;function S(t){if(t==null)return[];for(var n=t.split(A),e=[],i=0,r=n.length;i<r;i++)n[i]!==""&&e.push(n[i]);return e}function k(t,n){for(var e=S(b(n)),i=t,r=0,a=e.length;r<a;r++)if(i=i[e[r]],!i)return;return i}function E(t){for(var n=t.split(" | "),e={},i=n.shift(),r=0,a=n.length;r<a;r++){var o=n[r].split(": "),h=o.shift(),s=o.join(": ")||!0;e[h]=s}return e.key=i,e}function w(t,n){typeof L<"u"&&typeof L[t]<"u"?n():setTimeout(function(){w(t,n)},100)}this.waitForSVG=function(t){w("SVGIcon",t)},this.waitForAjax=function(t){w("AjaxGeoJSON",t)},this.createScale=function(t){L.control.scale(t).addTo(this.getCurrentMap())},this.getIconOptions=function(t){for(var n=t||{},e=["iconSize","iconAnchor","shadowSize","shadowAnchor","popupAnchor","tooltipAnchor"],i=L.Icon.Default.prototype.options,r=0,a=e.length;r<a;r++){var o=e[r],h=n[o];if(h){for(var s=h.split(","),c=0,B=s.length;c<B;c++)s[c]=Number(s[c]);n[o]=s}}return n.popupAnchor||(n.popupAnchor=function(l){return l=l.slice(),l[0]=0,l[1]*=-1,l[1]-=3,l}(n.iconSize||i.iconSize)),n.iconUrl&&(n.icon=new L.Icon(n)),n},this.maps=[],this.images=[],this.markergroups={},this.markers=[],this.lines=[],this.polygons=[],this.circles=[],this.geojsons=[],this.overlays=[]}var u=window.WPLeafletMapPlugin;if(window.WPLeafletMapPlugin=new y,u){for(var p=0,M=u.length;p<M;p++)window.WPLeafletMapPlugin.push(u[p]);u.splice(0);for(var d in u)u.hasOwnProperty(d)&&(window.WPLeafletMapPlugin[d]=u[d])}window.addEventListener?window.addEventListener("load",window.WPLeafletMapPlugin.init,!1):window.attachEvent&&window.attachEvent("onload",window.WPLeafletMapPlugin.init)})();
     1(function(){function S(){var T="v3.4.8";this.VERSION=T;function w(t){try{t()}catch(e){console.log("-- version --",T),console.error(e)}}var y=!1,h=[];this.push=function(t){y?w(t):h.push(t)},this.unshift=function(t){y?w(t):h.unshift(t)},this.init=function(){y=!0;for(var t=0,e=h.length;t<e;t++)w(h[t])},this.createMap=function(t){var e=document.getElementsByClassName("WPLeafletMap"),r=this.maps.length,i=e[r],n=L.map(i,t);return t.fitBounds&&(n._shouldFitBounds=!0),t.attribution&&E(t.attribution,n),this.maps.push(n),n},this.createImageMap=function(t){var e=this.createMap(t);return e.is_image_map=!0,this.images.push(e),e},this.getCurrentMap=function(){return this.maps[this.maps.length-1]},this.getCurrentGroup=function(){var t=this.maps.length;return this.markergroups[t]||(this.markergroups[t]=this.newMarkerGroup(this.maps[t-1])),this.markergroups[t]},this.getCurrentMarkerGroup=this.getCurrentGroup,this.getGroup=function(t){return new L.FeatureGroup().addTo(t)},this.newMarkerGroup=function(t){var e=this.getGroup(t);return e.timeout=null,t._shouldFitBounds&&e.on("layeradd",function(r){r.layer instanceof L.FeatureGroup&&r.layer.on("ready",function(){t.fitBounds(e.getBounds())}),window.clearTimeout(this.timeout),this.timeout=window.setTimeout(function(){try{t.fitBounds(e.getBounds())}catch{}},100)},e),e};function M(t){return String(t).replace(/[&<>"']/g,function(e){return{"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"}[e]})}this.textPopup=function(t){var e=document.createElement("div");return e.textContent=t==null?"":String(t),e},this.templatePopup=function(t,e){var r=document.createElement("template"),i=document.createElement("div");if(!("content"in r))return i.textContent=p(t,e),i;r.innerHTML=t;function n(o){if(o.nodeType===3)o.textContent=p(o.textContent,e);else if(o.nodeType===1)for(var a=Array.prototype.slice.call(o.attributes),c=0;c<a.length;c++){var s=a[c],u=s.name;if(s.value.search(A)!==-1){if(!/^(alt|title|width|height|href|src)$/.test(u)){o.removeAttribute(u);continue}var v=p(s.value,e);if(u==="href"||u==="src"){var l=document.createElement("a");l.href=v;var I=u==="src"?/^(https?:)$/i:/^(https?:|mailto:|tel:)$/i;if(!I.test(l.protocol)){o.removeAttribute(u);continue}}o.setAttribute(u,v)}}for(var d=o.firstChild;d;d=d.nextSibling)n(d)}return n(r.content),i.appendChild(r.content),i},this.propsToTable=function(t){var e,r=[];for(e in t)Object.prototype.hasOwnProperty.call(t,e)&&r.push(e);r=r.sort();for(var i="<table>",n=0,o=r.length;n<o;n++){var a=r[n];i+="<tr><td>"+M(a)+"</td>",i+="<td>"+M(t[a])+"</td></tr>"}return i+="</table>",i};function C(t){return t.trim()}function E(t,e){if(t)for(var r=t.split(";"),i=L.control.attribution({prefix:!1}).addTo(e),n=0,o=r.length;n<o;n++){var a=C(r[n]);i.addAttribution(a)}}var G=this.unescape=function(t){var e=document.createElement("textarea");return e.innerHTML=t.replace(/</g,"&lt;"),e.value},A=/\{ *(.*?) *\}/g;function p(t,e,r){return e==null?t:t.replace(A,function(i,n){var o=F(n),a=B(e,o.key);return a==null?o.default||i:r?M(a):String(a)})}this.template=function(t,e){return p(t,e,!0)};var x=/[.‘’'“”"\[\]]+/g;function k(t){if(t==null)return[];for(var e=t.split(x),r=[],i=0,n=e.length;i<n;i++)e[i]!==""&&r.push(e[i]);return r}function B(t,e){for(var r=k(G(e)),i=t,n=0,o=r.length;n<o;n++)if(i=i[r[n]],!i)return;return i}function F(t){for(var e=t.split(" | "),r={},i=e.shift(),n=0,o=e.length;n<o;n++){var a=e[n].split(": "),c=a.shift(),s=a.join(": ")||!0;r[c]=s}return r.key=i,r}function P(t,e){typeof L<"u"&&typeof L[t]<"u"?e():setTimeout(function(){P(t,e)},100)}this.waitForSVG=function(t){P("SVGIcon",t)},this.waitForAjax=function(t){P("AjaxGeoJSON",t)},this.createScale=function(t){L.control.scale(t).addTo(this.getCurrentMap())},this.getIconOptions=function(t){for(var e=t||{},r=["iconSize","iconAnchor","shadowSize","shadowAnchor","popupAnchor","tooltipAnchor"],i=L.Icon.Default.prototype.options,n=0,o=r.length;n<o;n++){var a=r[n],c=e[a];if(c){for(var s=c.split(","),u=0,v=s.length;u<v;u++)s[u]=Number(s[u]);e[a]=s}}return e.popupAnchor||(e.popupAnchor=function(l){return l=l.slice(),l[0]=0,l[1]*=-1,l[1]-=3,l}(e.iconSize||i.iconSize)),e.iconUrl&&(e.icon=new L.Icon(e)),e},this.maps=[],this.images=[],this.markergroups={},this.markers=[],this.lines=[],this.polygons=[],this.circles=[],this.geojsons=[],this.overlays=[]}var f=window.WPLeafletMapPlugin;if(window.WPLeafletMapPlugin=new S,f){for(var g=0,b=f.length;g<b;g++)window.WPLeafletMapPlugin.push(f[g]);f.splice(0);for(var m in f)f.hasOwnProperty(m)&&(window.WPLeafletMapPlugin[m]=f[m])}window.addEventListener?window.addEventListener("load",window.WPLeafletMapPlugin.init,!1):window.attachEvent&&window.attachEvent("onload",window.WPLeafletMapPlugin.init)})();
  • leaflet-map/tags/3.4.8/shortcodes/class.geojson-shortcode.php

    r3522877 r3832013  
    5353        if ($content) {
    5454            $content = str_replace(array("\r\n", "\n", "\r"), '<br>', $content);
    55             $content = htmlspecialchars($content);
    5655        }
    5756
    … …  
    6867        $circleMarker = filter_var($circleMarker, FILTER_VALIDATE_BOOLEAN);
    6968
    70         // shortcode content becomes popup text
    71         $content_text = empty($content) ? '' : $content;
    72         // alternatively, the popup_text attribute works as popup text
    73         $popup_text = empty($popup_text) ? '' : $popup_text;
    74         // choose which one takes priority (content_text)
    75         $popup_text = empty($content_text) ? $popup_text : $content_text;
    76 
     69        // Enclosed content takes priority. Decode legacy attribute markup before JSON encoding.
     70        $popup_text = empty($content)
     71            ? html_entity_decode(empty($popup_text) ? '' : $popup_text, ENT_QUOTES | ENT_HTML5, 'UTF-8')
     72            : $content;
    7773        $popup_property = empty($popup_property) ? '' : $popup_property;
    78 
    79         $popup_text = trim($popup_text);
     74        $popup_json_flags = JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT;
    8075
    8176        $table_view = filter_var(empty($table_view) ? 0 : $table_view, FILTER_VALIDATE_INT);
    … …  
    108103    if (table_view) {
    109104        text = window.WPLeafletMapPlugin.propsToTable(props);
    110     } else {
    111         text = popup_property
    112             ? props[ popup_property ]
    113             : window.WPLeafletMapPlugin.template(
    114                 popup_text,
    115                 feature.properties
    116             );
     105    } else if (popup_property) {
     106        // Check the value before wrapping it in a truthy DOM element.
     107        text = props[ popup_property ];
     108        if (text) {
     109            text = window.WPLeafletMapPlugin.textPopup(text);
     110        }
     111    } else if (popup_text) {
     112        text = window.WPLeafletMapPlugin.templatePopup(
     113            popup_text,
     114            props
     115        );
    117116    }
    118117    if (text) {
    … …  
    149148var fitbounds = <?php echo $fitbounds ? '1' : '0'; ?>;
    150149var circleMarker = <?php echo $circleMarker ? '1' : '0'; ?>;
    151 var popup_text = window.WPLeafletMapPlugin.unescape("<?php echo esc_js(
    152   $popup_text
    153 ); ?>");
    154 var popup_property = "<?php echo esc_js($popup_property); ?>";
     150var popup_text = <?php echo $this->LM->encode_popup_html(trim($popup_text)); ?>;
     151var popup_property = <?php echo wp_json_encode($popup_property, $popup_json_flags) ?: '""'; ?>;
    155152var table_view = <?php echo $table_view; ?>;
    156153var group = window.WPLeafletMapPlugin.getCurrentGroup();
  • leaflet-map/tags/3.4.8/shortcodes/class.image-overlay-shortcode.php

    r2863840 r3832013  
    1919{
    2020    protected $type = 'L.imageOverlay';
    21     protected $default_src = 'https://maps.lib.utexas.edu/maps/historical/newark_nj_1922.jpg';
     21    protected $default_src = 'https://leafletjs.com/examples/overlays/newark_nj_1922.jpg';
    2222    protected $default_bounds = "40.712216,-74.22655;40.773941,-74.12544";
    2323
  • leaflet-map/tags/3.4.8/shortcodes/class.wms-shortcode.php

    r3019392 r3832013  
    3333  protected function getHTML($atts = '', $content = null)
    3434  {
     35    $atts = (array) $atts;
     36    $default_source = 'https://gibs.earthdata.nasa.gov/wms/epsg3857/best/wms.cgi?';
     37    $default_layer = 'BlueMarble_ShadedRelief_Bathymetry';
     38    $source = empty($atts['src'])
     39      ? (empty($atts['source']) ? $default_source : $atts['source'])
     40      : $atts['src'];
     41    $atts['source'] = filter_var($source, FILTER_SANITIZE_URL);
     42    $atts['layer'] = empty($atts['layer']) ? $default_layer : $atts['layer'];
     43
     44    if (
     45      $atts['source'] === $default_source &&
     46      $atts['layer'] === $default_layer &&
     47      !array_key_exists('attribution', $atts)
     48    ) {
     49      $atts['attribution'] = 'NASA GIBS';
     50    }
     51
    3552    extract($this->getAtts($atts));
    3653
    … …  
    5269    $lng = $this->LM->filter_float($lng);
    5370
    54     /* only required field for image map (src/source) */
    55     $src = empty($src) ? '' : $src;
    56     $source = empty($source)
    57       ? 'https://ows.mundialis.de/services/service?'
    58       : $source;
    59     $source = filter_var(empty($src) ? $source : $src, FILTER_SANITIZE_URL);
    60 
    61     $layer = empty($layer) ? 'TOPO-OSM-WMS' : $layer;
    62 
    6371    $crs = str_replace(':', '', empty($crs) ? 'EPSG:3857' : $crs);
    64 
    65     if ($source == 'https://ows.mundialis.de/services/service?' && $layer == 'TOPO-OSM-WMS') {
    66         $attribution = empty($attribution) ? '© OpenStreetMap Contributors' : $attribution;
    67     }
    68     $attribution = empty($attribution) ? '' : $attribution;
    6972
    7073    ob_start();
  • leaflet-map/tags/3.4.8/templates/shortcode-helper.php

    r3519096 r3832013  
    110110                __("Add GeoJSON with circle markers and popups", 'leaflet-map') => array(
    111111                    '[leaflet-map fitbounds scrollwheel]',
    112                     '[leaflet-geojson circleMarker radius=10 src=https://gist.githubusercontent.com/bozdoz/064a7101b95a324e8852fe9381ab9a18/raw/ee100561f5a0a8cf55430e9f2157e4a1e2560a2e/map.geojson]{popup-text}[/leaflet-geojson]'
     112                    '[leaflet-geojson circleMarker radius=10 src=https://gist.githubusercontent.com/bozdoz/064a7101b95a324e8852fe9381ab9a18/raw/ee100561f5a0a8cf55430e9f2157e4a1e2560a2e/map.geojson]{popup-text}<br><img src="https://picsum.photos/seed/leaflet-map/50/50" alt="GeoJSON popup example" width="50" height="50">[/leaflet-geojson]'
    113113                    ),
    114114                __("Add KML by URL", 'leaflet-map') => array(
    … …  
    124124                ),
    125125                __("Image Map", 'leaflet-map') => array(
    126                     '[leaflet-image zoom=1 zoomcontrol scrollwheel !attribution]',
    127                     '[leaflet-marker draggable]'
     126                    '[leaflet-image src="https://picsum.photos/seed/leaflet-map/1000/1000" zoom=1 zoomcontrol scrollwheel !attribution]',
     127                    '[leaflet-marker draggable]<img src="https://picsum.photos/seed/leaflet-map/50/50" alt="Image Map example" width="50" height="50">[/leaflet-marker]'
    128128                ),
    129129                __("Image Overlay Map", 'leaflet-map') => array(
    … …  
    138138                    '[leaflet-wms zoomControl zoom=5 lat=38.9252 lng=35.33203 attribution="For Those of Us in Turkey"]',
    139139                ),
     140                __("Prevents XSS", 'leaflet-map') => array(
     141                    '[leaflet-map fitbounds scrollwheel]',
     142                    '[leaflet-geojson circleMarker radius=10 src=https://gist.githubusercontent.com/bozdoz/064a7101b95a324e8852fe9381ab9a18/raw/ee100561f5a0a8cf55430e9f2157e4a1e2560a2e/map.geojson]{popup-text}<br><img src="broken-image.png" onerror="console.log(\'GeoJSON XSS test:\', this.closest(\'.leaflet-popup-content\') ? \'popup\' : \'shortcode preview\')" alt="GeoJSON XSS prevention example" width="50" height="50">[/leaflet-geojson]',
     143                    '[leaflet-marker lat=44.67 lng=-63.61]<img src="broken-image.png" onerror="console.log(\'Marker XSS test:\', this.closest(\'.leaflet-popup-content\') ? \'popup\' : \'shortcode preview\')" alt="Marker XSS prevention example" width="50" height="50">[/leaflet-marker]'
     144                ),
    140145                );
    141146
    … …  
    145150                foreach ($collection as $shortcode) {
    146151                    echo do_shortcode($shortcode);
    147                     echo "<p>$shortcode</p>";
     152                    echo '<p>' . esc_html($shortcode) . '</p>';
    148153                }
    149154                echo '</div>';
  • leaflet-map/trunk/README.md

    r3483997 r3832013  
    191191`layer` for the layer name and `crs` for the coordination system (only supported by
    192192leaflet: EPSG:3857 and EPSG:4326).
     193
     194The default source is [NASA GIBS](https://nasa-gibs.github.io/gibs-api-docs/access-basics/),
     195using Blue Marble imagery with shaded relief and bathymetry.
     196
    193197```
    194198[leaflet-wms source="https://your/wms/service?" layer="yourLayer" crs="EPSG:3857" zoom=1]
    … …  
    199203| Option            | Default                                   |
    200204| ----------------- | ----------------------------------------- |
    201 | `src`             | https://ows.mundialis.de/services/service? |
    202 | `layer `          | TOPO-OSM-WMS                              |
     205| `src`             | https://gibs.earthdata.nasa.gov/wms/epsg3857/best/wms.cgi? |
     206| `layer `          | BlueMarble_ShadedRelief_Bathymetry          |
    203207| `crs `            | EPSG:3857                                 |
    204208| `zoom`            | 12                                        |
    … …  
    211215| `min_zoom`        | 0                                         |
    212216| `max_zoom`        | 20                                        |
    213 | `attribution`     | ©Leaflet ©OpenStreetMap                  |
     217| `attribution`     | NASA GIBS (for the default source and layer) |
    214218| `lat`             | 0                                         |
    215219| `lng`             | 0                                         |
    … …  
    327331`[leaflet-geojson]Field A = {field_a}[/leaflet-geojson]`.
    328332
     333Popup HTML in shortcode content is filtered through WordPress's `wp_kses_post()`.
     334Feature properties, including `popup_property` and table values, are displayed as text.
     335To display an image from a feature property, use a template such as
     336`[leaflet-geojson]<img src="{photo_url}" alt="{title}" width="50" height="50">[/leaflet-geojson]`.
     337Image URL substitutions accept HTTP(S) and relative URLs; event handlers are removed.
     338
    329339### [leaflet-kml]
    330340
  • leaflet-map/trunk/class.leaflet-map.php

    r3519096 r3832013  
    211211        if (defined('WP_DEBUG') && WP_DEBUG) {
    212212            $minified = '';
     213            $script_version = LEAFLET_MAP__PLUGIN_VERSION . '.' . filemtime(LEAFLET_MAP__PLUGIN_DIR . 'scripts/construct-leaflet-map.js');
    213214        } else {
    214215            $minified = '.min';
     216            $script_version = LEAFLET_MAP__PLUGIN_VERSION;
    215217        }
    216218
    … …  
    220222       
    221223        /* run a construct function in the document head for subsequent functions to use (it is lightweight) */
    222         wp_register_script('wp_leaflet_map', plugins_url(sprintf('scripts/construct-leaflet-map%s.js', $minified), __FILE__), Array('leaflet_js'), LEAFLET_MAP__PLUGIN_VERSION, false);
     224        wp_register_script('wp_leaflet_map', plugins_url(sprintf('scripts/construct-leaflet-map%s.js', $minified), __FILE__), Array('leaflet_js'), $script_version, false);
    223225    }
    224226
    … …  
    358360
    359361    /**
     362     * Sanitize popup HTML and encode it for an inline JavaScript value.
     363     *
     364     * @param string $content Popup HTML.
     365     * @return string JSON-encoded, sanitized HTML.
     366     */
     367    public function encode_popup_html($content)
     368    {
     369        return wp_json_encode(
     370            wp_kses_post($content),
     371            JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT
     372        ) ?: '""';
     373    }
     374
     375    /**
    360376     * Add Popups to Shapes
    361377     *
    … …  
    393409
    394410        $message = str_replace(array("\r\n", "\n", "\r"), '<br>', $message);
    395         $message = wp_kses_post( $message );
    396         $message = esc_html( $message );
    397 
    398         $message = "window.WPLeafletMapPlugin.unescape('{$message}')";
     411        $message = $this->encode_popup_html($message);
    399412
    400413        // use with: add_filter('leaflet_map_popup_message', 'example_callback', 10, 3);
  • leaflet-map/trunk/leaflet-map.php

    r3659792 r3832013  
    99 * Text Domain: leaflet-map
    1010 * Domain Path: /languages/
    11  * Version: 3.4.7
     11 * Version: 3.4.8
    1212 * License: GPL2
    1313 * Leaflet Map is free software: you can redistribute it and/or modify
    … …  
    3030}
    3131
    32 define('LEAFLET_MAP__PLUGIN_VERSION', '3.4.7');
     32define('LEAFLET_MAP__PLUGIN_VERSION', '3.4.8');
    3333define('LEAFLET_MAP__PLUGIN_FILE', __FILE__);
    3434define('LEAFLET_MAP__PLUGIN_DIR', plugin_dir_path(__FILE__));
  • leaflet-map/trunk/readme.txt

    r3659792 r3832013  
    77Tags: leaflet, map, openstreetmap, mapquest, interactive
    88Requires at least: 4.6
    9 Tested up to: 7.1
    10 Version: 3.4.7
    11 Stable tag: 3.4.7
     9Tested up to: 7.2
     10Version: 3.4.8
     11Stable tag: 3.4.8
    1212License: GPLv2
    1313License URI: https://www.gnu.org/licenses/gpl-2.0.html
    … …  
    120120
    121121Sure. Use the same attributes as leaflet-map, but use the `[leaflet-wms]` shortcode; attributes include: `src`, `layer`, and `crs`.
     122
     123By default, it uses NASA GIBS Blue Marble imagery with shaded relief and bathymetry.
    122124
    123125= Can I add a message to a marker? =
    … …  
    157159
    158160== Changelog ==
     161
     162= 3.4.8 =
     163* [Security] Fix stored cross-site scripting in shortcode popup content.
     164* [Bugfix] Replace the unavailable default WMS source with NASA GIBS Blue Marble imagery.
     165* Tested with WordPress 7.2
    159166
    160167= 3.4.7 =
  • leaflet-map/trunk/scripts/construct-leaflet-map.js

    r3043427 r3832013  
    177177    };
    178178
     179    function escapeHTML(value) {
     180      return String(value).replace(/[&<>"']/g, function (character) {
     181        return {
     182          '&': '&amp;',
     183          '<': '&lt;',
     184          '>': '&gt;',
     185          '"': '&quot;',
     186          "'": '&#39;',
     187        }[character];
     188      });
     189    }
     190
     191    /** Remote property HTML is data, never markup. */
     192    this.textPopup = function (value) {
     193      var container = document.createElement('div');
     194      container.textContent = value == null ? '' : String(value);
     195      return container;
     196    };
     197
     198    /**
     199     * The template has already passed through wp_kses_post() in PHP.
     200     * Parse it inertly, then insert feature values without parsing them as HTML.
     201     */
     202    this.templatePopup = function (html, data) {
     203      var template = document.createElement('template');
     204      var container = document.createElement('div');
     205      if (!('content' in template)) {
     206        container.textContent = interpolate(html, data);
     207        return container;
     208      }
     209      template.innerHTML = html;
     210
     211      function fill(node) {
     212        if (node.nodeType === 3) {
     213          node.textContent = interpolate(node.textContent, data);
     214        } else if (node.nodeType === 1) {
     215          // Only these attributes accept feature substitutions. In particular,
     216          // never substitute into CSS, event handlers or attribute names.
     217          var attributes = Array.prototype.slice.call(node.attributes);
     218          for (var i = 0; i < attributes.length; i++) {
     219            var attribute = attributes[i];
     220            var name = attribute.name;
     221            if (attribute.value.search(templateRe) === -1) {
     222              continue;
     223            }
     224            if (!/^(alt|title|width|height|href|src)$/.test(name)) {
     225              node.removeAttribute(name);
     226              continue;
     227            }
     228            var value = interpolate(attribute.value, data);
     229            if (name === 'href' || name === 'src') {
     230              // Resolve relative URLs and normalize obfuscated schemes before
     231              // checking. Escaping quotes alone cannot stop javascript: URLs.
     232              var url = document.createElement('a');
     233              url.href = value;
     234              var allowed =
     235                name === 'src' ? /^(https?:)$/i : /^(https?:|mailto:|tel:)$/i;
     236              if (!allowed.test(url.protocol)) {
     237                node.removeAttribute(name);
     238                continue;
     239              }
     240            }
     241            node.setAttribute(name, value);
     242          }
     243        }
     244        for (var child = node.firstChild; child; child = child.nextSibling) {
     245          fill(child);
     246        }
     247      }
     248
     249      fill(template.content);
     250      container.appendChild(template.content);
     251      return container;
     252    };
     253
    179254    /** Adds all properties as a table-view for GeoJSON popups */
    180255    this.propsToTable = function (props) {
    … …  
    192267      for (var i = 0, len = keys.length; i < len; i++) {
    193268        var key = keys[i];
    194         output += '<tr><td>' + key + '</td>';
    195         output += '<td>' + props[key] + '</td></tr>';
     269        output += '<tr><td>' + escapeHTML(key) + '</td>';
     270        output += '<td>' + escapeHTML(props[key]) + '</td></tr>';
    196271      }
    197272
    … …  
    224299
    225300    var unescape = (this.unescape = function (str) {
    226       var div = document.createElement('div');
    227       div.innerHTML = str;
    228       return div.innerText || str;
     301      // Decode entities in template keys without parsing them as markup.
     302      var textarea = document.createElement('textarea');
     303      textarea.innerHTML = str.replace(/</g, '&lt;');
     304      return textarea.value;
    229305    });
    230306
    … …  
    239315     * @param {object} data e.g. feature.properties
    240316     */
    241     this.template = function (str, data) {
     317    function interpolate(str, data, escapeValues) {
    242318      if (data == null) {
    243319        return str;
    … …  
    250326          return obj.default || match;
    251327        }
    252         return value;
     328        return escapeValues ? escapeHTML(value) : String(value);
    253329      });
     330    }
     331
     332    this.template = function (str, data) {
     333      return interpolate(str, data, true);
    254334    };
    255335
  • leaflet-map/trunk/scripts/construct-leaflet-map.min.js

    r3659792 r3832013  
    1 (function(){function y(){var m="v3.4.7";this.VERSION=m;function v(t){try{t()}catch(n){console.log("-- version --",m),console.error(n)}}var g=!1,f=[];this.push=function(t){g?v(t):f.push(t)},this.unshift=function(t){g?v(t):f.unshift(t)},this.init=function(){g=!0;for(var t=0,n=f.length;t<n;t++)v(f[t])},this.createMap=function(t){var n=document.getElementsByClassName("WPLeafletMap"),e=this.maps.length,i=n[e],r=L.map(i,t);return t.fitBounds&&(r._shouldFitBounds=!0),t.attribution&&T(t.attribution,r),this.maps.push(r),r},this.createImageMap=function(t){var n=this.createMap(t);return n.is_image_map=!0,this.images.push(n),n},this.getCurrentMap=function(){return this.maps[this.maps.length-1]},this.getCurrentGroup=function(){var t=this.maps.length;return this.markergroups[t]||(this.markergroups[t]=this.newMarkerGroup(this.maps[t-1])),this.markergroups[t]},this.getCurrentMarkerGroup=this.getCurrentGroup,this.getGroup=function(t){return new L.FeatureGroup().addTo(t)},this.newMarkerGroup=function(t){var n=this.getGroup(t);return n.timeout=null,t._shouldFitBounds&&n.on("layeradd",function(e){e.layer instanceof L.FeatureGroup&&e.layer.on("ready",function(){t.fitBounds(n.getBounds())}),window.clearTimeout(this.timeout),this.timeout=window.setTimeout(function(){try{t.fitBounds(n.getBounds())}catch{}},100)},n),n},this.propsToTable=function(t){var n,e=[];for(n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.push(n);e=e.sort();for(var i="<table>",r=0,a=e.length;r<a;r++){var o=e[r];i+="<tr><td>"+o+"</td>",i+="<td>"+t[o]+"</td></tr>"}return i+="</table>",i};function P(t){return t.trim()}function T(t,n){if(t)for(var e=t.split(";"),i=L.control.attribution({prefix:!1}).addTo(n),r=0,a=e.length;r<a;r++){var o=P(e[r]);i.addAttribution(o)}}var b=this.unescape=function(t){var n=document.createElement("div");return n.innerHTML=t,n.innerText||t},G=/\{ *(.*?) *\}/g;this.template=function(t,n){return n==null?t:t.replace(G,function(e,i){var r=E(i),a=k(n,r.key);return a??(r.default||e)})};var A=/[.‘’'“”"\[\]]+/g;function S(t){if(t==null)return[];for(var n=t.split(A),e=[],i=0,r=n.length;i<r;i++)n[i]!==""&&e.push(n[i]);return e}function k(t,n){for(var e=S(b(n)),i=t,r=0,a=e.length;r<a;r++)if(i=i[e[r]],!i)return;return i}function E(t){for(var n=t.split(" | "),e={},i=n.shift(),r=0,a=n.length;r<a;r++){var o=n[r].split(": "),h=o.shift(),s=o.join(": ")||!0;e[h]=s}return e.key=i,e}function w(t,n){typeof L<"u"&&typeof L[t]<"u"?n():setTimeout(function(){w(t,n)},100)}this.waitForSVG=function(t){w("SVGIcon",t)},this.waitForAjax=function(t){w("AjaxGeoJSON",t)},this.createScale=function(t){L.control.scale(t).addTo(this.getCurrentMap())},this.getIconOptions=function(t){for(var n=t||{},e=["iconSize","iconAnchor","shadowSize","shadowAnchor","popupAnchor","tooltipAnchor"],i=L.Icon.Default.prototype.options,r=0,a=e.length;r<a;r++){var o=e[r],h=n[o];if(h){for(var s=h.split(","),c=0,B=s.length;c<B;c++)s[c]=Number(s[c]);n[o]=s}}return n.popupAnchor||(n.popupAnchor=function(l){return l=l.slice(),l[0]=0,l[1]*=-1,l[1]-=3,l}(n.iconSize||i.iconSize)),n.iconUrl&&(n.icon=new L.Icon(n)),n},this.maps=[],this.images=[],this.markergroups={},this.markers=[],this.lines=[],this.polygons=[],this.circles=[],this.geojsons=[],this.overlays=[]}var u=window.WPLeafletMapPlugin;if(window.WPLeafletMapPlugin=new y,u){for(var p=0,M=u.length;p<M;p++)window.WPLeafletMapPlugin.push(u[p]);u.splice(0);for(var d in u)u.hasOwnProperty(d)&&(window.WPLeafletMapPlugin[d]=u[d])}window.addEventListener?window.addEventListener("load",window.WPLeafletMapPlugin.init,!1):window.attachEvent&&window.attachEvent("onload",window.WPLeafletMapPlugin.init)})();
     1(function(){function S(){var T="v3.4.8";this.VERSION=T;function w(t){try{t()}catch(e){console.log("-- version --",T),console.error(e)}}var y=!1,h=[];this.push=function(t){y?w(t):h.push(t)},this.unshift=function(t){y?w(t):h.unshift(t)},this.init=function(){y=!0;for(var t=0,e=h.length;t<e;t++)w(h[t])},this.createMap=function(t){var e=document.getElementsByClassName("WPLeafletMap"),r=this.maps.length,i=e[r],n=L.map(i,t);return t.fitBounds&&(n._shouldFitBounds=!0),t.attribution&&E(t.attribution,n),this.maps.push(n),n},this.createImageMap=function(t){var e=this.createMap(t);return e.is_image_map=!0,this.images.push(e),e},this.getCurrentMap=function(){return this.maps[this.maps.length-1]},this.getCurrentGroup=function(){var t=this.maps.length;return this.markergroups[t]||(this.markergroups[t]=this.newMarkerGroup(this.maps[t-1])),this.markergroups[t]},this.getCurrentMarkerGroup=this.getCurrentGroup,this.getGroup=function(t){return new L.FeatureGroup().addTo(t)},this.newMarkerGroup=function(t){var e=this.getGroup(t);return e.timeout=null,t._shouldFitBounds&&e.on("layeradd",function(r){r.layer instanceof L.FeatureGroup&&r.layer.on("ready",function(){t.fitBounds(e.getBounds())}),window.clearTimeout(this.timeout),this.timeout=window.setTimeout(function(){try{t.fitBounds(e.getBounds())}catch{}},100)},e),e};function M(t){return String(t).replace(/[&<>"']/g,function(e){return{"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"}[e]})}this.textPopup=function(t){var e=document.createElement("div");return e.textContent=t==null?"":String(t),e},this.templatePopup=function(t,e){var r=document.createElement("template"),i=document.createElement("div");if(!("content"in r))return i.textContent=p(t,e),i;r.innerHTML=t;function n(o){if(o.nodeType===3)o.textContent=p(o.textContent,e);else if(o.nodeType===1)for(var a=Array.prototype.slice.call(o.attributes),c=0;c<a.length;c++){var s=a[c],u=s.name;if(s.value.search(A)!==-1){if(!/^(alt|title|width|height|href|src)$/.test(u)){o.removeAttribute(u);continue}var v=p(s.value,e);if(u==="href"||u==="src"){var l=document.createElement("a");l.href=v;var I=u==="src"?/^(https?:)$/i:/^(https?:|mailto:|tel:)$/i;if(!I.test(l.protocol)){o.removeAttribute(u);continue}}o.setAttribute(u,v)}}for(var d=o.firstChild;d;d=d.nextSibling)n(d)}return n(r.content),i.appendChild(r.content),i},this.propsToTable=function(t){var e,r=[];for(e in t)Object.prototype.hasOwnProperty.call(t,e)&&r.push(e);r=r.sort();for(var i="<table>",n=0,o=r.length;n<o;n++){var a=r[n];i+="<tr><td>"+M(a)+"</td>",i+="<td>"+M(t[a])+"</td></tr>"}return i+="</table>",i};function C(t){return t.trim()}function E(t,e){if(t)for(var r=t.split(";"),i=L.control.attribution({prefix:!1}).addTo(e),n=0,o=r.length;n<o;n++){var a=C(r[n]);i.addAttribution(a)}}var G=this.unescape=function(t){var e=document.createElement("textarea");return e.innerHTML=t.replace(/</g,"&lt;"),e.value},A=/\{ *(.*?) *\}/g;function p(t,e,r){return e==null?t:t.replace(A,function(i,n){var o=F(n),a=B(e,o.key);return a==null?o.default||i:r?M(a):String(a)})}this.template=function(t,e){return p(t,e,!0)};var x=/[.‘’'“”"\[\]]+/g;function k(t){if(t==null)return[];for(var e=t.split(x),r=[],i=0,n=e.length;i<n;i++)e[i]!==""&&r.push(e[i]);return r}function B(t,e){for(var r=k(G(e)),i=t,n=0,o=r.length;n<o;n++)if(i=i[r[n]],!i)return;return i}function F(t){for(var e=t.split(" | "),r={},i=e.shift(),n=0,o=e.length;n<o;n++){var a=e[n].split(": "),c=a.shift(),s=a.join(": ")||!0;r[c]=s}return r.key=i,r}function P(t,e){typeof L<"u"&&typeof L[t]<"u"?e():setTimeout(function(){P(t,e)},100)}this.waitForSVG=function(t){P("SVGIcon",t)},this.waitForAjax=function(t){P("AjaxGeoJSON",t)},this.createScale=function(t){L.control.scale(t).addTo(this.getCurrentMap())},this.getIconOptions=function(t){for(var e=t||{},r=["iconSize","iconAnchor","shadowSize","shadowAnchor","popupAnchor","tooltipAnchor"],i=L.Icon.Default.prototype.options,n=0,o=r.length;n<o;n++){var a=r[n],c=e[a];if(c){for(var s=c.split(","),u=0,v=s.length;u<v;u++)s[u]=Number(s[u]);e[a]=s}}return e.popupAnchor||(e.popupAnchor=function(l){return l=l.slice(),l[0]=0,l[1]*=-1,l[1]-=3,l}(e.iconSize||i.iconSize)),e.iconUrl&&(e.icon=new L.Icon(e)),e},this.maps=[],this.images=[],this.markergroups={},this.markers=[],this.lines=[],this.polygons=[],this.circles=[],this.geojsons=[],this.overlays=[]}var f=window.WPLeafletMapPlugin;if(window.WPLeafletMapPlugin=new S,f){for(var g=0,b=f.length;g<b;g++)window.WPLeafletMapPlugin.push(f[g]);f.splice(0);for(var m in f)f.hasOwnProperty(m)&&(window.WPLeafletMapPlugin[m]=f[m])}window.addEventListener?window.addEventListener("load",window.WPLeafletMapPlugin.init,!1):window.attachEvent&&window.attachEvent("onload",window.WPLeafletMapPlugin.init)})();
  • leaflet-map/trunk/shortcodes/class.geojson-shortcode.php

    r3522877 r3832013  
    5353        if ($content) {
    5454            $content = str_replace(array("\r\n", "\n", "\r"), '<br>', $content);
    55             $content = htmlspecialchars($content);
    5655        }
    5756
    … …  
    6867        $circleMarker = filter_var($circleMarker, FILTER_VALIDATE_BOOLEAN);
    6968
    70         // shortcode content becomes popup text
    71         $content_text = empty($content) ? '' : $content;
    72         // alternatively, the popup_text attribute works as popup text
    73         $popup_text = empty($popup_text) ? '' : $popup_text;
    74         // choose which one takes priority (content_text)
    75         $popup_text = empty($content_text) ? $popup_text : $content_text;
    76 
     69        // Enclosed content takes priority. Decode legacy attribute markup before JSON encoding.
     70        $popup_text = empty($content)
     71            ? html_entity_decode(empty($popup_text) ? '' : $popup_text, ENT_QUOTES | ENT_HTML5, 'UTF-8')
     72            : $content;
    7773        $popup_property = empty($popup_property) ? '' : $popup_property;
    78 
    79         $popup_text = trim($popup_text);
     74        $popup_json_flags = JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT;
    8075
    8176        $table_view = filter_var(empty($table_view) ? 0 : $table_view, FILTER_VALIDATE_INT);
    … …  
    108103    if (table_view) {
    109104        text = window.WPLeafletMapPlugin.propsToTable(props);
    110     } else {
    111         text = popup_property
    112             ? props[ popup_property ]
    113             : window.WPLeafletMapPlugin.template(
    114                 popup_text,
    115                 feature.properties
    116             );
     105    } else if (popup_property) {
     106        // Check the value before wrapping it in a truthy DOM element.
     107        text = props[ popup_property ];
     108        if (text) {
     109            text = window.WPLeafletMapPlugin.textPopup(text);
     110        }
     111    } else if (popup_text) {
     112        text = window.WPLeafletMapPlugin.templatePopup(
     113            popup_text,
     114            props
     115        );
    117116    }
    118117    if (text) {
    … …  
    149148var fitbounds = <?php echo $fitbounds ? '1' : '0'; ?>;
    150149var circleMarker = <?php echo $circleMarker ? '1' : '0'; ?>;
    151 var popup_text = window.WPLeafletMapPlugin.unescape("<?php echo esc_js(
    152   $popup_text
    153 ); ?>");
    154 var popup_property = "<?php echo esc_js($popup_property); ?>";
     150var popup_text = <?php echo $this->LM->encode_popup_html(trim($popup_text)); ?>;
     151var popup_property = <?php echo wp_json_encode($popup_property, $popup_json_flags) ?: '""'; ?>;
    155152var table_view = <?php echo $table_view; ?>;
    156153var group = window.WPLeafletMapPlugin.getCurrentGroup();
  • leaflet-map/trunk/shortcodes/class.image-overlay-shortcode.php

    r2863840 r3832013  
    1919{
    2020    protected $type = 'L.imageOverlay';
    21     protected $default_src = 'https://maps.lib.utexas.edu/maps/historical/newark_nj_1922.jpg';
     21    protected $default_src = 'https://leafletjs.com/examples/overlays/newark_nj_1922.jpg';
    2222    protected $default_bounds = "40.712216,-74.22655;40.773941,-74.12544";
    2323
  • leaflet-map/trunk/shortcodes/class.wms-shortcode.php

    r3019392 r3832013  
    3333  protected function getHTML($atts = '', $content = null)
    3434  {
     35    $atts = (array) $atts;
     36    $default_source = 'https://gibs.earthdata.nasa.gov/wms/epsg3857/best/wms.cgi?';
     37    $default_layer = 'BlueMarble_ShadedRelief_Bathymetry';
     38    $source = empty($atts['src'])
     39      ? (empty($atts['source']) ? $default_source : $atts['source'])
     40      : $atts['src'];
     41    $atts['source'] = filter_var($source, FILTER_SANITIZE_URL);
     42    $atts['layer'] = empty($atts['layer']) ? $default_layer : $atts['layer'];
     43
     44    if (
     45      $atts['source'] === $default_source &&
     46      $atts['layer'] === $default_layer &&
     47      !array_key_exists('attribution', $atts)
     48    ) {
     49      $atts['attribution'] = 'NASA GIBS';
     50    }
     51
    3552    extract($this->getAtts($atts));
    3653
    … …  
    5269    $lng = $this->LM->filter_float($lng);
    5370
    54     /* only required field for image map (src/source) */
    55     $src = empty($src) ? '' : $src;
    56     $source = empty($source)
    57       ? 'https://ows.mundialis.de/services/service?'
    58       : $source;
    59     $source = filter_var(empty($src) ? $source : $src, FILTER_SANITIZE_URL);
    60 
    61     $layer = empty($layer) ? 'TOPO-OSM-WMS' : $layer;
    62 
    6371    $crs = str_replace(':', '', empty($crs) ? 'EPSG:3857' : $crs);
    64 
    65     if ($source == 'https://ows.mundialis.de/services/service?' && $layer == 'TOPO-OSM-WMS') {
    66         $attribution = empty($attribution) ? '© OpenStreetMap Contributors' : $attribution;
    67     }
    68     $attribution = empty($attribution) ? '' : $attribution;
    6972
    7073    ob_start();
  • leaflet-map/trunk/templates/shortcode-helper.php

    r3519096 r3832013  
    110110                __("Add GeoJSON with circle markers and popups", 'leaflet-map') => array(
    111111                    '[leaflet-map fitbounds scrollwheel]',
    112                     '[leaflet-geojson circleMarker radius=10 src=https://gist.githubusercontent.com/bozdoz/064a7101b95a324e8852fe9381ab9a18/raw/ee100561f5a0a8cf55430e9f2157e4a1e2560a2e/map.geojson]{popup-text}[/leaflet-geojson]'
     112                    '[leaflet-geojson circleMarker radius=10 src=https://gist.githubusercontent.com/bozdoz/064a7101b95a324e8852fe9381ab9a18/raw/ee100561f5a0a8cf55430e9f2157e4a1e2560a2e/map.geojson]{popup-text}<br><img src="https://picsum.photos/seed/leaflet-map/50/50" alt="GeoJSON popup example" width="50" height="50">[/leaflet-geojson]'
    113113                    ),
    114114                __("Add KML by URL", 'leaflet-map') => array(
    … …  
    124124                ),
    125125                __("Image Map", 'leaflet-map') => array(
    126                     '[leaflet-image zoom=1 zoomcontrol scrollwheel !attribution]',
    127                     '[leaflet-marker draggable]'
     126                    '[leaflet-image src="https://picsum.photos/seed/leaflet-map/1000/1000" zoom=1 zoomcontrol scrollwheel !attribution]',
     127                    '[leaflet-marker draggable]<img src="https://picsum.photos/seed/leaflet-map/50/50" alt="Image Map example" width="50" height="50">[/leaflet-marker]'
    128128                ),
    129129                __("Image Overlay Map", 'leaflet-map') => array(
    … …  
    138138                    '[leaflet-wms zoomControl zoom=5 lat=38.9252 lng=35.33203 attribution="For Those of Us in Turkey"]',
    139139                ),
     140                __("Prevents XSS", 'leaflet-map') => array(
     141                    '[leaflet-map fitbounds scrollwheel]',
     142                    '[leaflet-geojson circleMarker radius=10 src=https://gist.githubusercontent.com/bozdoz/064a7101b95a324e8852fe9381ab9a18/raw/ee100561f5a0a8cf55430e9f2157e4a1e2560a2e/map.geojson]{popup-text}<br><img src="broken-image.png" onerror="console.log(\'GeoJSON XSS test:\', this.closest(\'.leaflet-popup-content\') ? \'popup\' : \'shortcode preview\')" alt="GeoJSON XSS prevention example" width="50" height="50">[/leaflet-geojson]',
     143                    '[leaflet-marker lat=44.67 lng=-63.61]<img src="broken-image.png" onerror="console.log(\'Marker XSS test:\', this.closest(\'.leaflet-popup-content\') ? \'popup\' : \'shortcode preview\')" alt="Marker XSS prevention example" width="50" height="50">[/leaflet-marker]'
     144                ),
    140145                );
    141146
    … …  
    145150                foreach ($collection as $shortcode) {
    146151                    echo do_shortcode($shortcode);
    147                     echo "<p>$shortcode</p>";
     152                    echo '<p>' . esc_html($shortcode) . '</p>';
    148153                }
    149154                echo '</div>';
Note: See TracChangeset for help on using the changeset viewer.