codeigniter4 / codeigniter4/shield
Bug: Assigning null to ?array $identities property without proper handling
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- PHP
- Star
- 426
- Fork
- 143
- Merge trung bình
- 9 giờ 19 phút
- Pull request đã merge (30 ngày)
- 6
Mô tả
PHP Version
8.2.7
CodeIgniter4 Version
4.6.3
Shield Version
1.2.0
Which operating systems have you tested for this bug?
Windows
Which server did you use?
cli-server (PHP built-in webserver)
Database
mysqlite(memory unittest)
Did you customize Shield?
yes:
class User extends \CodeIgniter\Shield\Entities\User
.
.
.
public function saveUsernameIdentity(): bool
{
if (empty($this->username) && empty($this->password) && empty($this->password_hash)) {
return true;
}
/** @var UserIdentityModel $identityModel */
$identityModel = model(UserIdentityModel::class);
$identity = $this->getIdentity('username_password');
if ($identity === null && !empty($this->username)) {
$this->identities = null;
$this->createUsernameIdentity( [
'username' => $this->username,
'password' => '',
]);
$identity = $this->getUsernameIdentity();
}
if ($identity !== null) {
if (!empty($this->username)) {
$identity->secret = $this->username;
}
if (!empty($this->password)) {
$identity->secret2 = service('passwords')->hash($this->password);
}
if (!empty($this->password_hash) && empty($this->password)) {
$identity->secret2 = $this->password_hash;
}
try {
$identityModel->save($identity);
} catch (\CodeIgniter\Database\Exceptions\DataException $e) {
$messages = [
lang('Database.emptyDataset', ['insert']),
lang('Database.emptyDataset', ['update']),
];
if (in_array($e->getMessage(), $messages, true)) {
return true;
}
throw $e;
}
}
return true;
}
What happened?
the $identities property is correctly declared as nullable array:
https://github.com/codeigniter4/shield/blob/d07c0f9442dd0712b3fa39bfba677838ff1b8e26/src/Entities/User.php#L50
However, in several places, we directly assign null like these:
TypeError: CodeIgniter\Shield\Entities\User::setIdentities(): Argument 1 ($identities) must be of type array, null given,
Steps to Reproduce
try to reload all identities
Expected Output
reload identities without error
Anything else?
No response
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu trong src/Entities/User.php, đặc biệt là phần khai báo nullable của $identities gần dòng 50 và các phép gán quanh dòng 130 và 149. Tái hiện vấn đề bằng cách tải lại tất cả identity, sau đó kiểm tra đường đi của setter gây ra TypeError. Hoàn tất khi các identity được tải lại mà không có lỗi liên quan đến null.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- php
- Lĩnh vực
- authentication
- Loại issue
- Lỗi
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 52/100