Skip to content

FIRApp bundle ID validation: allow exact match for extensions #5531

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions FirebaseCore/Sources/FIRBundleUtil.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,19 @@ + (NSArray *)relevantURLSchemes {

+ (BOOL)hasBundleIdentifierPrefix:(NSString *)bundleIdentifier inBundles:(NSArray *)bundles {
for (NSBundle *bundle in bundles) {
// This allows app extensions that have the app's bundle as their prefix to pass this test.
NSString *applicationBundleIdentifier =
[GULAppEnvironmentUtil isAppExtension]
? [self bundleIdentifierByRemovingLastPartFrom:bundle.bundleIdentifier]
: bundle.bundleIdentifier;

if ([applicationBundleIdentifier isEqualToString:bundleIdentifier]) {
if ([bundle.bundleIdentifier isEqualToString:bundleIdentifier]) {
return YES;
}

if ([GULAppEnvironmentUtil isAppExtension]) {
// A developer could be using the same `FIROptions` for both their app and extension. Since
// extensions have a suffix added to the bundleID, we consider a matching prefix as valid.
NSString *appBundleIDFromExtension =
[self bundleIdentifierByRemovingLastPartFrom:bundle.bundleIdentifier];
if ([appBundleIDFromExtension isEqualToString:bundleIdentifier]) {
return YES;
}
}
}
return NO;
}
Expand Down
12 changes: 12 additions & 0 deletions FirebaseCore/Tests/Unit/FIRBundleUtilTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ - (void)testBundleIdentifierHasPrefixInBundlesForExtension {
[environmentUtilsMock stopMocking];
}

- (void)testBundleIdentifierExistsInBundlesForExtensions_exactMatch {
id environmentUtilsMock = [OCMockObject mockForClass:[GULAppEnvironmentUtil class]];
[[[environmentUtilsMock stub] andReturnValue:@(YES)] isAppExtension];

// Mock bundle should have what app extension has, the extension bundle ID.
[OCMStub([self.mockBundle bundleIdentifier]) andReturn:@"com.google.test.someextension"];
XCTAssertTrue([FIRBundleUtil hasBundleIdentifierPrefix:@"com.google.test.someextension"
inBundles:@[ self.mockBundle ]]);

[environmentUtilsMock stopMocking];
}

- (void)testBundleIdentifierHasPrefixInBundlesNotValidExtension {
id environmentUtilsMock = [OCMockObject mockForClass:[GULAppEnvironmentUtil class]];
[[[environmentUtilsMock stub] andReturnValue:@(YES)] isAppExtension];
Expand Down