Skip to content

type-check fcm_options before building image URL in extension helper - #16464

Open
isl-Ramzi wants to merge 2 commits into
firebase:mainfrom
isl-Ramzi:fcm-options-type-guard
Open

type-check fcm_options before building image URL in extension helper#16464
isl-Ramzi wants to merge 2 commits into
firebase:mainfrom
isl-Ramzi:fcm-options-type-guard

Conversation

@isl-Ramzi

Copy link
Copy Markdown
Contributor

populateNotificationContent reads the image URL from the remote push payload with a chained subscript content.userInfo[@"fcm_options"][@"image"], but a sender can set fcm_options to any JSON type, so a non-dictionary value (string, number, array) reaches objectForKeyedSubscript: on a class that does not implement it and the notification service extension aborts with NSInvalidArgumentException; a dictionary whose image entry is not a string hits the same problem one line later at URLWithString:. The rest of the module already guards untrusted payload dictionaries with isKindOfClass before subscripting (FIRMessaging.m, FIRMessagingAnalytics.m), so I read image only when fcm_options is a dictionary and proceed only when image is a string. Added two tests covering a non-dictionary fcm_options and a non-string image.

@gemini-code-assist

Copy link
Copy Markdown
Contributor
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

@ncooke3 ncooke3 self-assigned this Jul 29, 2026
@ncooke3
ncooke3 self-requested a review July 29, 2026 21:07
@paulb777

Copy link
Copy Markdown
Member

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds type safety checks to FIRMessagingExtensionHelper to ensure that fcm_options is a dictionary and the image URL is a string before processing, preventing potential exceptions from malformed payloads. It also adds corresponding unit tests. The review feedback correctly points out that in both new tests, the OCMReject expectations are set up after the method under test is invoked, which should be corrected to ensure synchronous calls are properly caught.

Comment thread FirebaseMessaging/Tests/UnitTests/FIRMessagingExtensionHelperTest.m Outdated
Comment thread FirebaseMessaging/Tests/UnitTests/FIRMessagingExtensionHelperTest.m Outdated
@paulb777

Copy link
Copy Markdown
Member

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces safety checks in FIRMessagingExtensionHelper.m to ensure that fcm_options is a dictionary and the image URL is a string before processing, preventing potential crashes from unexpected JSON types in the push payload. It also adds corresponding unit tests. The reviewer suggested using id instead of NSObject * to avoid explicit casting and replacing the ternary operator with an if statement to improve readability.

Comment on lines +119 to +122
NSObject *fcmOptions = content.userInfo[kPayloadOptionsName];
NSObject *currentImageURL = [fcmOptions isKindOfClass:[NSDictionary class]]
? ((NSDictionary *)fcmOptions)[kPayloadOptionsImageURLName]
: nil;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low

Using id instead of NSObject * for dynamically typed JSON payloads allows you to subscript the dictionary directly without explicit casting. Additionally, replacing the ternary operator with a simple if statement improves readability.

  id fcmOptions = content.userInfo[kPayloadOptionsName];
  id currentImageURL = nil;
  if ([fcmOptions isKindOfClass:[NSDictionary class]]) {
    currentImageURL = fcmOptions[kPayloadOptionsImageURLName];
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants