Skip to content

Commit 13a2c12

Browse files
committed
feat: add SensitiveParameter attribute
Avoid private key shown in stack trace. https://www.php.net/manual/en/class.sensitiveparameter.php
1 parent 7b6d1e9 commit 13a2c12

File tree

4 files changed

+32
-11
lines changed

4 files changed

+32
-11
lines changed

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@
3434
"ext-mbstring": "*",
3535
"ext-openssl": "*",
3636
"guzzlehttp/guzzle": "^7.4.5",
37-
"web-token/jwt-library": "^3.3.0|^4.0.0",
38-
"spomky-labs/base64url": "^2.0.4"
37+
"spomky-labs/base64url": "^2.0.4",
38+
"symfony/polyfill-php82": "^v1.31.0",
39+
"web-token/jwt-library": "^3.3.0|^4.0.0"
3940
},
4041
"suggest": {
4142
"ext-bcmath": "Optional for performance.",

src/Encryption.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,16 @@ public static function padPayload(string $payload, int $maxLengthToPad, string $
4747
* @param string $userPublicKey Base 64 encoded (MIME or URL-safe)
4848
* @param string $userAuthToken Base 64 encoded (MIME or URL-safe)
4949
*
50-
* @throws \ErrorException
50+
* @throws \ErrorException Thrown on php 8.1
51+
* @throws \Random\RandomException Thrown on php 8.2 and higher
5152
*/
52-
public static function encrypt(string $payload, string $userPublicKey, string $userAuthToken, string $contentEncoding): array
53-
{
53+
public static function encrypt(
54+
string $payload,
55+
string $userPublicKey,
56+
#[\SensitiveParameter]
57+
string $userAuthToken,
58+
string $contentEncoding,
59+
): array {
5460
return self::deterministicEncrypt(
5561
$payload,
5662
$userPublicKey,
@@ -64,8 +70,15 @@ public static function encrypt(string $payload, string $userPublicKey, string $u
6470
/**
6571
* @throws \RuntimeException
6672
*/
67-
public static function deterministicEncrypt(string $payload, string $userPublicKey, string $userAuthToken, string $contentEncoding, array $localKeyObject, string $salt): array
68-
{
73+
public static function deterministicEncrypt(
74+
string $payload,
75+
string $userPublicKey,
76+
#[\SensitiveParameter]
77+
string $userAuthToken,
78+
string $contentEncoding,
79+
array $localKeyObject,
80+
string $salt
81+
): array {
6982
$userPublicKey = Base64Url::decode($userPublicKey);
7083
$userAuthToken = Base64Url::decode($userAuthToken);
7184

src/VAPID.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,15 @@ public static function validate(array $vapid): array
9797
* @return array Returns an array with the 'Authorization' and 'Crypto-Key' values to be used as headers
9898
* @throws \ErrorException
9999
*/
100-
public static function getVapidHeaders(string $audience, string $subject, string $publicKey, string $privateKey, string $contentEncoding, ?int $expiration = null): array
101-
{
100+
public static function getVapidHeaders(
101+
string $audience,
102+
string $subject,
103+
string $publicKey,
104+
#[\SensitiveParameter]
105+
string $privateKey,
106+
string $contentEncoding,
107+
?int $expiration = null,
108+
): array {
102109
$expirationLimit = time() + 43200; // equal margin of error between 0 and 24h
103110
if (null === $expiration || $expiration > $expirationLimit) {
104111
$expiration = $expirationLimit;

src/WebPush.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ protected function createRejectedReport($reason): MessageSentReport
235235
}
236236

237237
/**
238-
* @throws \ErrorException
239-
* add back @throws \Random\RandomException when we drop PHP 8.1 support
238+
* @throws \ErrorException Thrown on php 8.1
239+
* @throws \Random\RandomException Thrown on php 8.2 and higher
240240
*/
241241
protected function prepare(array $notifications): array
242242
{

0 commit comments

Comments
 (0)