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
- 星标
- 426
- 派生
- 144
- 平均合并
- 3 天 14 小时
- 30 天内合并 PR
- 2
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
codeigniter4/shield 的其他 Issue
-
Dev: Add bot detection for magic links可能已有人在做 @datamweb 于 313 天前认领。 未关闭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
-
sync-en
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复
-
sync-en
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 4 天内回复
-
Перевод устарел
难度 1/5 1 小时以内 新手友好度 85/100
-
bug
难度 2/5 半天 新手友好度 76/100
m3ue/m3u-editor#1604 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
femiwiki/docker-mediawiki#1497 ·
维护者通常 1 天内回复