Skip to content

Commit 1ab19e7

Browse files
committed
msCGILoadMap(): do not load file pointed by CONTEXT= unless it validates new MS_CONTEXT_PATTERN configuration option (and doesn't validate MS_CONTEXT_BAD_PATTERN) (fixes #6779)
1 parent f6cc8a3 commit 1ab19e7

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

mapcontext.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ int msLoadMapContextLayerDimension(CPLXMLNode *psDimension, layerObj *layer)
664664
*/
665665
int msLoadMapContextGeneral(mapObj *map, CPLXMLNode *psGeneral,
666666
CPLXMLNode *psMapContext, int nVersion,
667-
char *filename)
667+
const char *filename)
668668
{
669669

670670
char *pszProj=NULL;
@@ -809,7 +809,7 @@ int msLoadMapContextGeneral(mapObj *map, CPLXMLNode *psGeneral,
809809
** Load a Layer block from a MapContext document
810810
*/
811811
int msLoadMapContextLayer(mapObj *map, CPLXMLNode *psLayer, int nVersion,
812-
char *filename, int unique_layer_names)
812+
const char *filename, int unique_layer_names)
813813
{
814814
char *pszValue;
815815
const char *pszHash;
@@ -1106,7 +1106,7 @@ int msLoadMapContextURL(mapObj *map, char *urlfilename, int unique_layer_names)
11061106
** (eg l:1:park. l:2:road ...). If It is set to MS_FALSE, the layer name
11071107
** would be the same name as the layer name in the context
11081108
*/
1109-
int msLoadMapContext(mapObj *map, char *filename, int unique_layer_names)
1109+
int msLoadMapContext(mapObj *map, const char *filename, int unique_layer_names)
11101110
{
11111111
#if defined(USE_WMS_LYR)
11121112
char *pszWholeText, *pszValue;

mapows.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ MS_DLL_EXPORT char *msWFSExecuteGetFeature(layerObj *lp);
551551

552552
MS_DLL_EXPORT int msWriteMapContext(mapObj *map, FILE *stream);
553553
MS_DLL_EXPORT int msSaveMapContext(mapObj *map, char *filename);
554-
MS_DLL_EXPORT int msLoadMapContext(mapObj *map, char *filename, int unique_layer_names);
554+
MS_DLL_EXPORT int msLoadMapContext(mapObj *map, const char *filename, int unique_layer_names);
555555
MS_DLL_EXPORT int msLoadMapContextURL(mapObj *map, char *urlfilename, int unique_layer_names);
556556

557557

mapservutil.c

+24-2
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,30 @@ mapObj *msCGILoadMap(mapservObj *mapserv)
303303
if(strncasecmp(mapserv->request->ParamValues[i],"http",4) == 0) {
304304
if(msGetConfigOption(map, "CGI_CONTEXT_URL"))
305305
msLoadMapContextURL(map, mapserv->request->ParamValues[i], MS_FALSE);
306-
} else
307-
msLoadMapContext(map, mapserv->request->ParamValues[i], MS_FALSE);
306+
} else {
307+
const char *map_context_filename = mapserv->request->ParamValues[i];
308+
const char *ms_context_pattern = CPLGetConfigOption("MS_CONTEXT_PATTERN", NULL);
309+
const char *ms_context_bad_pattern = CPLGetConfigOption("MS_CONTEXT_BAD_PATTERN", NULL);
310+
if(ms_context_bad_pattern == NULL) ms_context_bad_pattern = ms_map_bad_pattern_default;
311+
312+
if(ms_context_pattern == NULL) { // can't go any further, bail
313+
msSetError(MS_WEBERR, "Required configuration value MS_CONTEXT_PATTERN not set.", "msCGILoadMap()");
314+
msFreeMap(map);
315+
return NULL;
316+
}
317+
if(msIsValidRegex(ms_context_bad_pattern) == MS_FALSE ||
318+
msEvalRegex(ms_context_bad_pattern, map_context_filename) == MS_TRUE) {
319+
msSetError(MS_WEBERR, "CGI variable \"context\" fails to validate.", "msCGILoadMap()");
320+
msFreeMap(map);
321+
return NULL;
322+
}
323+
if(msEvalRegex(ms_context_pattern, map_context_filename) != MS_TRUE) {
324+
msSetError(MS_WEBERR, "CGI variable \"context\" fails to validate.", "msCGILoadMap()");
325+
msFreeMap(map);
326+
return NULL;
327+
}
328+
msLoadMapContext(map, map_context_filename, MS_FALSE);
329+
}
308330
}
309331
}
310332
}

0 commit comments

Comments
 (0)