type-check fcm_options before building image URL in extension helper - #16464
type-check fcm_options before building image URL in extension helper#16464isl-Ramzi wants to merge 2 commits into
Conversation
Using Gemini Code AssistThe 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
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 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. |
|
/gemini review |
There was a problem hiding this comment.
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.
|
/gemini review |
There was a problem hiding this comment.
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.
| NSObject *fcmOptions = content.userInfo[kPayloadOptionsName]; | ||
| NSObject *currentImageURL = [fcmOptions isKindOfClass:[NSDictionary class]] | ||
| ? ((NSDictionary *)fcmOptions)[kPayloadOptionsImageURLName] | ||
| : nil; |
There was a problem hiding this comment.
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];
}
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.