Notification not sent due to hex2bin() error
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 42/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- PHP
- Stelle
- 1.9k
- Fork
- 312
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di web-push-libs/web-push-php
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
web-push-libs/web-push-php#441 ·
-
Opera push not working?Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 30/100
web-push-libs/web-push-php#430 · 1 reazione ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
web-push-libs/web-push-php#429 · 3 commenti ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 20/100
web-push-libs/web-push-php#412 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
web-push-libs/web-push-php#411 · 5 commenti ·
Tutte le issue di web-push-libs/web-push-php
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
Automattic/blocks-engine#2803 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
hestiacp/hestiacp#5798 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
woocommerce/woocommerce-google-analytics-integration#699 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
wp-media/imagify-plugin#1289 ·
I maintainer di solito rispondono entro 5 giorni
-
Sidebar highlights two items when plugin routes share a prefix (/plugin/foo and /plugin/foo-bar)Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
getgrav/grav-plugin-admin2#195 ·