Skip to content

Commit bb807f4

Browse files
committed
Add SensitiveParameter attribute to sensitive parameters
Adds `#[SensitiveParameter]` to all potentially sensitive parameters, including key material, certificates and passphrases.
1 parent 848815d commit bb807f4

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

src/Signer/Key/InMemory.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Lcobucci\JWT\Signer\InvalidKeyProvided;
77
use Lcobucci\JWT\Signer\Key;
88
use Lcobucci\JWT\SodiumBase64Polyfill;
9+
use SensitiveParameter;
910
use SplFileObject;
1011
use Throwable;
1112

@@ -15,21 +16,30 @@
1516
final class InMemory implements Key
1617
{
1718
/** @param non-empty-string $contents */
18-
private function __construct(public readonly string $contents, public readonly string $passphrase)
19-
{
19+
private function __construct(
20+
public readonly string $contents,
21+
#[SensitiveParameter]
22+
public readonly string $passphrase,
23+
) {
2024
}
2125

2226
/** @param non-empty-string $contents */
23-
public static function plainText(string $contents, string $passphrase = ''): self
24-
{
27+
public static function plainText(
28+
string $contents,
29+
#[SensitiveParameter]
30+
string $passphrase = '',
31+
): self {
2532
self::guardAgainstEmptyKey($contents);
2633

2734
return new self($contents, $passphrase);
2835
}
2936

3037
/** @param non-empty-string $contents */
31-
public static function base64Encoded(string $contents, string $passphrase = ''): self
32-
{
38+
public static function base64Encoded(
39+
string $contents,
40+
#[SensitiveParameter]
41+
string $passphrase = '',
42+
): self {
3343
$decoded = SodiumBase64Polyfill::base642bin(
3444
$contents,
3545
SodiumBase64Polyfill::SODIUM_BASE64_VARIANT_ORIGINAL,
@@ -45,8 +55,11 @@ public static function base64Encoded(string $contents, string $passphrase = ''):
4555
*
4656
* @throws FileCouldNotBeRead
4757
*/
48-
public static function file(string $path, string $passphrase = ''): self
49-
{
58+
public static function file(
59+
string $path,
60+
#[SensitiveParameter]
61+
string $passphrase = '',
62+
): self {
5063
try {
5164
$file = new SplFileObject($path);
5265
} catch (Throwable $exception) {

src/Signer/OpenSSL.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
use Lcobucci\JWT\Signer;
77
use OpenSSLAsymmetricKey;
8+
use SensitiveParameter;
89

910
use function array_key_exists;
1011
use function assert;
@@ -40,7 +41,9 @@ abstract class OpenSSL implements Signer
4041
* @throws InvalidKeyProvided
4142
*/
4243
final protected function createSignature(
44+
#[SensitiveParameter]
4345
string $pem,
46+
#[SensitiveParameter]
4447
string $passphrase,
4548
string $payload,
4649
): string {
@@ -56,15 +59,20 @@ final protected function createSignature(
5659
}
5760

5861
/** @throws CannotSignPayload */
59-
private function getPrivateKey(string $pem, string $passphrase): OpenSSLAsymmetricKey
60-
{
62+
private function getPrivateKey(
63+
#[SensitiveParameter]
64+
string $pem,
65+
#[SensitiveParameter]
66+
string $passphrase,
67+
): OpenSSLAsymmetricKey {
6168
return $this->validateKey(openssl_pkey_get_private($pem, $passphrase));
6269
}
6370

6471
/** @throws InvalidKeyProvided */
6572
final protected function verifySignature(
6673
string $expected,
6774
string $payload,
75+
#[SensitiveParameter]
6876
string $pem,
6977
): bool {
7078
$key = $this->getPublicKey($pem);
@@ -74,8 +82,10 @@ final protected function verifySignature(
7482
}
7583

7684
/** @throws InvalidKeyProvided */
77-
private function getPublicKey(string $pem): OpenSSLAsymmetricKey
78-
{
85+
private function getPublicKey(
86+
#[SensitiveParameter]
87+
string $pem,
88+
): OpenSSLAsymmetricKey {
7989
return $this->validateKey(openssl_pkey_get_public($pem));
8090
}
8191

0 commit comments

Comments
 (0)