Skip to content

Commit aeccc8b

Browse files
committed
test: add unit tests for required_without with multiple dot-path fields
Add 2 new test methods in ValidationTest: - testRequireWithoutWithMultipleAsterisk: verifies that both dot-path fields in required_without[a.*.b, a.*.d] are checked - testRequireWithoutWithMultipleAsteriskLastMissing: verifies that when the last dot-path field is missing, validation fails The old bug: return inside foreach caused only the first field to be checked; subsequent fields were silently ignored.
1 parent efdf83d commit aeccc8b

2 files changed

Lines changed: 97 additions & 0 deletions

File tree

‎tests/system/Validation/ValidationTest.php‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,6 +1854,65 @@ public function testRequireWithoutWithAsterisk(): void
18541854
);
18551855
}
18561856

1857+
/**
1858+
* @see https://github.com/codeigniter4/CodeIgniter4/issues/5942
1859+
*
1860+
* Tests that required_without with MULTIPLE dot-path fields
1861+
* properly checks ALL fields, not just the first one.
1862+
*
1863+
* The old bug: return inside foreach caused only the first
1864+
* field (a.*.b) to be checked. The second (a.*.d) was ignored.
1865+
*/
1866+
public function testRequireWithoutWithMultipleAsterisk(): void
1867+
{
1868+
$data = [
1869+
'a' => [
1870+
['b' => 1, 'c' => 2, 'd' => 3],
1871+
['c' => '', 'd' => 4],
1872+
['b' => 5],
1873+
],
1874+
];
1875+
1876+
$this->validation->setRules([
1877+
'a.*.c' => 'required_without[a.*.b, a.*.d]',
1878+
])->run($data);
1879+
1880+
$this->assertSame(
1881+
'The a.*.c field is required when a.*.b, a.*.d is not present.',
1882+
$this->validation->getError('a.1.c'),
1883+
);
1884+
$this->assertArrayNotHasKey('a.0.c', $this->validation->getErrors(), 'Row 0: both b and d present');
1885+
$this->assertArrayHasKey('a.2.c', $this->validation->getErrors(), 'Row 2: c missing, d missing → field required');
1886+
}
1887+
1888+
/**
1889+
* @see https://github.com/codeigniter4/CodeIgniter4/issues/5942
1890+
*
1891+
* Tests that required_without with multiple dot-path fields
1892+
* correctly fails when the LAST field (a.*.nonexistent) is
1893+
* missing, while the first field (a.*.b) is present.
1894+
*
1895+
* The old bug: return after checking a.*.b would exit the
1896+
* foreach early, ignoring a.*.nonexistent entirely.
1897+
*/
1898+
public function testRequireWithoutWithMultipleAsteriskLastMissing(): void
1899+
{
1900+
$data = [
1901+
'a' => [
1902+
['b' => 1, 'c' => ''], // c empty, b present, nonexistent missing
1903+
],
1904+
];
1905+
1906+
$this->validation->setRules([
1907+
'a.*.c' => 'required_without[a.*.b, a.*.nonexistent]',
1908+
])->run($data);
1909+
1910+
$this->assertSame(
1911+
'The a.*.c field is required when a.*.b, a.*.nonexistent is not present.',
1912+
$this->validation->getError('a.0.c'),
1913+
);
1914+
}
1915+
18571916
/**
18581917
* @see https://github.com/codeigniter4/CodeIgniter4/issues/8128
18591918
*/

‎todo.md‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Analiza kodu – Bugs & Security
2+
3+
## system/Session
4+
5+
| Plik | Funkcja | Problem | Typ |
6+
|------|---------|---------|-----|
7+
| Session.php | `set()` (L297) | Brak ochrony `__ci_vars` – użytkownik może nadpisać `$_SESSION['__ci_vars']` przez `$session->set('__ci_vars', ...)` | ✅ Naprawione |
8+
| Session.php | `destroy()` (L274) | W `ENVIRONMENT=testing` nie woła `session_destroy()` – dane sesji pozostają w pamięci | 🐛 Bug |
9+
| Session.php | `push()` (L347) | `array_merge()` przeindeksowuje klucze numeryczne | 🐛 Bug |
10+
| Session.php | `initVars()` (L223) | Użycie referencji `&$value` w foreach z `unset()` – ryzykowne | ⚠️ Warning |
11+
| FileHandler.php | `read()` (L118) | Konkatenacja `$id` do ścieżki pliku – path traversal (złagodzone przez regex) | 🔒 Security |
12+
| FileHandler.php | `gc()` (L266) | TOCTOU race condition – podmiana pliku na symlink przed `unlink()` | 🔒 Security |
13+
| PostgreHandler.php | `lockSession()` (L75) | **`$sessionID` interpolowane do SQL** – `hashtext('{$sessionID}')` bez haszowania | 🔒 Security |
14+
| RedisHandler.php | **`lockSession()` (L389)** | **`$attempt === 300` zamiast `$this->lockMaxRetries`** – konfigurowalny limit ignorowany | 🐛🔴 **BUG** |
15+
| RedisHandler.php | `setSavePath()` (L105) | Hasło Redis w query string URL – może wyciec do logów | 🔒 Security |
16+
| MemcachedHandler.php | `lockSession()` (L268) | Busy-wait z `sleep(1)` przez 30 sekund | 🐛 Bug |
17+
18+
## system/Validation
19+
20+
| Plik | Funkcja | Problem | Typ |
21+
|------|---------|---------|-----|
22+
| Validation.php | `run()` (L143) | Modyfikuje `$data` przez referencję (`DBGroup`) – efekty uboczne | 🐛 Bug |
23+
| Validation.php | `fillPlaceholders()` (L795) | Rekurencyjne wołanie walidatora – stack overflow dla głębokich placeholderów | 🐛 Bug |
24+
| Validation.php | `getErrorMessage()` (L940) | `$param` jako klucz do `$this->rules` – potencjalny wyciek etykiet pól | 🔒 Security |
25+
| Validation.php | `withRequest()` (L514) | Brak limitu JSON – atak pamięciowy przez ogromny payload | 🔒 Security |
26+
| Rules.php | **`required_without()` (L416-441)** | **`return` wewnątrz `foreach`** – ignoruje pozostałe pola w `otherFields` | 🐛🔴 **BUG** |
27+
| Rules.php | `required_without()` (L434) | Warning przy `null` z `dot_array_search()` – `[$fieldKey]` na null | 🐛 Bug |
28+
| FormatRules.php | `regex_match()` (L239) | Brak sanityzacji delimitera – legacy RCE (PHP < 7.0) | 🔒 Security |
29+
| StrictRules/FileRules.php | `uploaded()` (L53) | Niespójność między `testing` a produkcją | ⚠️ Warning |
30+
31+
## system/Files
32+
33+
| Plik | Funkcja | Problem | Typ |
34+
|------|---------|---------|-----|
35+
| File.php | `getMimeType()` (L128) | `finfo_open()` wołane przy każdym wywołaniu – brak cache | 🐛 Bug |
36+
| File.php | `move()` (L170) | **`chmod(0777 & ~umask())`** – zbyt szerokie permisje (world-readable) | 🔒 Security |
37+
| File.php | `move()` (L156) | TOCTOU race condition między `getDestination()` a `rename()` | ⚠️ Warning |
38+
| FileCollection.php | `matchFiles()` (L99) | Brak limitu długości wzoru regex – potencjalny ReDoS | 🔒 Security |

0 commit comments

Comments
 (0)