Skip to content
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
5 changes: 3 additions & 2 deletions system/Encryption/EncrypterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace CodeIgniter\Encryption;

use CodeIgniter\Encryption\Exceptions\EncryptionException;
use SensitiveParameter;

/**
* CodeIgniter Encryption Handler
Expand All @@ -32,7 +33,7 @@ interface EncrypterInterface
*
* @throws EncryptionException
*/
public function encrypt($data, $params = null);
public function encrypt(#[SensitiveParameter] $data, #[SensitiveParameter] $params = null);

/**
* Decrypt - convert ciphertext into plaintext
Expand All @@ -44,5 +45,5 @@ public function encrypt($data, $params = null);
*
* @throws EncryptionException
*/
public function decrypt($data, $params = null);
public function decrypt($data, #[SensitiveParameter] $params = null);
}
5 changes: 3 additions & 2 deletions system/Encryption/Handlers/OpenSSLHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace CodeIgniter\Encryption\Handlers;

use CodeIgniter\Encryption\Exceptions\EncryptionException;
use SensitiveParameter;

/**
* Encryption handling for OpenSSL library
Expand Down Expand Up @@ -79,7 +80,7 @@ class OpenSSLHandler extends BaseHandler
/**
* {@inheritDoc}
*/
public function encrypt($data, $params = null)
public function encrypt(#[SensitiveParameter] $data, #[SensitiveParameter] $params = null)
{
// Allow key override
if ($params !== null) {
Expand Down Expand Up @@ -115,7 +116,7 @@ public function encrypt($data, $params = null)
/**
* {@inheritDoc}
*/
public function decrypt($data, $params = null)
public function decrypt($data, #[SensitiveParameter] $params = null)
{
// Allow key override
if ($params !== null) {
Expand Down
5 changes: 3 additions & 2 deletions system/Encryption/Handlers/SodiumHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace CodeIgniter\Encryption\Handlers;

use CodeIgniter\Encryption\Exceptions\EncryptionException;
use SensitiveParameter;

/**
* SodiumHandler uses libsodium in encryption.
Expand All @@ -40,7 +41,7 @@ class SodiumHandler extends BaseHandler
/**
* {@inheritDoc}
*/
public function encrypt($data, $params = null)
public function encrypt(#[SensitiveParameter] $data, #[SensitiveParameter] $params = null)
{
$this->parseParams($params);

Expand Down Expand Up @@ -71,7 +72,7 @@ public function encrypt($data, $params = null)
/**
* {@inheritDoc}
*/
public function decrypt($data, $params = null)
public function decrypt($data, #[SensitiveParameter] $params = null)
{
$this->parseParams($params);

Expand Down
9 changes: 3 additions & 6 deletions system/HTTP/CURLRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Config\App;
use Config\CURLRequest as ConfigCURLRequest;
use CurlShareHandle;
use SensitiveParameter;

/**
* A lightweight HTTP client for sending synchronous HTTP requests via cURL.
Expand Down Expand Up @@ -260,13 +261,9 @@ public function put(string $url, array $options = []): ResponseInterface
*
* @return $this
*/
public function setAuth(string $username, string $password, string $type = 'basic')
public function setAuth(string $username, #[SensitiveParameter] string $password, string $type = 'basic')
{
$this->config['auth'] = [
$username,
$password,
$type,
];
$this->config['auth'] = [$username, $password, $type];

return $this;
}
Expand Down
3 changes: 2 additions & 1 deletion system/HTTP/URI.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use CodeIgniter\Exceptions\InvalidArgumentException;
use CodeIgniter\HTTP\Exceptions\HTTPException;
use Config\App;
use SensitiveParameter;
use Stringable;

/**
Expand Down Expand Up @@ -768,7 +769,7 @@ public function withScheme(string $scheme)
*
* @TODO PSR-7: Should be `withUserInfo($user, $password = null)`.
*/
public function setUserInfo(string $user, string $pass)
public function setUserInfo(string $user, #[SensitiveParameter] string $pass)
{
$this->user = trim($user);
$this->password = trim($pass);
Expand Down
5 changes: 3 additions & 2 deletions system/Security/Security.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Config\Cookie as CookieConfig;
use Config\Security as SecurityConfig;
use ErrorException;
use SensitiveParameter;

/**
* Class Security
Expand Down Expand Up @@ -371,13 +372,13 @@ protected function randomize(string $hash): string
*
* @throws InvalidArgumentException "hex2bin(): Hexadecimal input string must have an even length"
*/
protected function derandomize(string $token): string
protected function derandomize(#[SensitiveParameter] string $token): string
{
$key = substr($token, -static::CSRF_HASH_BYTES * 2);
$value = substr($token, 0, static::CSRF_HASH_BYTES * 2);

try {
return bin2hex(hex2bin($value) ^ hex2bin($key));
return bin2hex((string) hex2bin($value) ^ (string) hex2bin($key));
} catch (ErrorException $e) {
// "hex2bin(): Hexadecimal input string must have an even length"
throw new InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
Expand Down
11 changes: 11 additions & 0 deletions user_guide_src/source/changelogs/v4.7.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ Interface Changes
Method Signature Changes
========================

- Added the ``SensitiveParameter`` attribute to various methods to conceal sensitive information from stack traces. Affected methods are:
- ``CodeIgniter\Encryption\EncrypterInterface::encrypt()``
- ``CodeIgniter\Encryption\EncrypterInterface::decrypt()``
- ``CodeIgniter\Encryption\Handlers\OpenSSLHandler::encrypt()``
- ``CodeIgniter\Encryption\Handlers\OpenSSLHandler::decrypt()``
- ``CodeIgniter\Encryption\Handlers\SodiumHandler::encrypt()``
- ``CodeIgniter\Encryption\Handlers\SodiumHandler::decrypt()``
- ``CodeIgniter\HTTP\CURLRequest::setAuth()``
- ``CodeIgniter\HTTP\URI::setUserInfo()``
- ``CodeIgniter\Security\Security::derandomize()``

Removed Deprecated Items
========================

Expand Down
Loading