Bug: Assigning null to ?array $identities property without proper handling
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 52/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- php
- Ambito
- authentication
Direzione di ricerca
Inizia in src/Entities/User.php, in particolare con la dichiarazione nullable di $identities intorno alla riga 50 e con le assegnazioni intorno alle righe 130 e 149. Riproduci il problema ricaricando tutte le identità, quindi esamina il percorso del setter che genera il TypeError. Il lavoro è completato quando le identità vengono ricaricate senza l'errore relativo a null.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- PHP
- Stelle
- 426
- Fork
- 144
- Merge medio
- 3g 14h
- PR unite (30g)
- 2
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di codeigniter4/shield
-
Dev: Add bot detection for magic linksForse già presa @datamweb l’ha presa 313 giorni fa. Apertadev
codeigniter4/shield#1293 · 5 commenti · 1 assegnatario ·
-
Bug: Auth.php ErrorsApertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 35/100
codeigniter4/shield#1270 · 6 commenti ·
-
dev enhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
codeigniter4/shield#1255 · 1 commento · 1 reazione ·
-
dev github_actions
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
codeigniter4/shield#792 · 3 commenti · 1 reazione ·
Tutte le issue di codeigniter4/shield
Issue simili
-
sync-en
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno
-
sync-en
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 4 giorni
-
Перевод устарел
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
-
bug
Difficoltà 2/5 Mezza giornata Idoneità per principianti 76/100
m3ue/m3u-editor#1604 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
femiwiki/docker-mediawiki#1497 ·
I maintainer di solito rispondono entro 1 giorno