Bug: Assigning null to ?array $identities property without proper handling
評估
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 新手友好度
- 52/100
- Issue 類型
- 缺陷
- 描述清晰度
- 基本清楚
- 活躍度
- 停滯
- 技術堆疊
- php
研究方向
從 src/Entities/User.php 開始,特別查看第 50 行附近的 nullable $identities 宣告,以及第 130 行和第 149 行附近的指派。重新載入所有 identity 以重現問題,然後檢查引發 TypeError 的 setter 路徑。當 identity 能夠在不出現與 null 相關錯誤的情況下重新載入時,即表示完成。
由索引模型根據 Issue 內容生成。
描述
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
- 主要語言
- PHP
- 星號
- 429
- 分支
- 144
- 平均合併
- 6 小時 9 分鐘
- 30 天內合併 PR
- 4
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
codeigniter4/shield 的其他 Issue
-
Dev: Add bot detection for magic links可能已有人在做 @datamweb 於 340 天前認領。 未關閉dev
codeigniter4/shield#1293 · 5 則留言 · 已指派 1 人 ·
-
bug
難度 2/5 1-3 小時 新手友好度 35/100
codeigniter4/shield#1270 · 6 則留言 ·
-
dev enhancement
難度 5/5 一週以上 新手友好度 35/100
codeigniter4/shield#1255 · 1 則留言 · 1 個 reaction ·
-
dev github_actions
難度 3/5 1-2 天 新手友好度 35/100
codeigniter4/shield#792 · 3 則留言 · 1 個 reaction ·
查看 codeigniter4/shield 的全部 Issue
相似的 Issue
-
難度 1/5 1 小時以內 新手友好度 79/100
smarty-php/smarty#1220 ·
-
難度 2/5 1-3 小時 新手友好度 69/100
opnsense/core#11171 · 1 個 reaction ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 68/100
getgrav/grav-plugin-form#664 ·
-
claude
難度 2/5 1-3 小時 新手友好度 82/100
sprain/sprainocchio#26 ·
-
sync-en
難度 1/5 1-3 小時 新手友好度 84/100
維護者通常 1 天內回覆