@@ -75,6 +75,7 @@ struct mapcache_cache_sqlite {
7575 * top_fmt ,* top_x_fmt ,* top_y_fmt ,* inv_top_x_fmt ,* inv_top_y_fmt ;
7676 int count_x , count_y ;
7777 int top ;
78+ int allow_path_in_dim ;
7879};
7980
8081
@@ -234,8 +235,25 @@ static void _mapcache_cache_sqlite_filename_for_tile(mapcache_context *ctx, mapc
234235 int i = tile -> dimensions -> nelts ;
235236 while (i -- ) {
236237 mapcache_requested_dimension * entry = APR_ARRAY_IDX (tile -> dimensions ,i ,mapcache_requested_dimension * );
237- const char * dimval = mapcache_util_str_sanitize (ctx -> pool ,entry -> cached_value ,"/." ,'#' );
238- char * single_dim = apr_pstrcat (ctx -> pool ,"{dim:" ,entry -> dimension -> name ,"}" ,NULL );
238+ mapcache_dimension_type dimtype = entry -> dimension -> type ;
239+ const char * dimval ;
240+ char * single_dim ;
241+ if (dcache -> allow_path_in_dim
242+ && (dimtype == MAPCACHE_DIMENSION_POSTGRESQL
243+ || dimtype == MAPCACHE_DIMENSION_SQLITE
244+ || dimtype == MAPCACHE_DIMENSION_ELASTICSEARCH ))
245+ {
246+ // Only if paths are allowed in dimension values and dimension is a second level type
247+ // Forbid "../" in the dimension value
248+ dimval = mapcache_util_str_replace_all (ctx -> pool , entry -> cached_value , "../" , "#" );
249+ }
250+ else
251+ {
252+ // If paths are not allowed in dimension values or if dimension is not a second level type
253+ // Forbid '.' and '/' in the dimension value
254+ dimval = mapcache_util_str_sanitize (ctx -> pool ,entry -> cached_value ,"/." ,'#' );
255+ }
256+ single_dim = apr_pstrcat (ctx -> pool ,"{dim:" ,entry -> dimension -> name ,"}" ,NULL );
239257 dimstring = apr_pstrcat (ctx -> pool ,dimstring ,"#" ,dimval ,NULL );
240258 if (strstr (* path ,single_dim )) {
241259 * path = mapcache_util_str_replace (ctx -> pool ,* path , single_dim , dimval );
@@ -856,6 +874,7 @@ static void _mapcache_cache_sqlite_configuration_parse_xml(mapcache_context *ctx
856874{
857875 ezxml_t cur_node ;
858876 mapcache_cache_sqlite * cache ;
877+ char * attr ;
859878 sqlite3_initialize ();
860879 sqlite3_config (SQLITE_CONFIG_MULTITHREAD );
861880 cache = (mapcache_cache_sqlite * ) pcache ;
@@ -867,6 +886,11 @@ static void _mapcache_cache_sqlite_configuration_parse_xml(mapcache_context *ctx
867886 ctx -> set_error (ctx , 500 , "sqlite config <dbname_template> not supported anymore, use a \"multi-sqlite3\" cache type" );
868887 return ;
869888 }
889+ cache -> allow_path_in_dim = 0 ;
890+ attr = (char * )ezxml_attr (node ,"allow_path_in_dim" );
891+ if (attr && * attr && !strcmp (attr ,"yes" )) {
892+ cache -> allow_path_in_dim = 1 ;
893+ }
870894 if ((cur_node = ezxml_child (node , "dbfile" )) != NULL ) {
871895 char * fmt ;
872896 cache -> dbfile = apr_pstrdup (ctx -> pool , cur_node -> txt );
0 commit comments