Skip to content

Commit ea703c3

Browse files
authored
Merge pull request #109 from SimonFrings/SensitiveParameter
Mark passwords and URIs as `#[\SensitiveParameter]` (PHP 8.2+)
2 parents 45f9be9 + 1633718 commit ea703c3

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

src/Client.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@ final class Client implements ConnectorInterface
3131
* @param ?ConnectorInterface $connector
3232
* @throws InvalidArgumentException
3333
*/
34-
public function __construct($socksUri, ConnectorInterface $connector = null)
35-
{
34+
public function __construct(
35+
#[\SensitiveParameter]
36+
$socksUri,
37+
ConnectorInterface $connector = null
38+
) {
3639
// support `sockss://` scheme for SOCKS over TLS
3740
// support `socks+unix://` scheme for Unix domain socket (UDS) paths
3841
if (preg_match('/^(socks(?:5|4)?)(s|\+unix):\/\/(.*?@)?(.+?)$/', $socksUri, $match)) {
@@ -97,8 +100,11 @@ private function setProtocolVersionFromScheme($scheme)
97100
* @param string $password
98101
* @link http://tools.ietf.org/html/rfc1929
99102
*/
100-
private function setAuth($username, $password)
101-
{
103+
private function setAuth(
104+
$username,
105+
#[\SensitiveParameter]
106+
$password
107+
) {
102108
if (strlen($username) > 255 || strlen($password) > 255) {
103109
throw new InvalidArgumentException('Both username and password MUST NOT exceed a length of 255 bytes each');
104110
}

src/Server.php

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,32 @@ final class Server
5757
* @param ?ConnectorInterface $connector
5858
* @param null|array|callable $auth
5959
*/
60-
public function __construct(LoopInterface $loop = null, ConnectorInterface $connector = null, $auth = null)
61-
{
60+
public function __construct(
61+
LoopInterface $loop = null,
62+
ConnectorInterface $connector = null,
63+
#[\SensitiveParameter]
64+
$auth = null
65+
) {
6266
if (\is_array($auth)) {
6367
// wrap authentication array in authentication callback
64-
$this->auth = function ($username, $password) use ($auth) {
68+
$this->auth = function (
69+
$username,
70+
#[\SensitiveParameter]
71+
$password
72+
) use ($auth) {
6573
return \React\Promise\resolve(
6674
isset($auth[$username]) && (string)$auth[$username] === $password
6775
);
6876
};
6977
} elseif (\is_callable($auth)) {
7078
// wrap authentication callback in order to cast its return value to a promise
71-
$this->auth = function($username, $password, $remote) use ($auth) {
79+
$this->auth = function(
80+
$username,
81+
#[\SensitiveParameter]
82+
$password,
83+
#[\SensitiveParameter]
84+
$remote
85+
) use ($auth) {
7286
return \React\Promise\resolve(
7387
\call_user_func($auth, $username, $password, $remote)
7488
);
@@ -247,7 +261,10 @@ public function handleSocks5(ConnectionInterface $stream, $auth, StreamReader $r
247261
})->then(function ($username) use ($reader, $auth, $stream, &$remote) {
248262
return $reader->readByte()->then(function ($length) use ($reader) {
249263
return $reader->readLength($length);
250-
})->then(function ($password) use ($username, $auth, $stream, &$remote) {
264+
})->then(function (
265+
#[\SensitiveParameter]
266+
$password
267+
) use ($username, $auth, $stream, &$remote) {
251268
// username and password given => authenticate
252269

253270
// prefix username/password to remote URI

0 commit comments

Comments
 (0)