Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Notification not sent due to hex2bin() error

Open
#372 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
php
Domain
backend

Research direction

Start with src/Utils.php around lines 62–63 and follow the encryption flow into src/Encryption.php, using the reported stack trace and the provided WebPush setup as the entry point. Compare the failing subscription or key data with working notifications and add a regression case if the input can be reproduced. Done means the invalid input is handled appropriately and notification sending no longer reaches the reported Base64Url type error.

Written by the indexing model from the issue text.

Description

NOTE: Please test in a least two browsers (i.e. Chrome and Firefox). This
helps with diagnosing problems quicker.

Please confirm the following:

  • I have read the README entirely
  • I have verified in the issues that my problem hasn't already been resolved

Setup

Please provide the following details, the more info you can provide the
better.

  • Operating System: Linux & Window
  • PHP Version: 8.1 & 8.2
  • web-push-php Version: 8.0.0

Please check that you have installed and enabled these PHP extensions :

  • curl
  • gmp
  • mbstring
  • openssl

Please select any browsers that you are experiencing problems with:

  • Chrome (Version 115.0.5790.171 (Build officiel) (64 bits))
  • Firefox
  • Firefox for Mobile
  • Opera for Android
  • Samsung Internet Browser
  • Other

Please specify the versions (i.e. Chrome Beta, Firefox Beta etc).

Problem

Please explain what behaviour you are seeing.

Hi, I am using this package in production and most of the notifications to differents users seems to work. But today I got the following error:

[13-Aug-2023 08:52:55 Europe/Paris] PHP Warning: hex2bin(): Hexadecimal input string must have an even length in /home/XXX/public_html/vendor/minishlink/web-push/src/Utils.php on line 62 [13-Aug-2023 08:52:55 Europe/Paris] PHP Warning: hex2bin(): Hexadecimal input string must have an even length in /home/XXX/public_html/vendor/minishlink/web-push/src/Utils.php on line 63 [13-Aug-2023 08:52:55 Europe/Paris] PHP Fatal error: Uncaught TypeError: Base64Url\Base64Url::encode(): Argument #1 ($data) must be of type string, bool given, called in /home/XXX/public_html/vendor/minishlink/web-push/src/Encryption.php on line 99 and defined in /home/XXX/public_html/vendor/spomky-labs/base64url/src/Base64Url.php:33 Stack trace: #0 /home/XXX/public_html/vendor/minishlink/web-push/src/Encryption.php(99): Base64Url\Base64Url::encode(false) #1 /home/XXX/public_html/vendor/minishlink/web-push/src/Encryption.php(61): Minishlink\WebPush\Encryption::deterministicEncrypt('{"title":"New p...', '\x04\x11<\x8D[a\xF6\xE1\xA1\xE7\x9B\xC2\xD1%3...', '\x01\xF8h*bA\xBCkox\xA0P\x8D,\xE6...', 'aes128gcm', Array, '-\xB4F\x8Ed\x05H\x96T\n\xC8\xFB\x00|\xCC...') #2 /home/XXX/public_html/vendor/minishlink/web-push/src/WebPush.php(217): Minishlink\WebPush\Encryption::encrypt('{"title":"New p...', 'BBE8jVth 9uGh55...', 'AfhoKmJBvGtveKB...', 'aes128gcm') #3 /home/XXX/public_html/vendor/minishlink/web-push/src/WebPush.php(164): Minishlink\WebPush\WebPush->prepare(Array) #4 /home/XXX/public_html/src/model/NotificationManager.php(176): Minishlink\WebPush\WebPush->flush() #5 /home/XXX/public_html/src/model/PrivateMessageManager.php(347): model\NotificationManager->sendNotification(15693, 'private_message', '/!\\ XXXXXXXX pr...') #6 /home/XXX/public_html/src/controller/PrivateMessagesController.php(112): model\PrivateMessageManager->sendNewMessage('Hi,\n\nBy being p...', 51966, 1) #7 /home/XXX/public_html/private-messages.php(22): controller\PrivateMessagesController->sendNewMessage() #8 {main} thrown in /home/XXX/public_html/vendor/spomky-labs/base64url/src/Base64Url.php on line 33

It seems that there is a problem in the file Utils.php line 62 on this lines:
return [ hex2bin(mb_substr($data, 0, $dataLength / 2, '8bit')), hex2bin(mb_substr($data, $dataLength / 2, null, '8bit')), ];

Expected

Please explain what you expected to happen

The notification should be sent like the other ones that works.

Features Used

  • VAPID Support
  • Sending with Payload

Example / Reproduce Case

Please provide a code sample that reproduces the issue. If there is a
repository that reproduces the issue please put the link here.

I can not really provide a code to reproduces that since I think I should not share my private key but do not hesitate to tell me if you need unsensitive data.

Here is an example of the code that init the web push and send the notifications maybe I missed something ?

$auth = [ 'VAPID' => [ 'subject' => WEB_PUSH_DOMAIN, 'publicKey' => WEB_PUSH_NOTIFICATION_PUBLIC_KEY, 'privateKey' => WEB_PUSH_NOTIFICATION_PRIVATE_KEY, ], ]; try { $webPush = new WebPush($auth); foreach ($webPushTokens as $token) { $webPush->queueNotification( Subscription::create([ 'endpoint' => $token['endpoint'], 'contentEncoding' => $token['content_encoding'], 'keys' => [ 'p256dh' => $token['p256dh'], 'auth' => $token['token'] ] ]), json_encode([ 'title' => $title, 'body' => $text ]) ); } foreach ($webPush->flush() as $report) { } } catch (Exception) { }

Other

Please put any remaining notes here.
I don't really know why it is not working for an user but I was not able to test it for firefox since I am not really able to reproduce that.

Dominant language
PHP
Stars
1.9k
Forks
312
Avg merge
1d 15h
Merged PRs (30d)
1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from web-push-libs/web-push-php

All issues in web-push-libs/web-push-php

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.