Skip to content

Commit 3e322fe

Browse files
authored
Merge pull request #1483 from coffeemakr/master
Add SensitiveParameter attribute
2 parents dd2fca7 + 3ce0bd4 commit 3e322fe

File tree

9 files changed

+61
-20
lines changed

9 files changed

+61
-20
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Added
9+
- Added sensitive parameter to avoid sensitive data being included in stack traces (PR #1483)
10+
811
## [9.2.0] - released 2025-02-15
912
### Added
1013
- Added a new function to the provided ClientTrait, `supportsGrantType` to allow the auth server to issue the response `unauthorized_client` when applicable (PR #1420)

src/AuthorizationServer.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface;
2828
use Psr\Http\Message\ResponseInterface;
2929
use Psr\Http\Message\ServerRequestInterface;
30+
use SensitiveParameter;
3031

3132
class AuthorizationServer implements EmitterAwareInterface
3233
{
@@ -61,7 +62,9 @@ public function __construct(
6162
private ClientRepositoryInterface $clientRepository,
6263
private AccessTokenRepositoryInterface $accessTokenRepository,
6364
private ScopeRepositoryInterface $scopeRepository,
65+
#[SensitiveParameter]
6466
CryptKeyInterface|string $privateKey,
67+
#[SensitiveParameter]
6568
Key|string $encryptionKey,
6669
ResponseTypeInterface|null $responseType = null
6770
) {

src/CryptKey.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
use LogicException;
1818
use OpenSSLAsymmetricKey;
19+
use SensitiveParameter;
1920

2021
use function decoct;
2122
use function file_get_contents;
@@ -40,8 +41,12 @@ class CryptKey implements CryptKeyInterface
4041

4142
protected string $keyPath;
4243

43-
public function __construct(string $keyPath, protected ?string $passPhrase = null, bool $keyPermissionsCheck = true)
44-
{
44+
public function __construct(
45+
string $keyPath,
46+
#[SensitiveParameter]
47+
protected ?string $passPhrase = null,
48+
bool $keyPermissionsCheck = true
49+
) {
4550
if (str_starts_with($keyPath, self::FILE_PREFIX) === false && $this->isValidKey($keyPath, $this->passPhrase ?? '')) {
4651
$this->keyContents = $keyPath;
4752
$this->keyPath = '';
@@ -99,8 +104,12 @@ public function getKeyContents(): string
99104
/**
100105
* Validate key contents.
101106
*/
102-
private function isValidKey(string $contents, string $passPhrase): bool
103-
{
107+
private function isValidKey(
108+
#[SensitiveParameter]
109+
string $contents,
110+
#[SensitiveParameter]
111+
string $passPhrase
112+
): bool {
104113
$privateKey = openssl_pkey_get_private($contents, $passPhrase);
105114

106115
$key = $privateKey instanceof OpenSSLAsymmetricKey ? $privateKey : openssl_pkey_get_public($contents);

src/CryptTrait.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Exception;
2222
use InvalidArgumentException;
2323
use LogicException;
24+
use SensitiveParameter;
2425

2526
use function is_string;
2627

@@ -83,8 +84,10 @@ protected function decrypt(string $encryptedData): string
8384
}
8485
}
8586

86-
public function setEncryptionKey(Key|string|null $key = null): void
87-
{
87+
public function setEncryptionKey(
88+
#[SensitiveParameter]
89+
Key|string|null $key = null
90+
): void {
8891
$this->encryptionKey = $key;
8992
}
9093
}

src/Entities/Traits/AccessTokenTrait.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use League\OAuth2\Server\Entities\ClientEntityInterface;
2222
use League\OAuth2\Server\Entities\ScopeEntityInterface;
2323
use RuntimeException;
24+
use SensitiveParameter;
2425

2526
trait AccessTokenTrait
2627
{
@@ -31,8 +32,10 @@ trait AccessTokenTrait
3132
/**
3233
* Set the private key used to encrypt this access token.
3334
*/
34-
public function setPrivateKey(CryptKeyInterface $privateKey): void
35-
{
35+
public function setPrivateKey(
36+
#[SensitiveParameter]
37+
CryptKeyInterface $privateKey
38+
): void {
3639
$this->privateKey = $privateKey;
3740
}
3841

src/RequestAccessTokenEvent.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@
1414

1515
use League\OAuth2\Server\Entities\AccessTokenEntityInterface;
1616
use Psr\Http\Message\ServerRequestInterface;
17+
use SensitiveParameter;
1718

1819
class RequestAccessTokenEvent extends RequestEvent
1920
{
20-
public function __construct(string $name, ServerRequestInterface $request, private AccessTokenEntityInterface $accessToken)
21-
{
21+
public function __construct(
22+
string $name,
23+
ServerRequestInterface $request,
24+
#[SensitiveParameter]
25+
private AccessTokenEntityInterface $accessToken
26+
) {
2227
parent::__construct($name, $request);
2328
}
2429

src/RequestRefreshTokenEvent.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@
1414

1515
use League\OAuth2\Server\Entities\RefreshTokenEntityInterface;
1616
use Psr\Http\Message\ServerRequestInterface;
17+
use SensitiveParameter;
1718

1819
class RequestRefreshTokenEvent extends RequestEvent
1920
{
20-
public function __construct(string $name, ServerRequestInterface $request, private RefreshTokenEntityInterface $refreshToken)
21-
{
21+
public function __construct(
22+
string $name,
23+
ServerRequestInterface $request,
24+
#[SensitiveParameter]
25+
private RefreshTokenEntityInterface $refreshToken
26+
) {
2227
parent::__construct($name, $request);
2328
}
2429

src/ResponseTypes/AbstractResponseType.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use League\OAuth2\Server\CryptTrait;
1919
use League\OAuth2\Server\Entities\AccessTokenEntityInterface;
2020
use League\OAuth2\Server\Entities\RefreshTokenEntityInterface;
21+
use SensitiveParameter;
2122

2223
abstract class AbstractResponseType implements ResponseTypeInterface
2324
{
@@ -29,18 +30,24 @@ abstract class AbstractResponseType implements ResponseTypeInterface
2930

3031
protected CryptKeyInterface $privateKey;
3132

32-
public function setAccessToken(AccessTokenEntityInterface $accessToken): void
33-
{
33+
public function setAccessToken(
34+
#[SensitiveParameter]
35+
AccessTokenEntityInterface $accessToken
36+
): void {
3437
$this->accessToken = $accessToken;
3538
}
3639

37-
public function setRefreshToken(RefreshTokenEntityInterface $refreshToken): void
38-
{
40+
public function setRefreshToken(
41+
#[SensitiveParameter]
42+
RefreshTokenEntityInterface $refreshToken
43+
): void {
3944
$this->refreshToken = $refreshToken;
4045
}
4146

42-
public function setPrivateKey(CryptKeyInterface $key): void
43-
{
47+
public function setPrivateKey(
48+
#[SensitiveParameter]
49+
CryptKeyInterface $key
50+
): void {
4451
$this->privateKey = $key;
4552
}
4653
}

src/ResponseTypes/BearerTokenResponse.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use League\OAuth2\Server\Entities\AccessTokenEntityInterface;
1818
use LogicException;
1919
use Psr\Http\Message\ResponseInterface;
20+
use SensitiveParameter;
2021

2122
use function array_merge;
2223
use function json_encode;
@@ -75,8 +76,10 @@ public function generateHttpResponse(ResponseInterface $response): ResponseInter
7576
*
7677
* @return array<array-key,mixed>
7778
*/
78-
protected function getExtraParams(AccessTokenEntityInterface $accessToken): array
79-
{
79+
protected function getExtraParams(
80+
#[SensitiveParameter]
81+
AccessTokenEntityInterface $accessToken
82+
): array {
8083
return [];
8184
}
8285
}

0 commit comments

Comments
 (0)