@@ -218,7 +218,7 @@ public static Map<String, Object> createFileFromScreen(DispatchContext dctx, Map
218218 Map <String , Object > screenContext = UtilGenerics .cast (serviceContext .remove ("screenContext" ));
219219 String contentType = (String ) serviceContext .remove ("contentType" );
220220 String filePath = (String ) serviceContext .remove ("filePath" );
221- String fileName = ( String ) serviceContext .remove ("fileName" );
221+ String fileName = new File (( String ) serviceContext .remove ("fileName" )). getName ( );
222222
223223 if (UtilValidate .isEmpty (screenContext )) {
224224 screenContext = new HashMap <>();
@@ -265,7 +265,12 @@ public static Map<String, Object> createFileFromScreen(DispatchContext dctx, Map
265265 if (UtilValidate .isEmpty (filePath )) {
266266 filePath = EntityUtilProperties .getPropertyValue ("content" , "content.output.path" , "/output" , delegator );
267267 }
268- File file = new File (filePath , fileName );
268+ File baseDir = new File (filePath ).getCanonicalFile ();
269+ File file = new File (baseDir , fileName ).getCanonicalFile ();
270+ if (!file .toPath ().startsWith (baseDir .toPath ())) {
271+ return ServiceUtil .returnError (UtilProperties .getMessage (RESOURCE , "ContentRenderingPathTraversalError" ,
272+ UtilMisc .toMap ("fileName" , fileName , "filePath" , filePath ), locale ));
273+ }
269274
270275 FileOutputStream fos = new FileOutputStream (file );
271276 fos .write (baos .toByteArray ());
0 commit comments