Skip to content

Commit

Permalink
fix: update data viewer against XSS
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Nutt <michael@nuttnet.net>
  • Loading branch information
mnutt committed Jan 18, 2023
1 parent 2172de3 commit c71269e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
10 changes: 8 additions & 2 deletions public/templates/data.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
<div id="layerList"></div>
<pre id="propertyList"></pre>
<script>
var keyMatch = location.search.match(/[\?\&]key=([^&]+)/i);
var keyParam = keyMatch ? '?key=' + keyMatch[1] : '';

var map = new maplibregl.Map({
container: 'map',
hash: true,
Expand All @@ -44,7 +47,7 @@
sources: {
'vector_layer_': {
type: 'vector',
url: '{{public_url}}data/{{id}}.json{{&key_query}}'
url: '{{public_url}}data/{{id}}.json' + keyParam
}
},
layers: []
Expand Down Expand Up @@ -76,11 +79,14 @@
<h1 style="display:none;">{{name}}</h1>
<div id='map'></div>
<script>
var keyMatch = location.search.match(/[\?\&]key=([^&]+)/i);
var keyParam = keyMatch ? '?key=' + keyMatch[1] : '';

var map = L.map('map', { zoomControl: false });
new L.Control.Zoom({ position: 'topright' }).addTo(map);

var tile_urls = [], tile_attribution, tile_minzoom, tile_maxzoom;
var url = '{{public_url}}data/{{id}}.json{{&key_query}}';
var url = '{{public_url}}data/{{id}}.json' + keyParam;
var req = new XMLHttpRequest();
req.overrideMimeType("application/json");
req.open('GET', url, true);
Expand Down
9 changes: 5 additions & 4 deletions public/templates/viewer.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@
q.indexOf('vector') >= 0 ? 'vector' :
(q.indexOf('raster') >= 0 ? 'raster' :
(maplibregl.supported() ? 'vector' : 'raster'));

var keyMatch = location.search.match(/[\?\&]key=([^&]+)/i);
var key = keyMatch ? '?key=' + keyMatch[1] : '';
var keyParam = keyMatch ? '?key=' + keyMatch[1] : '';

if (preference == 'vector') {
maplibregl.setRTLTextPlugin('{{public_url}}mapbox-gl-rtl-text.js' + key);
maplibregl.setRTLTextPlugin('{{public_url}}mapbox-gl-rtl-text.js' + keyParam);
var map = new maplibregl.Map({
container: 'map',
style: '{{public_url}}styles/{{id}}/style.json' + key,
style: '{{public_url}}styles/{{id}}/style.json' + keyParam,
hash: true,
maplibreLogo: true
});
Expand All @@ -52,7 +53,7 @@
new L.Control.Zoom({ position: 'topright' }).addTo(map);

var tile_urls = [], tile_attribution, tile_minzoom, tile_maxzoom;
var url = '{{public_url}}styles/{{id}}.json' + key;
var url = '{{public_url}}styles/{{id}}.json' + keyParam;
var req = new XMLHttpRequest();
req.overrideMimeType("application/json");
req.open('GET', url, true);
Expand Down

0 comments on commit c71269e

Please sign in to comment.