@@ -77,7 +77,7 @@ @implementation GCDWebDAVServer
7777
7878- (instancetype )initWithUploadDirectory : (NSString *)path {
7979 if ((self = [super init ])) {
80- _uploadDirectory = [[ path stringByStandardizingPath ] copy ];
80+ _uploadDirectory = [path copy ];
8181 GCDWebDAVServer* __unsafe_unretained server = self;
8282
8383 // 9.1 PROPFIND method
@@ -157,11 +157,6 @@ - (instancetype)initWithUploadDirectory:(NSString*)path {
157157
158158@implementation GCDWebDAVServer (Methods)
159159
160- // Must match implementation in GCDWebUploader
161- - (BOOL )_checkSandboxedPath : (NSString *)path {
162- return [[path stringByStandardizingPath ] hasPrefix: _uploadDirectory];
163- }
164-
165160- (BOOL )_checkFileExtension : (NSString *)fileName {
166161 if (_allowedFileExtensions && ![_allowedFileExtensions containsObject: [[fileName pathExtension ] lowercaseString ]]) {
167162 return NO ;
@@ -186,9 +181,9 @@ - (GCDWebServerResponse*)performOPTIONS:(GCDWebServerRequest*)request {
186181
187182- (GCDWebServerResponse*)performGET : (GCDWebServerRequest*)request {
188183 NSString * relativePath = request.path ;
189- NSString * absolutePath = [_uploadDirectory stringByAppendingPathComponent: relativePath];
184+ NSString * absolutePath = [_uploadDirectory stringByAppendingPathComponent: GCDWebServerNormalizePath ( relativePath) ];
190185 BOOL isDirectory = NO ;
191- if (![self _checkSandboxedPath: absolutePath] || ![ [NSFileManager defaultManager ] fileExistsAtPath: absolutePath isDirectory: &isDirectory]) {
186+ if (![[NSFileManager defaultManager ] fileExistsAtPath: absolutePath isDirectory: &isDirectory]) {
192187 return [GCDWebServerErrorResponse responseWithClientError: kGCDWebServerHTTPStatusCode_NotFound message: @" \" %@ \" does not exist" , relativePath];
193188 }
194189
@@ -221,10 +216,7 @@ - (GCDWebServerResponse*)performPUT:(GCDWebServerFileRequest*)request {
221216 }
222217
223218 NSString * relativePath = request.path ;
224- NSString * absolutePath = [_uploadDirectory stringByAppendingPathComponent: relativePath];
225- if (![self _checkSandboxedPath: absolutePath]) {
226- return [GCDWebServerErrorResponse responseWithClientError: kGCDWebServerHTTPStatusCode_NotFound message: @" \" %@ \" does not exist" , relativePath];
227- }
219+ NSString * absolutePath = [_uploadDirectory stringByAppendingPathComponent: GCDWebServerNormalizePath (relativePath)];
228220 BOOL isDirectory;
229221 if (![[NSFileManager defaultManager ] fileExistsAtPath: [absolutePath stringByDeletingLastPathComponent ] isDirectory: &isDirectory] || !isDirectory) {
230222 return [GCDWebServerErrorResponse responseWithClientError: kGCDWebServerHTTPStatusCode_Conflict message: @" Missing intermediate collection(s) for \" %@ \" " , relativePath];
@@ -265,9 +257,9 @@ - (GCDWebServerResponse*)performDELETE:(GCDWebServerRequest*)request {
265257 }
266258
267259 NSString * relativePath = request.path ;
268- NSString * absolutePath = [_uploadDirectory stringByAppendingPathComponent: relativePath];
260+ NSString * absolutePath = [_uploadDirectory stringByAppendingPathComponent: GCDWebServerNormalizePath ( relativePath) ];
269261 BOOL isDirectory = NO ;
270- if (![self _checkSandboxedPath: absolutePath] || ![ [NSFileManager defaultManager ] fileExistsAtPath: absolutePath isDirectory: &isDirectory]) {
262+ if (![[NSFileManager defaultManager ] fileExistsAtPath: absolutePath isDirectory: &isDirectory]) {
271263 return [GCDWebServerErrorResponse responseWithClientError: kGCDWebServerHTTPStatusCode_NotFound message: @" \" %@ \" does not exist" , relativePath];
272264 }
273265
@@ -299,10 +291,7 @@ - (GCDWebServerResponse*)performMKCOL:(GCDWebServerDataRequest*)request {
299291 }
300292
301293 NSString * relativePath = request.path ;
302- NSString * absolutePath = [_uploadDirectory stringByAppendingPathComponent: relativePath];
303- if (![self _checkSandboxedPath: absolutePath]) {
304- return [GCDWebServerErrorResponse responseWithClientError: kGCDWebServerHTTPStatusCode_NotFound message: @" \" %@ \" does not exist" , relativePath];
305- }
294+ NSString * absolutePath = [_uploadDirectory stringByAppendingPathComponent: GCDWebServerNormalizePath (relativePath)];
306295 BOOL isDirectory;
307296 if (![[NSFileManager defaultManager ] fileExistsAtPath: [absolutePath stringByDeletingLastPathComponent ] isDirectory: &isDirectory] || !isDirectory) {
308297 return [GCDWebServerErrorResponse responseWithClientError: kGCDWebServerHTTPStatusCode_Conflict message: @" Missing intermediate collection(s) for \" %@ \" " , relativePath];
@@ -348,10 +337,7 @@ - (GCDWebServerResponse*)performCOPY:(GCDWebServerRequest*)request isMove:(BOOL)
348337 }
349338
350339 NSString * srcRelativePath = request.path ;
351- NSString * srcAbsolutePath = [_uploadDirectory stringByAppendingPathComponent: srcRelativePath];
352- if (![self _checkSandboxedPath: srcAbsolutePath]) {
353- return [GCDWebServerErrorResponse responseWithClientError: kGCDWebServerHTTPStatusCode_NotFound message: @" \" %@ \" does not exist" , srcRelativePath];
354- }
340+ NSString * srcAbsolutePath = [_uploadDirectory stringByAppendingPathComponent: GCDWebServerNormalizePath (srcRelativePath)];
355341
356342 NSString * dstRelativePath = [request.headers objectForKey: @" Destination" ];
357343 NSRange range = [dstRelativePath rangeOfString: (NSString *)[request.headers objectForKey: @" Host" ]];
@@ -362,8 +348,8 @@ - (GCDWebServerResponse*)performCOPY:(GCDWebServerRequest*)request isMove:(BOOL)
362348#pragma clang diagnostic ignored "-Wdeprecated-declarations"
363349 dstRelativePath = [[dstRelativePath substringFromIndex: (range.location + range.length)] stringByReplacingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
364350#pragma clang diagnostic pop
365- NSString * dstAbsolutePath = [_uploadDirectory stringByAppendingPathComponent: dstRelativePath];
366- if (![ self _checkSandboxedPath: dstAbsolutePath] ) {
351+ NSString * dstAbsolutePath = [_uploadDirectory stringByAppendingPathComponent: GCDWebServerNormalizePath ( dstRelativePath) ];
352+ if (!dstAbsolutePath) {
367353 return [GCDWebServerErrorResponse responseWithClientError: kGCDWebServerHTTPStatusCode_NotFound message: @" \" %@ \" does not exist" , srcRelativePath];
368354 }
369355
@@ -532,9 +518,9 @@ - (GCDWebServerResponse*)performPROPFIND:(GCDWebServerDataRequest*)request {
532518 }
533519
534520 NSString * relativePath = request.path ;
535- NSString * absolutePath = [_uploadDirectory stringByAppendingPathComponent: relativePath];
521+ NSString * absolutePath = [_uploadDirectory stringByAppendingPathComponent: GCDWebServerNormalizePath ( relativePath) ];
536522 BOOL isDirectory = NO ;
537- if (![self _checkSandboxedPath: absolutePath] || ![ [NSFileManager defaultManager ] fileExistsAtPath: absolutePath isDirectory: &isDirectory]) {
523+ if (![[NSFileManager defaultManager ] fileExistsAtPath: absolutePath isDirectory: &isDirectory]) {
538524 return [GCDWebServerErrorResponse responseWithClientError: kGCDWebServerHTTPStatusCode_NotFound message: @" \" %@ \" does not exist" , relativePath];
539525 }
540526
@@ -582,9 +568,9 @@ - (GCDWebServerResponse*)performLOCK:(GCDWebServerDataRequest*)request {
582568 }
583569
584570 NSString * relativePath = request.path ;
585- NSString * absolutePath = [_uploadDirectory stringByAppendingPathComponent: relativePath];
571+ NSString * absolutePath = [_uploadDirectory stringByAppendingPathComponent: GCDWebServerNormalizePath ( relativePath) ];
586572 BOOL isDirectory = NO ;
587- if (![self _checkSandboxedPath: absolutePath] || ![ [NSFileManager defaultManager ] fileExistsAtPath: absolutePath isDirectory: &isDirectory]) {
573+ if (![[NSFileManager defaultManager ] fileExistsAtPath: absolutePath isDirectory: &isDirectory]) {
588574 return [GCDWebServerErrorResponse responseWithClientError: kGCDWebServerHTTPStatusCode_NotFound message: @" \" %@ \" does not exist" , relativePath];
589575 }
590576
@@ -679,9 +665,9 @@ - (GCDWebServerResponse*)performUNLOCK:(GCDWebServerRequest*)request {
679665 }
680666
681667 NSString * relativePath = request.path ;
682- NSString * absolutePath = [_uploadDirectory stringByAppendingPathComponent: relativePath];
668+ NSString * absolutePath = [_uploadDirectory stringByAppendingPathComponent: GCDWebServerNormalizePath ( relativePath) ];
683669 BOOL isDirectory = NO ;
684- if (![self _checkSandboxedPath: absolutePath] || ![ [NSFileManager defaultManager ] fileExistsAtPath: absolutePath isDirectory: &isDirectory]) {
670+ if (![[NSFileManager defaultManager ] fileExistsAtPath: absolutePath isDirectory: &isDirectory]) {
685671 return [GCDWebServerErrorResponse responseWithClientError: kGCDWebServerHTTPStatusCode_NotFound message: @" \" %@ \" does not exist" , relativePath];
686672 }
687673
0 commit comments