Skip to content

Commit 0fe6547

Browse files
dontqwertyLarsMichelsen
authored andcommitted
Fix #319
1 parent f795de3 commit 0fe6547

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

share/server/core/sources/geomap.php

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ class GeomapError extends MapSourceError {}
66
// CSV source file handling
77
//
88

9+
const ACCEPTED_GEOMAP_SERVER_URL_SCHEMES = ["http", "https"];
10+
911
function geomap_source_file($p) {
1012
return cfg('paths', 'geomap') . '/' . $p['source_file'] . '.csv';
1113
}
@@ -120,6 +122,7 @@ function geomap_get_contents($url) {
120122
'http' => array(
121123
'timeout' => cfg('global', 'http_timeout'),
122124
'user_agent' => 'NagVis '.CONST_VERSION.' geomap',
125+
'max_redirects' => 0,
123126
)
124127
);
125128

@@ -268,6 +271,33 @@ function geomap_files($params) {
268271
);
269272
}
270273

274+
function validate_geomap_server_base_url($url) {
275+
# If the given url contains non standard URL characters, throw an error
276+
$sanitized_url = filter_var($url, FILTER_SANITIZE_URL);
277+
if ($sanitized_url !== $url) {
278+
throw new GeomapError(l('Geomap server URL contains not allowed characters. Url: "[U]"',
279+
array('U' => $url)));
280+
}
281+
282+
$url_scheme = parse_url($url, PHP_URL_SCHEME);
283+
if (!$url_scheme || !in_array(strtolower($url_scheme), ACCEPTED_GEOMAP_SERVER_URL_SCHEMES)) {
284+
throw new GeomapError(l('Invalid scheme in Geomap server URL: "[U]"',
285+
array('U' => $url)));
286+
}
287+
288+
$url_query = parse_url($url, PHP_URL_QUERY);
289+
if (!empty($url_query)) {
290+
throw new GeomapError(l('Geomap server cannot contain query parameters. URL: "[U]"',
291+
array('U' => $url)));
292+
}
293+
294+
$url_fragment = parse_url($url, PHP_URL_FRAGMENT);
295+
if (!empty($url_fragment)) {
296+
throw new GeomapError(l('Geomap server cannot contain anchors. URL: "[U]"',
297+
array('U' => $url)));
298+
}
299+
}
300+
271301
function process_geomap($MAPCFG, $map_name, &$map_config) {
272302
$params = $MAPCFG->getSourceParams();
273303
list($image_name, $image_path, $data_path) = geomap_files($params);
@@ -354,7 +384,9 @@ function process_geomap($MAPCFG, $map_name, &$map_config) {
354384
throw new GeomapError(l('Missing mandatory "width" and "height" parameters."'));
355385

356386
// Using this API: http://pafciu17.dev.openstreetmap.org/
357-
$url = cfg('global', 'geomap_server')
387+
$geomap_server_base_url = cfg('global', 'geomap_server');
388+
validate_geomap_server_base_url($geomap_server_base_url);
389+
$url = $geomap_server_base_url
358390
.'?module=map'
359391
.'&width='.$params['width'].'&height='.$params['height']
360392
.'&type='.$params['geomap_type'];

0 commit comments

Comments
 (0)