You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by dp...@apache.org on 2024/08/21 17:13:23 UTC
(cordova-ios) branch master updated: fix: Update CDVAllowList to support more valid schemes (#1473)
This is an automated email from the ASF dual-hosted git repository.
dpogue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-ios.git
The following commit(s) were added to refs/heads/master by this push:
new f3339a9e fix: Update CDVAllowList to support more valid schemes (#1473)
f3339a9e is described below
commit f3339a9eebae2a3c532eea9b1bd4b62cb4c46b2d
Author: Darryl Pogue <da...@dpogue.ca>
AuthorDate: Wed Aug 21 10:13:18 2024 -0700
fix: Update CDVAllowList to support more valid schemes (#1473)
These may be unusual schemes, but they are canonically valid and should
be supported.
Closes GH-1291.
---
.../Plugins/CDVIntentAndNavigationFilter/CDVAllowList.m | 8 ++++----
tests/CordovaLibTests/CDVAllowListTests.m | 15 +++++++++++++++
2 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/CordovaLib/Classes/Private/Plugins/CDVIntentAndNavigationFilter/CDVAllowList.m b/CordovaLib/Classes/Private/Plugins/CDVIntentAndNavigationFilter/CDVAllowList.m
index a0ce668e..11567d26 100644
--- a/CordovaLib/Classes/Private/Plugins/CDVIntentAndNavigationFilter/CDVAllowList.m
+++ b/CordovaLib/Classes/Private/Plugins/CDVIntentAndNavigationFilter/CDVAllowList.m
@@ -169,7 +169,7 @@ NSString* const kCDVDefaultSchemeName = @"cdv-default-scheme";
self.allowList = nil;
self.permittedSchemes = nil;
} else { // specific access
- NSRegularExpression* parts = [NSRegularExpression regularExpressionWithPattern:@"^((\\*|[A-Za-z-]+):/?/?)?(((\\*\\.)?[^*/:]+)|\\*)?(:(\\d+))?(/.*)?" options:0 error:nil];
+ NSRegularExpression* parts = [NSRegularExpression regularExpressionWithPattern:@"^((\\*|([a-z][a-z0-9+\\-.]*)):/?/?)?(((\\*\\.)?[^*/:]+)|\\*)?(:(\\d+))?(/.*)?" options:0 error:nil];
NSTextCheckingResult* m = [parts firstMatchInString:origin options:NSMatchingAnchored range:NSMakeRange(0, [origin length])];
if (m != nil) {
NSRange r;
@@ -180,7 +180,7 @@ NSString* const kCDVDefaultSchemeName = @"cdv-default-scheme";
}
NSString* host = nil;
- r = [m rangeAtIndex:3];
+ r = [m rangeAtIndex:4];
if (r.location != NSNotFound) {
host = [origin substringWithRange:r];
}
@@ -191,13 +191,13 @@ NSString* const kCDVDefaultSchemeName = @"cdv-default-scheme";
}
NSString* port = nil;
- r = [m rangeAtIndex:7];
+ r = [m rangeAtIndex:8];
if (r.location != NSNotFound) {
port = [origin substringWithRange:r];
}
NSString* path = nil;
- r = [m rangeAtIndex:8];
+ r = [m rangeAtIndex:9];
if (r.location != NSNotFound) {
path = [origin substringWithRange:r];
}
diff --git a/tests/CordovaLibTests/CDVAllowListTests.m b/tests/CordovaLibTests/CDVAllowListTests.m
index d823614e..a6a771ef 100644
--- a/tests/CordovaLibTests/CDVAllowListTests.m
+++ b/tests/CordovaLibTests/CDVAllowListTests.m
@@ -209,6 +209,21 @@
XCTAssertTrue([expectedErrorString isEqualToString:errorString], @"Customized allowList rejection string has unexpected value.");
}
+- (void)testUnusualSchemes
+{
+ NSArray* allowedHosts = [NSArray arrayWithObjects:
+ @"com.myapp://*",
+ @"web+app://*",
+ @"a12345://*",
+ nil];
+
+ CDVAllowList* allowList = [[CDVAllowList alloc] initWithArray:allowedHosts];
+
+ XCTAssertTrue([allowList URLIsAllowed:[NSURL URLWithString:@"com.myapp://www.apache.org"]]);
+ XCTAssertTrue([allowList URLIsAllowed:[NSURL URLWithString:@"web+app://www.apache.org"]]);
+ XCTAssertTrue([allowList URLIsAllowed:[NSURL URLWithString:@"a12345://www.apache.org"]]);
+}
+
- (void)testSpecificProtocol
{
NSArray* allowedHosts = [NSArray arrayWithObjects:
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org