Search code examples
push-notificationpushmozillaweb-push

Mozilla Push Service: 413 - Request Entity Too Large


I'm sending push notifications to Mozilla's Push Service:

https://updates.push.services.mozilla.com/wpush/v1/...

This is working really well for a long time now, but since two weeks I get an 413 - Request Entity Too Large for one (and only this one) of the consumers.

I searched the web for that error message, but all I found was the limit of 4KB for most of the push services. But the payload I am sending is much smaller:

{
    "Titel": "New calendar entry from subdomain.domain.com",
    "Text": "A new entry has been made by firstname lastname in the calendar your-calendar-name on 2021/02/03.",
    "Icon": "https:\/\/subdomain.domain.com\/version\/webapp\/icon192.png",
    "URL": "https:\/\/subdomain.domain.com\/calendar\/event\/15578"
}

So my question is: what can cause this Request Entity Too Large error when I'm sending a payload that's under 4KB?


Solution

  • I came across something very like this problem today. The cause of the problem was Firefox for Android, which behaves differently from Firefox for desktop. URLs for the desktop version are like this: https://updates.push.services.mozilla.com/wpush/v2/[something] The android version URLs are like this: https://updates.push.services.mozilla.com/wpush/v1/[something]

    Note v2 as opposed to v1

    The requests to the v1 endpoint were all returning with 413 Request Entity Too Large

    The difference is that the desktop version accepts the standard 4078 bytes, but the Android version seems to have a lower limit (possibly 3052 bytes).

    I use minishlink's php library for sending push notifications, and I found some information about this here: https://github.com/web-push-libs/web-push-php#payload-length-security-and-performance

    This document says that the default is compatible with Firefox for Android (3052 bytes), but in practice I could only get it to work when I added the line

    $webPush->setAutomaticPadding(false);

    to my code. So if you happen to be using a library that pads the payload for security reasons, that might be your problem.

    For more discussion, see https://github.com/web-push-libs/web-push-php/issues/108, which suggests that 2847 bytes, not 3052, is the actual limit in practice for payload to Firefox for Android.