@@ -21,7 +21,7 @@ import {
21
21
Message , validateMessage , MessagingDevicesResponse ,
22
22
MessagingDeviceGroupResponse , MessagingTopicManagementResponse ,
23
23
MessagingPayload , MessagingOptions , MessagingTopicResponse ,
24
- MessagingConditionResponse , BatchResponse , MulticastMessage ,
24
+ MessagingConditionResponse , BatchResponse , MulticastMessage , DataMessagePayload , NotificationMessagePayload ,
25
25
} from './messaging-types' ;
26
26
import { FirebaseMessagingRequestHandler } from './messaging-api-request' ;
27
27
import { FirebaseServiceInterface , FirebaseServiceInternalsInterface } from '../firebase-service' ;
@@ -758,9 +758,7 @@ export class Messaging implements FirebaseServiceInterface {
758
758
) ;
759
759
}
760
760
761
- payloadKeys . forEach ( ( payloadKey : keyof MessagingPayload ) => {
762
- const value = payloadCopy [ payloadKey ] ;
763
-
761
+ const validatePayload = ( payloadKey : string , value : DataMessagePayload | NotificationMessagePayload ) => {
764
762
// Validate each top-level key in the payload is an object
765
763
if ( ! validator . isNonNullObject ( value ) ) {
766
764
throw new FirebaseMessagingError (
@@ -786,7 +784,14 @@ export class Messaging implements FirebaseServiceInterface {
786
784
) ;
787
785
}
788
786
} ) ;
789
- } ) ;
787
+ } ;
788
+
789
+ if ( payloadCopy . data !== undefined ) {
790
+ validatePayload ( 'data' , payloadCopy . data ) ;
791
+ }
792
+ if ( payloadCopy . notification !== undefined ) {
793
+ validatePayload ( 'notification' , payloadCopy . notification ) ;
794
+ }
790
795
791
796
// Validate the data payload object does not contain blacklisted properties
792
797
if ( 'data' in payloadCopy ) {
0 commit comments