parse-community / node-apn

Apple Push Notification module for Node.js
Other
177 stars 64 forks source link

Reject payloads before they are sent to APNs if they're too large #31

Open TysonAndre opened 4 years ago

TysonAndre commented 4 years ago

Request ended with status 413 and responseData: {"reason":"PayloadTooLarge "}

https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html#//apple_ref/doc/uid/TP40008194-CH10-SW1 indicates that

  • For regular remote notifications, the maximum size is 4KB (4096 bytes)
  • For Voice over Internet Protocol (VoIP) notifications, the maximum size is 5KB (5120 bytes)

For example, add a default of 4096 bytes, and allow it to be overridden to a larger positive integer for VoIP or to account for future changes to APNs limits

If, for example, a client were to attempt to send a JSON payload that was 1 megabyte in size due to failing to truncate part of the input, it would be useful to prevent something that would definitely fail from being sent to APNs, especially if it blocked other requests to APNs or APNs server closes the connection (haven't checked if they currently do that).

(lib/provider.js is what does the final JSON.stringify)

parse-github-assistant[bot] commented 2 years ago

Thanks for opening this issue!