Skip to content

Commit

Permalink
- NSURL+OCURLNormalization:
Browse files Browse the repository at this point in the history
	- new property to normalize a file URL and return its path as string
	- new method to check if one file URL is the child of or identical to another URL
- OCVault:
	- use new normalization tools to reliably detect if a requested item's URL is within the vault (fixes owncloud/ios-app#1228)
  • Loading branch information
felix-schwarz committed Jun 21, 2023
1 parent a07fed5 commit e301f3d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
3 changes: 3 additions & 0 deletions ownCloudSDK/Categories/Foundation/NSURL+OCURLNormalization.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ NS_ASSUME_NONNULL_BEGIN

- (BOOL)hasSameSchemeHostAndPortAs:(NSURL *)otherURL;

@property(strong,nullable,readonly,nonatomic) NSString *standardizedFileURLPath;
- (BOOL)isIdenticalOrChildOf:(NSURL *)parentFileURL;

@end

NS_ASSUME_NONNULL_END
28 changes: 28 additions & 0 deletions ownCloudSDK/Categories/Foundation/NSURL+OCURLNormalization.m
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,32 @@ - (BOOL)hasSameSchemeHostAndPortAs:(NSURL *)otherURL
return ([otherURL.scheme isEqual:self.scheme] && [otherURL.host isEqual:self.host] && [otherURL.effectivePort isEqual:self.effectivePort]);
}

- (NSString *)standardizedFileURLPath
{
NSURL *url = self.URLByStandardizingPath;

if (url.isFileURL)
{
NSString *path = url.path;

if ([path hasPrefix:@"/private/"])
{
// Remove leading "/private/" - URLByStandardizingPath will only do this for files that *exist*, so not for f.ex. placeholders that *don't* exist
path = [path substringFromIndex:8];
}

return (path);
}

return (nil);
}

- (BOOL)isIdenticalOrChildOf:(NSURL *)parentFileURL
{
NSString *parentPath = parentFileURL.standardizedFileURLPath;
NSString *path = self.standardizedFileURLPath;

return ([path hasPrefix:parentPath]);
}

@end
7 changes: 4 additions & 3 deletions ownCloudSDK/Vaults/OCVault.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#import "NSArray+OCFiltering.h"
#import "GADrive.h"
#import "GADriveItem.h"
#import "NSURL+OCURLNormalization.h"

@implementation OCVault

Expand Down Expand Up @@ -1115,10 +1116,10 @@ + (NSURL *)httpPipelineRootURL
+ (nullable OCVaultLocation *)locationForURL:(NSURL *)url
{
OCVaultLocation *location = nil;
NSString *urlPath = url.URLByStandardizingPath.path;
NSString *storageRootPath = OCVault.storageRootURL.path.normalizedDirectoryPath;
NSString *urlPath = url.standardizedFileURLPath;
NSString *storageRootPath = OCVault.storageRootURL.standardizedFileURLPath.normalizedDirectoryPath;

if (![urlPath hasPrefix:storageRootPath])
if (![url isIdenticalOrChildOf:OCVault.storageRootURL])
{
// URL not in file provider's storage root path
return (nil);
Expand Down

0 comments on commit e301f3d

Please sign in to comment.