Skip to content

Commit d59f07a

Browse files
Merge pull request #62336 from nextcloud/bugfix/noid/mark-some-parameters-as-sensitive
fix: Mark some parameters as sensitive
2 parents 8399785 + 7d51b70 commit d59f07a

7 files changed

Lines changed: 56 additions & 10 deletions

File tree

lib/private/Security/CredentialsManager.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use OCP\IDBConnection;
1313
use OCP\Security\ICredentialsManager;
1414
use OCP\Security\ICrypto;
15+
use SensitiveParameter;
1516

1617
/**
1718
* Store and retrieve credentials for external services
@@ -34,7 +35,12 @@ public function __construct(
3435
* @param mixed $credentials
3536
*/
3637
#[\Override]
37-
public function store(string $userId, string $identifier, $credentials): void {
38+
public function store(
39+
string $userId,
40+
string $identifier,
41+
#[SensitiveParameter]
42+
$credentials,
43+
): void {
3844
$value = $this->crypto->encrypt(json_encode($credentials));
3945

4046
$this->dbConnection->setValues(self::DB_TABLE, [

lib/private/Security/Crypto.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use OCP\Security\ICrypto;
1515
use phpseclib\Crypt\AES;
1616
use phpseclib\Crypt\Hash;
17+
use SensitiveParameter;
1718

1819
/**
1920
* Class Crypto provides a high-level encryption layer using AES-CBC. If no key has been provided
@@ -41,7 +42,11 @@ public function __construct(
4142
* @return string Calculated HMAC
4243
*/
4344
#[\Override]
44-
public function calculateHMAC(string $message, string $password = ''): string {
45+
public function calculateHMAC(
46+
string $message,
47+
#[SensitiveParameter]
48+
string $password = '',
49+
): string {
4550
if ($password === '') {
4651
$password = $this->config->getSystemValueString('secret');
4752
}
@@ -63,7 +68,11 @@ public function calculateHMAC(string $message, string $password = ''): string {
6368
* @throws Exception if encrypting the data failed
6469
*/
6570
#[\Override]
66-
public function encrypt(string $plaintext, string $password = ''): string {
71+
public function encrypt(
72+
string $plaintext,
73+
#[SensitiveParameter]
74+
string $password = '',
75+
): string {
6776
if ($password === '') {
6877
$password = $this->config->getSystemValueString('secret');
6978
}
@@ -93,7 +102,11 @@ public function encrypt(string $plaintext, string $password = ''): string {
93102
* @throws Exception If the decryption failed
94103
*/
95104
#[\Override]
96-
public function decrypt(string $authenticatedCiphertext, string $password = ''): string {
105+
public function decrypt(
106+
string $authenticatedCiphertext,
107+
#[SensitiveParameter]
108+
string $password = '',
109+
): string {
97110
$secret = $this->config->getSystemValue('secret');
98111
try {
99112
if ($password === '') {

lib/public/Security/Events/GenerateSecurePasswordEvent.php

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

1212
use OCP\EventDispatcher\Event;
1313
use OCP\Security\PasswordContext;
14+
use SensitiveParameter;
1415

1516
/**
1617
* Event to request a secure password to be generated
@@ -50,7 +51,10 @@ public function getPassword(): ?string {
5051
* This is used by password generators to set the generated password.
5152
* @since 18.0.0
5253
*/
53-
public function setPassword(string $password): void {
54+
public function setPassword(
55+
#[SensitiveParameter]
56+
string $password,
57+
): void {
5458
$this->password = $password;
5559
}
5660

lib/public/Security/Events/ValidatePasswordPolicyEvent.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use OCP\EventDispatcher\Event;
1313
use OCP\Security\PasswordContext;
14+
use SensitiveParameter;
1415

1516
/**
1617
* This event can be emitted to request a validation of a password.
@@ -26,6 +27,7 @@ class ValidatePasswordPolicyEvent extends Event {
2627
* @since 31.0.0 - $context parameter added
2728
*/
2829
public function __construct(
30+
#[SensitiveParameter]
2931
private string $password,
3032
private PasswordContext $context = PasswordContext::ACCOUNT,
3133
) {

lib/public/Security/ICredentialsManager.php

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

1010
namespace OCP\Security;
1111

12+
use SensitiveParameter;
13+
1214
/**
1315
* Store and retrieve credentials for external services
1416
*
@@ -23,7 +25,12 @@ interface ICredentialsManager {
2325
* @param mixed $credentials
2426
* @since 8.2.0
2527
*/
26-
public function store(string $userId, string $identifier, $credentials): void;
28+
public function store(
29+
string $userId,
30+
string $identifier,
31+
#[SensitiveParameter]
32+
$credentials,
33+
): void;
2734

2835
/**
2936
* Retrieve a set of credentials

lib/public/Security/ICrypto.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
namespace OCP\Security;
1111

12+
use SensitiveParameter;
13+
1214
/**
1315
* Class Crypto provides a high-level encryption layer using AES-CBC. If no key has been provided
1416
* it will use the secret defined in config.php as key. Additionally the message will be HMAC'd.
@@ -26,7 +28,11 @@ interface ICrypto {
2628
* @return string Calculated HMAC
2729
* @since 8.0.0
2830
*/
29-
public function calculateHMAC(string $message, string $password = ''): string;
31+
public function calculateHMAC(
32+
string $message,
33+
#[SensitiveParameter]
34+
string $password = '',
35+
): string;
3036

3137
/**
3238
* Encrypts a value and adds an HMAC (Encrypt-Then-MAC)
@@ -35,7 +41,11 @@ public function calculateHMAC(string $message, string $password = ''): string;
3541
* @return string Authenticated ciphertext
3642
* @since 8.0.0
3743
*/
38-
public function encrypt(string $plaintext, string $password = ''): string;
44+
public function encrypt(
45+
string $plaintext,
46+
#[SensitiveParameter]
47+
string $password = '',
48+
): string;
3949

4050
/**
4151
* Decrypts a value and verifies the HMAC (Encrypt-Then-Mac)
@@ -46,5 +56,9 @@ public function encrypt(string $plaintext, string $password = ''): string;
4656
* @throws \Exception If the decryption failed
4757
* @since 8.0.0
4858
*/
49-
public function decrypt(string $authenticatedCiphertext, string $password = ''): string;
59+
public function decrypt(
60+
string $authenticatedCiphertext,
61+
#[SensitiveParameter]
62+
string $password = '',
63+
): string;
5064
}

lib/public/Security/VerificationToken/IVerificationToken.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
interface IVerificationToken {
1717
/**
18-
* Checks whether the a provided tokent matches a stored token and its
18+
* Checks whether a provided token matches a stored token and its
1919
* constraints. An InvalidTokenException is thrown on issues, otherwise
2020
* the check is successful.
2121
*

0 commit comments

Comments
 (0)