Skip to content

Commit

Permalink
PHP 8.2: Added #[\SensitiveParameter] to all the codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
fballiano committed Sep 29, 2024
1 parent c2af7cd commit 891b27d
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@
DeadCode\Property\RemoveUselessVarTagRector::class,
Rector\Php83\Rector\ClassMethod\AddOverrideAttributeToOverriddenMethodsRector::class,
TypeDeclaration\ClassMethod\ReturnNeverTypeRector::class
])
->withConfiguredRule(Rector\Php82\Rector\Param\AddSensitiveParameterAttributeRector::class, [
'sensitive_parameters' => [
'password'
],
]);
2 changes: 1 addition & 1 deletion app/code/core/Mage/Admin/Model/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ protected function logoutIndirect()
* @param Mage_Core_Controller_Request_Http $request
* @return Mage_Admin_Model_User|null
*/
public function login($username, $password, $request = null)
public function login($username, #[\SensitiveParameter] $password, $request = null)
{
if (empty($username) || empty($password)) {
return null;
Expand Down
8 changes: 4 additions & 4 deletions app/code/core/Mage/Admin/Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ public function getAclRole()
* @return bool
* @throws Mage_Core_Exception
*/
public function authenticate($username, $password)
public function authenticate($username, #[\SensitiveParameter] $password)
{
$config = Mage::getStoreConfigFlag('admin/security/use_case_sensitive_login');
$result = false;
Expand Down Expand Up @@ -420,7 +420,7 @@ public function authenticate($username, $password)
* @return $this
* @throws Mage_Core_Exception
*/
public function login($username, $password)
public function login($username, #[\SensitiveParameter] $password)
{
if ($this->authenticate($username, $password)) {
$this->getResource()->recordLogin($this);
Expand Down Expand Up @@ -478,7 +478,7 @@ public function hasAssigned2Role($user)
* @param string $password
* @return string
*/
protected function _getEncodedPassword($password)
protected function _getEncodedPassword(#[\SensitiveParameter] $password)
{
return Mage::helper('core')->getHash($password, self::HASH_SALT_LENGTH);
}
Expand Down Expand Up @@ -636,7 +636,7 @@ public function validate()
* @return array|true
* @throws Zend_Validate_Exception
*/
public function validateCurrentPassword($password)
public function validateCurrentPassword(#[\SensitiveParameter] $password)
{
$result = [];

Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Adminhtml/Controller/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ protected function _validateSecretKey()
*
* @return mixed - returns true or array of errors
*/
protected function _validateCurrentPassword($password)
protected function _validateCurrentPassword(#[\SensitiveParameter] $password)
{
$user = Mage::getSingleton('admin/session')->getUser();
return $user->validateCurrentPassword($password);
Expand Down
6 changes: 3 additions & 3 deletions app/code/core/Mage/Core/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public function getRandomString($len, $chars = null)
* @param string|int|bool $salt
* @return string
*/
public function getHash($password, $salt = false)
public function getHash(#[\SensitiveParameter] $password, $salt = false)
{
return $this->getEncryptor()->getHash($password, $salt);
}
Expand All @@ -276,7 +276,7 @@ public function getHash($password, $salt = false)
* @param mixed $salt
* @return string
*/
public function getHashPassword($password, $salt = false)
public function getHashPassword(#[\SensitiveParameter] $password, $salt = false)
{
$encryptionModel = $this->getEncryptor();
$latestVersionHash = $this->getVersionHash($encryptionModel);
Expand All @@ -292,7 +292,7 @@ public function getHashPassword($password, $salt = false)
* @return bool
* @throws Exception
*/
public function validateHash($password, $hash)
public function validateHash(#[\SensitiveParameter] $password, $hash)
{
return $this->getEncryptor()->validateHash($password, $hash);
}
Expand Down
8 changes: 4 additions & 4 deletions app/code/core/Mage/Core/Model/Encryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function setHelper($helper)
* @param mixed $salt
* @return string
*/
public function getHash($password, $salt = false)
public function getHash(#[\SensitiveParameter] $password, $salt = false)
{
if (is_int($salt)) {
$salt = $this->_helper->getRandomString($salt);
Expand All @@ -82,7 +82,7 @@ public function getHash($password, $salt = false)
* @param mixed $salt
* @return string
*/
public function getHashPassword($password, $salt = null)
public function getHashPassword(#[\SensitiveParameter] $password, $salt = null)
{
if (is_int($salt)) {
$salt = $this->_helper->getRandomString($salt);
Expand Down Expand Up @@ -119,7 +119,7 @@ public function hash($data, $version = self::HASH_VERSION_MD5)
* @return bool
* @throws Exception
*/
public function validateHash($password, $hash)
public function validateHash(#[\SensitiveParameter] $password, $hash)
{
if (strlen($password) > self::MAXIMUM_PASSWORD_LENGTH) {
return false;
Expand All @@ -139,7 +139,7 @@ public function validateHash($password, $hash)
* @param int $version
* @return bool
*/
public function validateHashByVersion($password, $hash, $version = self::HASH_VERSION_MD5)
public function validateHashByVersion(#[\SensitiveParameter] $password, $hash, $version = self::HASH_VERSION_MD5)
{
if ($version == self::HASH_VERSION_LATEST && $version == $this->_helper->getVersionHash($this)) {
return password_verify($password, $hash);
Expand Down
14 changes: 7 additions & 7 deletions app/code/core/Mage/Customer/Model/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public function getSharingConfig()
* @throws Mage_Core_Exception
* @return true
*/
public function authenticate($login, $password)
public function authenticate($login, #[\SensitiveParameter] $password)
{
$this->loadByEmail($login);
if ($this->getConfirmation() && $this->isConfirmationRequired()) {
Expand Down Expand Up @@ -486,7 +486,7 @@ public function getPassword(): string
* @param string $password
* @return $this
*/
public function setPassword($password)
public function setPassword(#[\SensitiveParameter] $password)
{
$this->setData('password', $password);
$this->setPasswordHash($this->hashPassword($password));
Expand All @@ -501,7 +501,7 @@ public function setPassword($password)
* @param int $salt
* @return string
*/
public function hashPassword($password, $salt = null)
public function hashPassword(#[\SensitiveParameter] $password, $salt = null)
{
/** @var Mage_Core_Helper_Data $helper */
$helper = $this->_getHelper('core');
Expand Down Expand Up @@ -545,7 +545,7 @@ public function generatePassword($length = 8)
* @return bool
* @throws Exception
*/
public function validatePassword($password)
public function validatePassword(#[\SensitiveParameter] $password)
{
$hash = $this->getPasswordHash();
if (!$hash) {
Expand All @@ -560,7 +560,7 @@ public function validatePassword($password)
* @param string $password
* @return string
*/
public function encryptPassword($password)
public function encryptPassword(#[\SensitiveParameter] $password)
{
return Mage::helper('core')->encrypt($password);
}
Expand All @@ -571,7 +571,7 @@ public function encryptPassword($password)
* @param string $password
* @return string
*/
public function decryptPassword($password)
public function decryptPassword(#[\SensitiveParameter] $password)
{
return Mage::helper('core')->decrypt($password);
}
Expand Down Expand Up @@ -719,7 +719,7 @@ public function isAddressPrimary(Mage_Customer_Model_Address $address)
* @throws Mage_Core_Exception
* @return $this
*/
public function sendNewAccountEmail($type = 'registered', $backUrl = '', $storeId = '0', $password = null)
public function sendNewAccountEmail($type = 'registered', $backUrl = '', $storeId = '0', #[\SensitiveParameter] $password = null)
{
$types = [
'registered' => self::XML_PATH_REGISTER_EMAIL_TEMPLATE, // welcome email, when confirmation is disabled
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Customer/Model/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public function checkCustomerId($customerId)
* @param string $password
* @return bool
*/
public function login($username, $password)
public function login($username, #[\SensitiveParameter] $password)
{
/** @var Mage_Customer_Model_Customer $customer */
$customer = Mage::getModel('customer/customer')
Expand Down

0 comments on commit 891b27d

Please sign in to comment.