Skip to content

Commit

Permalink
fix: use modern URL() and also 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 e879ecd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
12 changes: 10 additions & 2 deletions public/templates/data.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
<div id="layerList"></div>
<pre id="propertyList"></pre>
<script>
const { searchParams } = new URL(document.location);
const accessKey = searchParams.get('key');
const keyParam = accessKey ? `?key=${accessKey}` : '';

var map = new maplibregl.Map({
container: 'map',
hash: true,
Expand All @@ -44,7 +48,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 +80,15 @@
<h1 style="display:none;">{{name}}</h1>
<div id='map'></div>
<script>
const { searchParams } = new URL(document.location);
const accessKey = searchParams.get('key');
const keyParam = accessKey ? `?key=${accessKey}` : '';

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
12 changes: 7 additions & 5 deletions public/templates/viewer.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@
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] : '';

const { searchParams } = new URL(document.location);
const accessKey = searchParams.get('key');
const keyParam = accessKey ? `?key=${accessKey}` : '';

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 +54,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 e879ecd

Please sign in to comment.