Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Mark sensitive params with SensitiveParameter attribute #51940

Merged
merged 6 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/Illuminate/Auth/DatabaseUserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function retrieveById($identifier)
* @param string $token
* @return \Illuminate\Contracts\Auth\Authenticatable|null
*/
public function retrieveByToken($identifier, $token)
public function retrieveByToken($identifier, #[\SensitiveParameter] $token)
{
$user = $this->getGenericUser(
$this->connection->table($this->table)->find($identifier)
Expand All @@ -84,7 +84,7 @@ public function retrieveByToken($identifier, $token)
* @param string $token
* @return void
*/
public function updateRememberToken(UserContract $user, $token)
public function updateRememberToken(UserContract $user, #[\SensitiveParameter] $token)
{
$this->connection->table($this->table)
->where($user->getAuthIdentifierName(), $user->getAuthIdentifier())
Expand All @@ -97,7 +97,7 @@ public function updateRememberToken(UserContract $user, $token)
* @param array $credentials
* @return \Illuminate\Contracts\Auth\Authenticatable|null
*/
public function retrieveByCredentials(array $credentials)
public function retrieveByCredentials(#[\SensitiveParameter] array $credentials)
{
$credentials = array_filter(
$credentials,
Expand Down Expand Up @@ -152,7 +152,7 @@ protected function getGenericUser($user)
* @param array $credentials
* @return bool
*/
public function validateCredentials(UserContract $user, array $credentials)
public function validateCredentials(UserContract $user, #[\SensitiveParameter] array $credentials)
{
return $this->hasher->check(
$credentials['password'], $user->getAuthPassword()
Expand All @@ -167,7 +167,7 @@ public function validateCredentials(UserContract $user, array $credentials)
* @param bool $force
* @return void
*/
public function rehashPasswordIfRequired(UserContract $user, array $credentials, bool $force = false)
public function rehashPasswordIfRequired(UserContract $user, #[\SensitiveParameter] array $credentials, bool $force = false)
{
if (! $this->hasher->needsRehash($user->getAuthPassword()) && ! $force) {
return;
Expand Down
10 changes: 5 additions & 5 deletions src/Illuminate/Auth/EloquentUserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function retrieveById($identifier)
* @param string $token
* @return \Illuminate\Contracts\Auth\Authenticatable|null
*/
public function retrieveByToken($identifier, $token)
public function retrieveByToken($identifier, #[\SensitiveParameter] $token)
{
$model = $this->createModel();

Expand All @@ -90,7 +90,7 @@ public function retrieveByToken($identifier, $token)
* @param string $token
* @return void
*/
public function updateRememberToken(UserContract $user, $token)
public function updateRememberToken(UserContract $user, #[\SensitiveParameter] $token)
{
$user->setRememberToken($token);

Expand All @@ -109,7 +109,7 @@ public function updateRememberToken(UserContract $user, $token)
* @param array $credentials
* @return \Illuminate\Contracts\Auth\Authenticatable|null
*/
public function retrieveByCredentials(array $credentials)
public function retrieveByCredentials(#[\SensitiveParameter] array $credentials)
{
$credentials = array_filter(
$credentials,
Expand Down Expand Up @@ -146,7 +146,7 @@ public function retrieveByCredentials(array $credentials)
* @param array $credentials
* @return bool
*/
public function validateCredentials(UserContract $user, array $credentials)
public function validateCredentials(UserContract $user, #[\SensitiveParameter] array $credentials)
{
if (is_null($plain = $credentials['password'])) {
return false;
Expand All @@ -163,7 +163,7 @@ public function validateCredentials(UserContract $user, array $credentials)
* @param bool $force
* @return void
*/
public function rehashPasswordIfRequired(UserContract $user, array $credentials, bool $force = false)
public function rehashPasswordIfRequired(UserContract $user, #[\SensitiveParameter] array $credentials, bool $force = false)
{
if (! $this->hasher->needsRehash($user->getAuthPassword()) && ! $force) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Auth/Events/Attempting.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Attempting
* @param bool $remember
* @return void
*/
public function __construct($guard, $credentials, $remember)
public function __construct($guard, #[\SensitiveParameter] $credentials, $remember)
{
$this->guard = $guard;
$this->remember = $remember;
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Auth/Events/Failed.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Failed
* @param array $credentials
* @return void
*/
public function __construct($guard, $user, $credentials)
public function __construct($guard, $user, #[\SensitiveParameter] $credentials)
{
$this->user = $user;
$this->guard = $guard;
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Auth/Notifications/ResetPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ResetPassword extends Notification
* @param string $token
* @return void
*/
public function __construct($token)
public function __construct(#[\SensitiveParameter] $token)
{
$this->token = $token;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Auth/Passwords/CanResetPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function getEmailForPasswordReset()
* @param string $token
* @return void
*/
public function sendPasswordResetNotification($token)
public function sendPasswordResetNotification(#[\SensitiveParameter] $token)
{
$this->notify(new ResetPasswordNotification($token));
}
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Auth/Passwords/DatabaseTokenRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ protected function deleteExisting(CanResetPasswordContract $user)
* @param string $token
* @return array
*/
protected function getPayload($email, $token)
protected function getPayload($email, #[\SensitiveParameter] $token)
{
return ['email' => $email, 'token' => $this->hasher->make($token), 'created_at' => new Carbon];
}
Expand All @@ -127,7 +127,7 @@ protected function getPayload($email, $token)
* @param string $token
* @return bool
*/
public function exists(CanResetPasswordContract $user, $token)
public function exists(CanResetPasswordContract $user, #[\SensitiveParameter] $token)
{
$record = (array) $this->getTable()->where(
'email', $user->getEmailForPasswordReset()
Expand Down
12 changes: 6 additions & 6 deletions src/Illuminate/Auth/Passwords/PasswordBroker.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class PasswordBroker implements PasswordBrokerContract
* @param \Illuminate\Contracts\Events\Dispatcher $users
* @return void
*/
public function __construct(TokenRepositoryInterface $tokens, UserProvider $users, ?Dispatcher $dispatcher = null)
public function __construct(#[\SensitiveParameter] TokenRepositoryInterface $tokens, UserProvider $users, ?Dispatcher $dispatcher = null)
{
$this->users = $users;
$this->tokens = $tokens;
Expand All @@ -56,7 +56,7 @@ public function __construct(TokenRepositoryInterface $tokens, UserProvider $user
* @param \Closure|null $callback
* @return string
*/
public function sendResetLink(array $credentials, ?Closure $callback = null)
public function sendResetLink(#[\SensitiveParameter] array $credentials, ?Closure $callback = null)
{
// First we will check to see if we found a user at the given credentials and
// if we did not we will redirect back to this current URI with a piece of
Expand Down Expand Up @@ -96,7 +96,7 @@ public function sendResetLink(array $credentials, ?Closure $callback = null)
* @param \Closure $callback
* @return mixed
*/
public function reset(array $credentials, Closure $callback)
public function reset(#[\SensitiveParameter] array $credentials, Closure $callback)
{
$user = $this->validateReset($credentials);

Expand Down Expand Up @@ -125,7 +125,7 @@ public function reset(array $credentials, Closure $callback)
* @param array $credentials
* @return \Illuminate\Contracts\Auth\CanResetPassword|string
*/
protected function validateReset(array $credentials)
protected function validateReset(#[\SensitiveParameter] array $credentials)
{
if (is_null($user = $this->getUser($credentials))) {
return static::INVALID_USER;
Expand All @@ -146,7 +146,7 @@ protected function validateReset(array $credentials)
*
* @throws \UnexpectedValueException
*/
public function getUser(array $credentials)
public function getUser(#[\SensitiveParameter] array $credentials)
{
$credentials = Arr::except($credentials, ['token']);

Expand Down Expand Up @@ -188,7 +188,7 @@ public function deleteToken(CanResetPasswordContract $user)
* @param string $token
* @return bool
*/
public function tokenExists(CanResetPasswordContract $user, $token)
public function tokenExists(CanResetPasswordContract $user, #[\SensitiveParameter] $token)
{
return $this->tokens->exists($user, $token);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Auth/Passwords/TokenRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function create(CanResetPasswordContract $user);
* @param string $token
* @return bool
*/
public function exists(CanResetPasswordContract $user, $token);
public function exists(CanResetPasswordContract $user, #[\SensitiveParameter] $token);

/**
* Determine if the given user recently created a password reset token.
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Auth/RequestGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function user()
* @param array $credentials
* @return bool
*/
public function validate(array $credentials = [])
public function validate(#[\SensitiveParameter] array $credentials = [])
{
return ! is_null((new static(
$this->callback, $credentials['request'], $this->getProvider()
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Auth/SessionGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ protected function shouldLogin($callbacks, AuthenticatableContract $user)
* @param array $credentials
* @return void
*/
protected function rehashPasswordIfRequired(AuthenticatableContract $user, array $credentials)
protected function rehashPasswordIfRequired(AuthenticatableContract $user, #[\SensitiveParameter] array $credentials)
{
if ($this->rehashOnLogin) {
$this->provider->rehashPasswordIfRequired($user, $credentials);
Expand Down
10 changes: 5 additions & 5 deletions src/Illuminate/Contracts/Auth/UserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function retrieveById($identifier);
* @param string $token
* @return \Illuminate\Contracts\Auth\Authenticatable|null
*/
public function retrieveByToken($identifier, $token);
public function retrieveByToken($identifier, #[\SensitiveParameter] $token);

/**
* Update the "remember me" token for the given user in storage.
Expand All @@ -28,15 +28,15 @@ public function retrieveByToken($identifier, $token);
* @param string $token
* @return void
*/
public function updateRememberToken(Authenticatable $user, $token);
public function updateRememberToken(Authenticatable $user, #[\SensitiveParameter] $token);

/**
* Retrieve a user by the given credentials.
*
* @param array $credentials
* @return \Illuminate\Contracts\Auth\Authenticatable|null
*/
public function retrieveByCredentials(array $credentials);
public function retrieveByCredentials(#[\SensitiveParameter] array $credentials);

/**
* Validate a user against the given credentials.
Expand All @@ -45,7 +45,7 @@ public function retrieveByCredentials(array $credentials);
* @param array $credentials
* @return bool
*/
public function validateCredentials(Authenticatable $user, array $credentials);
public function validateCredentials(Authenticatable $user, #[\SensitiveParameter] array $credentials);

/**
* Rehash the user's password if required and supported.
Expand All @@ -55,5 +55,5 @@ public function validateCredentials(Authenticatable $user, array $credentials);
* @param bool $force
* @return void
*/
public function rehashPasswordIfRequired(Authenticatable $user, array $credentials, bool $force = false);
public function rehashPasswordIfRequired(Authenticatable $user, #[\SensitiveParameter] array $credentials, bool $force = false);
}
2 changes: 1 addition & 1 deletion src/Illuminate/Contracts/Encryption/Encrypter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface Encrypter
*
* @throws \Illuminate\Contracts\Encryption\EncryptException
*/
public function encrypt($value, $serialize = true);
public function encrypt(#[\SensitiveParameter] $value, $serialize = true);

/**
* Decrypt the given value.
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Contracts/Encryption/StringEncrypter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface StringEncrypter
*
* @throws \Illuminate\Contracts\Encryption\EncryptException
*/
public function encryptString($value);
public function encryptString(#[\SensitiveParameter] $value);

/**
* Decrypt the given string without unserialization.
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Contracts/Hashing/Hasher.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function info($hashedValue);
* @param array $options
* @return string
*/
public function make($value, array $options = []);
public function make(#[\SensitiveParameter] $value, array $options = []);

/**
* Check the given plain value against a hash.
Expand All @@ -29,7 +29,7 @@ public function make($value, array $options = []);
* @param array $options
* @return bool
*/
public function check($value, $hashedValue, array $options = []);
public function check(#[\SensitiveParameter] $value, $hashedValue, array $options = []);

/**
* Check if the given hash has been hashed using the given options.
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -1353,7 +1353,7 @@ public function fromEncryptedString($value)
* @param mixed $value
* @return string
*/
protected function castAttributeAsEncryptedString($key, $value)
protected function castAttributeAsEncryptedString($key, #[\SensitiveParameter] $value)
{
return static::currentEncrypter()->encrypt($value, false);
}
Expand Down Expand Up @@ -1386,7 +1386,7 @@ protected static function currentEncrypter()
* @param mixed $value
* @return string
*/
protected function castAttributeAsHashedString($key, $value)
protected function castAttributeAsHashedString($key, #[\SensitiveParameter] $value)
{
if ($value === null) {
return null;
Expand Down
8 changes: 4 additions & 4 deletions src/Illuminate/Encryption/Encrypter.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static function generateKey($cipher)
*
* @throws \Illuminate\Contracts\Encryption\EncryptException
*/
public function encrypt($value, $serialize = true)
public function encrypt(#[\SensitiveParameter] $value, $serialize = true)
{
$iv = random_bytes(openssl_cipher_iv_length(strtolower($this->cipher)));

Expand Down Expand Up @@ -139,7 +139,7 @@ public function encrypt($value, $serialize = true)
*
* @throws \Illuminate\Contracts\Encryption\EncryptException
*/
public function encryptString($value)
public function encryptString(#[\SensitiveParameter] $value)
{
return $this->encrypt($value, false);
}
Expand Down Expand Up @@ -217,7 +217,7 @@ public function decryptString($payload)
* @param string $key
* @return string
*/
protected function hash($iv, $value, $key)
protected function hash(#[\SensitiveParameter] $iv, #[\SensitiveParameter] $value, #[\SensitiveParameter] $key)
{
return hash_hmac('sha256', $iv.$value, $key);
}
Expand Down Expand Up @@ -291,7 +291,7 @@ protected function validMac(array $payload)
* @param string $key
* @return bool
*/
protected function validMacForKey($payload, $key)
protected function validMacForKey(#[\SensitiveParameter] $payload, $key)
{
return hash_equals(
$this->hash($payload['iv'], $payload['value'], $key), $payload['mac']
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Hashing/AbstractHasher.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function info($hashedValue)
* @param array $options
* @return bool
*/
public function check($value, $hashedValue, array $options = [])
public function check(#[\SensitiveParameter] $value, $hashedValue, array $options = [])
{
if (is_null($hashedValue) || strlen($hashedValue) === 0) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Hashing/Argon2IdHasher.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Argon2IdHasher extends ArgonHasher
*
* @throws \RuntimeException
*/
public function check($value, $hashedValue, array $options = [])
public function check(#[\SensitiveParameter] $value, $hashedValue, array $options = [])
{
if ($this->verifyAlgorithm && ! $this->isUsingCorrectAlgorithm($hashedValue)) {
throw new RuntimeException('This password does not use the Argon2id algorithm.');
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Hashing/ArgonHasher.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function __construct(array $options = [])
*
* @throws \RuntimeException
*/
public function make($value, array $options = [])
public function make(#[\SensitiveParameter] $value, array $options = [])
{
$hash = @password_hash($value, $this->algorithm(), [
'memory_cost' => $this->memory($options),
Expand Down Expand Up @@ -93,7 +93,7 @@ protected function algorithm()
*
* @throws \RuntimeException
*/
public function check($value, $hashedValue, array $options = [])
public function check(#[\SensitiveParameter] $value, $hashedValue, array $options = [])
{
if ($this->verifyAlgorithm && ! $this->isUsingCorrectAlgorithm($hashedValue)) {
throw new RuntimeException('This password does not use the Argon2i algorithm.');
Expand Down
Loading