@@ -201,37 +201,46 @@ BOOL FIRDLOSVersionSupported(NSString *_Nullable systemVersion, NSString *minSup
201
201
return timeZoneName;
202
202
}
203
203
204
- BOOL FIRDLIsURLForAllowedCustomDomain (NSURL *_Nullable URL) {
205
- BOOL customDomainMatchFound = false ;
206
- for (NSURL *allowedCustomDomain in FIRDLCustomDomains) {
207
- // At least one custom domain host name should match at a minimum.
208
- if ([allowedCustomDomain.host isEqualToString: URL.host]) {
209
- NSString *urlStr = URL.absoluteString ;
210
- NSString *domainURIPrefixStr = allowedCustomDomain.absoluteString ;
211
-
212
- // Next, do a string compare to check if entire domainURIPrefix matches as well.
213
- if (([urlStr rangeOfString: domainURIPrefixStr
214
- options: NSCaseInsensitiveSearch | NSAnchoredSearch]
215
- .location ) == 0 ) {
216
- NSString *urlWithoutDomainURIPrefix = [urlStr substringFromIndex: domainURIPrefixStr.length];
217
-
218
- // For a valid custom domain DL Suffix:
219
- // 1. At least one path exists OR
220
- // 2. Should have a link query param with an http/https link
221
- BOOL matchesRegularExpression =
222
- ([urlWithoutDomainURIPrefix
223
- rangeOfString: @" ((\\ /[A-Za-z0-9]+)|((\\ ?|\\ /\\ ?)link=https?.*))"
224
- options: NSRegularExpressionSearch]
225
- .location != NSNotFound );
226
-
227
- if (matchesRegularExpression) {
228
- customDomainMatchFound = true ;
229
- break ;
204
+ BOOL FIRDLIsURLForAllowedCustomDomain (NSURL *URL) {
205
+ if (URL) {
206
+ for (NSURL *allowedCustomDomain in FIRDLCustomDomains) {
207
+ // At least one custom domain host name should match at a minimum.
208
+ if ([URL.absoluteString hasPrefix: allowedCustomDomain.absoluteString]) {
209
+ NSString *urlWithoutDomainURIPrefix =
210
+ [URL.absoluteString substringFromIndex: allowedCustomDomain.absoluteString.length];
211
+
212
+ // The urlWithoutDomainURIPrefix should be starting with '/' or '?' otherwise it means the
213
+ // allowed domain is not exactly matching the incoming URL domain prefix.
214
+ if ([urlWithoutDomainURIPrefix hasPrefix: @" /" ] ||
215
+ [urlWithoutDomainURIPrefix hasPrefix: @" ?" ]) {
216
+ // For a valid custom domain DL Suffix the urlWithoutDomainURIPrefix should have:
217
+ // 1. At least one path exists OR
218
+ // 2. Should have a link query param with an http/https link
219
+
220
+ NSURLComponents *components =
221
+ [[NSURLComponents alloc ] initWithString: urlWithoutDomainURIPrefix];
222
+ if (components.path && components.path .length > 1 ) {
223
+ // Have a path exists. So valid custom domain.
224
+ return true ;
225
+ }
226
+
227
+ if (components.queryItems && components.queryItems .count > 0 ) {
228
+ for (NSURLQueryItem *queryItem in components.queryItems ) {
229
+ // Checks whether we have a link query param
230
+ if ([queryItem.name caseInsensitiveCompare: @" link" ] == NSOrderedSame) {
231
+ // Checks whether link query param value starts with http/https
232
+ if (queryItem.value && ([queryItem.value hasPrefix: @" http://" ] ||
233
+ [queryItem.value hasPrefix: @" https://" ])) {
234
+ return true ;
235
+ }
236
+ }
237
+ }
238
+ }
230
239
}
231
240
}
232
241
}
233
242
}
234
- return customDomainMatchFound ;
243
+ return false ;
235
244
}
236
245
237
246
/* We are validating following domains in proper format.
0 commit comments