@@ -6,6 +6,8 @@ class GeomapError extends MapSourceError {}
6
6
// CSV source file handling
7
7
//
8
8
9
+ const ACCEPTED_GEOMAP_SERVER_URL_SCHEMES = ["http " , "https " ];
10
+
9
11
function geomap_source_file ($ p ) {
10
12
return cfg ('paths ' , 'geomap ' ) . '/ ' . $ p ['source_file ' ] . '.csv ' ;
11
13
}
@@ -120,6 +122,7 @@ function geomap_get_contents($url) {
120
122
'http ' => array (
121
123
'timeout ' => cfg ('global ' , 'http_timeout ' ),
122
124
'user_agent ' => 'NagVis ' .CONST_VERSION .' geomap ' ,
125
+ 'max_redirects ' => 0 ,
123
126
)
124
127
);
125
128
@@ -268,6 +271,33 @@ function geomap_files($params) {
268
271
);
269
272
}
270
273
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
+
271
301
function process_geomap ($ MAPCFG , $ map_name , &$ map_config ) {
272
302
$ params = $ MAPCFG ->getSourceParams ();
273
303
list ($ image_name , $ image_path , $ data_path ) = geomap_files ($ params );
@@ -354,7 +384,9 @@ function process_geomap($MAPCFG, $map_name, &$map_config) {
354
384
throw new GeomapError (l ('Missing mandatory "width" and "height" parameters." ' ));
355
385
356
386
// 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
358
390
.'?module=map '
359
391
.'&width= ' .$ params ['width ' ].'&height= ' .$ params ['height ' ]
360
392
.'&type= ' .$ params ['geomap_type ' ];
0 commit comments