Skip to content

Commit ea4d38f

Browse files
committed
fix: Mark some parameters as sensitive
Signed-off-by: Joas Schilling <coding@schilljs.com>
1 parent 6b2ce7b commit ea4d38f

7 files changed

Lines changed: 54 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: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ interface ICrypto {
2626
* @return string Calculated HMAC
2727
* @since 8.0.0
2828
*/
29-
public function calculateHMAC(string $message, string $password = ''): string;
29+
public function calculateHMAC(
30+
string $message,
31+
#[SensitiveParameter]
32+
string $password = '',
33+
): string;
3034

3135
/**
3236
* Encrypts a value and adds an HMAC (Encrypt-Then-MAC)
@@ -35,7 +39,11 @@ public function calculateHMAC(string $message, string $password = ''): string;
3539
* @return string Authenticated ciphertext
3640
* @since 8.0.0
3741
*/
38-
public function encrypt(string $plaintext, string $password = ''): string;
42+
public function encrypt(
43+
string $plaintext,
44+
#[SensitiveParameter]
45+
string $password = '',
46+
): string;
3947

4048
/**
4149
* Decrypts a value and verifies the HMAC (Encrypt-Then-Mac)
@@ -46,5 +54,9 @@ public function encrypt(string $plaintext, string $password = ''): string;
4654
* @throws \Exception If the decryption failed
4755
* @since 8.0.0
4856
*/
49-
public function decrypt(string $authenticatedCiphertext, string $password = ''): string;
57+
public function decrypt(
58+
string $authenticatedCiphertext,
59+
#[SensitiveParameter]
60+
string $password = '',
61+
): string;
5062
}

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)