Skip to content

177469304: Firebase dynamic links with custom domain will only work if the custom domai has a trailing '/' #7087

Closed
@superrsage

Description

@superrsage

[REQUIRED] Step 1: Describe your environment

  • Xcode version: 12.2
  • Firebase SDK version: 6.31.1
  • Installation method: CocoaPods (select one)
  • Firebase Component: DynamicLinks

[REQUIRED] Step 2: Describe the problem

Steps to reproduce:

Using a custom sub domain for dynamic links (like links.example.com) doesn't work. The piece of code below from the firebase library is checking for a trailing '/' at the end of the host. See the line:

if (urlStr.length > domainURIPrefixStr.length + 1 && ([urlStr characterAtIndex:domainURIPrefixStr.length] == '/'))

Why is this check necessary? This check will only allow custom domains that have a trailing '/'

Relevant Code:

BOOL FIRDLIsURLForWhiteListedCustomDomain(NSURL *_Nullable URL) {
  BOOL customDomainMatchFound = false;
  for (NSURL *allowedCustomDomain in FIRDLCustomDomains) {
    // All custom domain host names should match at a minimum.
    if ([allowedCustomDomain.host isEqualToString:URL.host]) {
      NSString *urlStr = URL.absoluteString;
      NSString *domainURIPrefixStr = allowedCustomDomain.absoluteString;

      // Next, do a string compare to check if entire domainURIPrefix matches as well.
      if (([URL.absoluteString rangeOfString:allowedCustomDomain.absoluteString
                                     options:NSCaseInsensitiveSearch | NSAnchoredSearch]
               .location) == 0) {
        // The (short) URL needs to be longer than the domainURIPrefix, it's first character after
        // the domainURIPrefix needs to be '/' and should be followed by at-least one more
        // character.
        if (urlStr.length > domainURIPrefixStr.length + 1 &&
            ([urlStr characterAtIndex:domainURIPrefixStr.length] == '/')) {
          // Check if there are any more '/' after the first '/'trailing the
          // domainURIPrefix. This does not apply to unique match links copied from the clipboard.
          // The clipboard links will have '?link=' after the domainURIPrefix.
          NSString *urlWithoutDomainURIPrefix =
              [urlStr substringFromIndex:domainURIPrefixStr.length + 1];
          if ([urlWithoutDomainURIPrefix rangeOfString:@"/"].location == NSNotFound ||
              [urlWithoutDomainURIPrefix rangeOfString:@"?link="].location != NSNotFound) {
            customDomainMatchFound = true;
            break;
          }
        }
      }
    }
  }
  return customDomainMatchFound;
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions