@@ -576,43 +576,53 @@ public async Task<ContentTypeImportModel> Upload()
576
576
var fileName = file . Headers . ContentDisposition . FileName . Trim ( Constants . CharArrays . DoubleQuote ) ;
577
577
var ext = fileName . Substring ( fileName . LastIndexOf ( '.' ) + 1 ) . ToLower ( ) ;
578
578
579
- var destFileName = root + "\\ " + fileName ;
580
- try
581
- {
582
- // due to a bug before 8.7.0 we didn't delete temp files, so we need to make sure to delete before
583
- // moving else you get errors and the upload fails without a message in the UI (there's a JS error)
584
- if ( System . IO . File . Exists ( destFileName ) )
585
- System . IO . File . Delete ( destFileName ) ;
586
-
587
- // renaming the file because MultipartFormDataStreamProvider has created a random fileName instead of using the name from the
588
- // content-disposition for more than 6 years now. Creating a CustomMultipartDataStreamProvider deriving from MultipartFormDataStreamProvider
589
- // seems like a cleaner option, but I'm not sure where to put it and renaming only takes one line of code.
590
- System . IO . File . Move ( result . FileData [ 0 ] . LocalFileName , destFileName ) ;
591
- }
592
- catch ( Exception ex )
579
+ var destFileName = Path . Combine ( root , fileName ) ;
580
+ if ( Path . GetFullPath ( destFileName ) . StartsWith ( Path . GetFullPath ( root ) ) )
593
581
{
594
- Logger . Error < ContentTypeController , string > ( ex , "Error uploading udt file to App_Data: {File}" , destFileName ) ;
595
- }
596
-
597
- if ( ext . InvariantEquals ( "udt" ) )
598
- {
599
- model . TempFileName = Path . Combine ( root , fileName ) ;
582
+ try
583
+ {
584
+ // due to a bug before 8.7.0 we didn't delete temp files, so we need to make sure to delete before
585
+ // moving else you get errors and the upload fails without a message in the UI (there's a JS error)
586
+ if ( System . IO . File . Exists ( destFileName ) )
587
+ System . IO . File . Delete ( destFileName ) ;
588
+
589
+ // renaming the file because MultipartFormDataStreamProvider has created a random fileName instead of using the name from the
590
+ // content-disposition for more than 6 years now. Creating a CustomMultipartDataStreamProvider deriving from MultipartFormDataStreamProvider
591
+ // seems like a cleaner option, but I'm not sure where to put it and renaming only takes one line of code.
592
+ System . IO . File . Move ( result . FileData [ 0 ] . LocalFileName , destFileName ) ;
593
+ }
594
+ catch ( Exception ex )
595
+ {
596
+ Logger . Error < ContentTypeController , string > ( ex , "Error uploading udt file to App_Data: {File}" , destFileName ) ;
597
+ }
600
598
601
- var xd = new XmlDocument
599
+ if ( ext . InvariantEquals ( "udt" ) )
602
600
{
603
- XmlResolver = null
604
- } ;
605
- xd . Load ( model . TempFileName ) ;
601
+ model . TempFileName = destFileName ;
602
+
603
+ var xd = new XmlDocument
604
+ {
605
+ XmlResolver = null
606
+ } ;
607
+ xd . Load ( model . TempFileName ) ;
606
608
607
- model . Alias = xd . DocumentElement ? . SelectSingleNode ( "//DocumentType/Info/Alias" ) ? . FirstChild . Value ;
608
- model . Name = xd . DocumentElement ? . SelectSingleNode ( "//DocumentType/Info/Name" ) ? . FirstChild . Value ;
609
+ model . Alias = xd . DocumentElement ? . SelectSingleNode ( "//DocumentType/Info/Alias" ) ? . FirstChild . Value ;
610
+ model . Name = xd . DocumentElement ? . SelectSingleNode ( "//DocumentType/Info/Name" ) ? . FirstChild . Value ;
611
+ }
612
+ else
613
+ {
614
+ model . Notifications . Add ( new Notification (
615
+ Services . TextService . Localize ( "speechBubbles" , "operationFailedHeader" ) ,
616
+ Services . TextService . Localize ( "media" , "disallowedFileType" ) ,
617
+ NotificationStyle . Warning ) ) ;
618
+ }
609
619
}
610
620
else
611
621
{
612
622
model . Notifications . Add ( new Notification (
613
- Services . TextService . Localize ( "speechBubbles" , "operationFailedHeader" ) ,
614
- Services . TextService . Localize ( "media" , "disallowedFileType " ) ,
615
- NotificationStyle . Warning ) ) ;
623
+ Services . TextService . Localize ( "speechBubbles" , "operationFailedHeader" ) ,
624
+ Services . TextService . Localize ( "media" , "invalidFileName " ) ,
625
+ NotificationStyle . Warning ) ) ;
616
626
}
617
627
618
628
return model ;
0 commit comments