Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the cause of BadWebPushTopic from https://web.push.apple.com?

I receive sporadic from the Apple webpush API https://web.push.apple.com/... the response {"reason":"BadWebPushTopic"} with response code 400 . If I send the same message with the same Topic later it work without problems.

My Topic header has always 25 characters with 0-9 and a-z.

Any suggestion how to handle this error?

like image 950
Horcrux7 Avatar asked Oct 29 '25 19:10

Horcrux7


2 Answers

After many tests, it seems that the topic size works with a factor of 4. Sounds like the Apple server try to decode it as base64. I have fill it with 0 to 32 characters, which is the max size for the topic.

like image 126
Horcrux7 Avatar answered Oct 31 '25 10:10

Horcrux7


@Horcrux7's answer above is helpful, but not fully accurate. Expanding on it below for future readers.

The push topic name for Apple notification is stricter than Chrome/Android and has the following specification (from here):

  • Uses characters from the "URL or filename-safe Base64 characters sets" (which include a-z, A-Z, 0-9, _, -)
  • Length between 1 and 32

I would consider = to be part of the "URL character set" but based on testing, it is not. All of =, +, and / characters, used in base64 encoding, are all disallowed. This means if you want to base64, my suggestion would be to use RFC 4648 §5 URL- and filename-safe standard which replaces + with - and / with _ as the 62nd and 63rd characters, respectively. In addition the base64 cannot have padding using the default = padding character since it's disallowed so you either have to have a length that's a factor of 4 so that there is no padding or replace the padding with an allowed character.

Example of a valid base64-encoded id: wVNMqp5oQhO8fIefxjtQwVNMq_5oQhOv

If you don't adhere to this, you'll get a 400 response and with a body that includes mention of:

BadWebPushTopic

The Topic header is present but doesn’t conform to the specification.

like image 24
nico Avatar answered Oct 31 '25 11:10

nico



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!