Repository navigation
fix(messaging): tolerate non-string fields, non-list locArgs, and epoch-seconds sentTime in RemoteMessage.fromMap - #18828
Conversation
…ch-seconds sentTime in RemoteMessage.fromMap
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. |
Description
Hardens
RemoteMessage.fromMap(packages/firebase_messaging/firebase_messaging_platform_interface/lib/src/remote_message.dart) andRemoteNotification.fromMap/AndroidNotification.fromMap/AppleNotification.fromMap/AppleNotificationSound.fromMap/WebNotification.fromMap(packages/firebase_messaging/firebase_messaging_platform_interface/lib/src/remote_notification.dart) against non-string scalar values, non-listlocArgs, and epoch-seconds or non-integersentTimevalues across platform channels.Why this is needed
RemoteMessage.fromMapalready used?.toString()formessageId(map['messageId']?.toString(), with the comment "using toString on messageId as it can be an int or string when being sent from native"), because APNs and platform channels can deserialize numeric JSON/plist values (senderId,category,collapseKey,badge,title,body, etc.) asnumorboolrather thanString. However, all other string fields onRemoteMessageandRemoteNotificationperformed implicitdynamic as String?casts, and_toListcalledList<String>.from(value)directly (throwingTypeErroriflocArgsis a single scalar or contains non-string elements such as numbers).sentTime,RemoteMessage.fromMappreviously ran:FLTFirebaseMessagingPlugin.m),sentTimeis extracted from APNsuserInfo[@"google.c.a.ts"], which is a 10-digit Unix timestamp in seconds (whereas Android'sRemoteMessage.getSentTime()is in milliseconds). Interpreting a 10-digit seconds value directly as milliseconds produces aDateTimein January 1970 (1970-01-20).sentTimeis a non-integer string,int.parsethrows an uncaughtFormatExceptionduring message delivery.Why this does not break existing SDK behavior
String,bool,int,num,List<String>, andMapvalues produce the exact sameRemoteMessageandRemoteNotificationfields as before (including all 99 existing unit tests infirebase_messaging_platform_interface).sentTimevalues (and0or negative values) are unchanged; only positive timestamps strictly below10000000000(10^10, i.e., 10-digit epoch seconds) are multiplied by1000to convert seconds to milliseconds, and unparseable/out-of-range values returnnullinstead of throwingFormatExceptionorArgumentError.Verification
387c707b2with only the new tests):flutter test --no-pubfails with:a2be89cbb):dart format --output=none --set-exit-if-changed .(0 changes)dart analyze --fatal-infos .(0 issues)flutter test --no-pubinfirebase_messaging_platform_interface(101 passed, 0 failed)Related Issues
N/A
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]).This will ensure a smooth and quick review process. Updating the
pubspec.yamland changelogs is not required.///).melos run analyze) does not report any problems on my PR.Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?