Skip to content

Commit ef400a8

Browse files
committed
Mark parameters containing user credentials as sensitive
PHP 8.2 introduced the `SensitiveParameter` attribute. The effect of the attribute is that the value of the parameter is no longer directly shown in stack traces; instead, starting with PHP 8.2, the parameter will be presented as a `SensitiveParameterValue` object. As the attribute only applies to parameters, it (unfortunately) has no effect on serialization of the object. See: https://3v4l.org/StoQO Might be an idea to start a discussion about an `SensitiveProperty` attribute on the PHP Internals mailing list, but that's outside the scope of this PR. For now, this PR marks the `$args` parameter for the `Auth\Basic` class constructor and the `Proxy\Http` constructor as sensitive as both of these are supposed to contain user credentials (user name, password) for accessing a protected URL. Includes updating the example code for custom authentication to also use the attribute. **Open question**: the `$options` array passed to a large range of Requests methods can [also contain credentials](https://github.com/WordPress/Requests/blob/ebb9f65855c860bc33005b3d8bccf6444e598fba/src/Requests.php#L395-L399). Should this parameter also be marked as sensitive in all appropriate places ? Refs: * https://www.php.net/manual/en/class.sensitiveparameter.php * https://wiki.php.net/rfc/redact_parameters_in_back_traces
1 parent cdbd8b0 commit ef400a8

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

docs/authentication-custom.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ services that do this; perhaps this is a market waiting to be tapped?)
1616
class MySoftware_Auth_Hotdog implements WpOrg\Requests\Auth {
1717
protected $password;
1818

19-
public function __construct($password) {
19+
public function __construct(
20+
#[\SensitiveParameter]
21+
$password
22+
) {
2023
$this->password = $password;
2124
}
2225

src/Auth/Basic.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace WpOrg\Requests\Auth;
1111

12+
use SensitiveParameter;
1213
use WpOrg\Requests\Auth;
1314
use WpOrg\Requests\Exception\ArgumentCount;
1415
use WpOrg\Requests\Exception\InvalidArgument;
@@ -48,7 +49,10 @@ class Basic implements Auth {
4849
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed argument is not an array or null.
4950
* @throws \WpOrg\Requests\Exception\ArgumentCount On incorrect number of array elements (`authbasicbadargs`).
5051
*/
51-
public function __construct($args = null) {
52+
public function __construct(
53+
#[SensitiveParameter]
54+
$args = null
55+
) {
5256
if (is_array($args)) {
5357
if (count($args) !== 2) {
5458
throw ArgumentCount::create('an array with exactly two elements', count($args), 'authbasicbadargs');

src/Proxy/Http.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace WpOrg\Requests\Proxy;
1111

12+
use SensitiveParameter;
1213
use WpOrg\Requests\Exception\ArgumentCount;
1314
use WpOrg\Requests\Exception\InvalidArgument;
1415
use WpOrg\Requests\Hooks;
@@ -65,7 +66,10 @@ final class Http implements Proxy {
6566
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed argument is not an array, a string or null.
6667
* @throws \WpOrg\Requests\Exception\ArgumentCount On incorrect number of arguments (`proxyhttpbadargs`)
6768
*/
68-
public function __construct($args = null) {
69+
public function __construct(
70+
#[SensitiveParameter]
71+
$args = null
72+
) {
6973
if (is_string($args)) {
7074
$this->proxy = $args;
7175
} elseif (is_array($args)) {

0 commit comments

Comments
 (0)