Skip to content

Commit f7545a9

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into 4.8
2 parents 99f9f92 + 37bf585 commit f7545a9

38 files changed

Lines changed: 2022 additions & 72 deletions

‎CHANGELOG.md‎

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,80 @@
11
# Changelog
22

3+
## [v4.7.6](https://github.com/codeigniter4/CodeIgniter4/tree/v4.7.6) (2026-11-01)
4+
[Full Changelog](https://github.com/codeigniter4/CodeIgniter4/compare/v4.7.5...v4.7.6)
5+
6+
### Security
7+
8+
* **Cache:** ``FileHandler::deleteMatching()`` now matches the pattern against cache
9+
file names only. Previously, a pattern such as ``../*`` could delete files outside
10+
the cache directory. Patterns can no longer match files in subdirectories of the
11+
cache directory, so those files are no longer deleted. Special characters in the
12+
cache path, such as ``[``, are no longer interpreted as part of the pattern.
13+
See the `Security advisory GHSA-9hf2-g3w9-pfmp <https://github.com/codeigniter4/CodeIgniter4/security/advisories/GHSA-9hf2-g3w9-pfmp>`_
14+
for more information. See :ref:`upgrade-476-cache-delete-matching` for migration
15+
instructions.
16+
* **Model:** Fixed a mass assignment vulnerability in ``replace()``.
17+
The method now discards fields not listed in ``$allowedFields`` when field
18+
protection is enabled, while retaining a supplied primary key. Input emptied
19+
by filtering, or reduced to only its primary key, now throws a ``DataException``.
20+
Previously, applications passing untrusted input to ``replace()`` could write
21+
protected columns. See :doc:`Upgrading from 4.7.5 to 4.7.6 </installation/upgrade_476>`
22+
for migration instructions.
23+
See the `Security advisory GHSA-jv74-fx4h-m63x <https://github.com/codeigniter4/CodeIgniter4/security/advisories/GHSA-jv74-fx4h-m63x>`_
24+
for more information.
25+
* **Security Helper:** Fixed a path traversal vulnerability in ``sanitize_filename()``.
26+
Backslashes were only removed by a final ``stripslashes()`` call after filtering.
27+
When ``$relativePath`` was ``true``, input such as ``.\./`` became ``../`` on all
28+
platforms. In both modes, repeated backslashes could survive as Windows path
29+
separators, and ``\0`` could become a NUL byte.
30+
Backslashes are now removed during filtering, and ``stripslashes()`` is no longer
31+
called. Forward slashes are still preserved when ``$relativePath`` is ``true``.
32+
The same applies to ``Security::sanitizeFilename()``.
33+
See :doc:`Upgrading from 4.7.5 to 4.7.6 </installation/upgrade_476>` and the
34+
`Security advisory GHSA-9j59-qcxw-q7qm <https://github.com/codeigniter4/CodeIgniter4/security/advisories/GHSA-9j59-qcxw-q7qm>`_
35+
for more information.
36+
* **Database:** Fixed a SQL injection vulnerability in named query bindings.
37+
When a query combined named binds (``:name:``) with a value that was already
38+
escaped and rendered into the SQL (for example a subquery passed to ``where()``,
39+
``union()``, ``fromSubquery()`` or ``selectSubquery()``, a custom ``where()``
40+
string built with ``$db->escape()``, the ``WHERE`` binds of ``deleteBatch()``,
41+
or a manually escaped fragment in ``$db->query()``), a placeholder inside that
42+
value was replaced with the bind of the same name, which could break out of the
43+
string literal. Placeholders are now ignored inside quoted strings, quoted
44+
identifiers and SQL comments, and the ``WHERE`` binds of ``deleteBatch()`` are
45+
substituted only after the batch data has been rendered into the query.
46+
Plain ``where()``, ``like()``, ``insert()`` and ``update()`` calls were not affected.
47+
See the `Security advisory GHSA-25rf-99hr-7pmr <https://github.com/codeigniter4/CodeIgniter4/security/advisories/GHSA-25rf-99hr-7pmr>`_
48+
and :ref:`upgrade-476-named-binds` for more information.
49+
50+
### Fixed Bugs
51+
52+
* fix: preserve JSON request body when CSRF token is not in it by @gr8man in https://github.com/codeigniter4/CodeIgniter4/pull/10620
53+
* fix: sort generator imports in templates with CRLF line endings by @paulbalandan in https://github.com/codeigniter4/CodeIgniter4/pull/10622
54+
* fix: handle invalid values and empty tag names in XMLFormatter by @gr8man in https://github.com/codeigniter4/CodeIgniter4/pull/10626
55+
* fix: detect X-Forwarded-Proto case-insensitively in isSecure() by @gr8man in https://github.com/codeigniter4/CodeIgniter4/pull/10627
56+
* fix: refresh REQUEST after URI GET normalization by @rahul05ranjan in https://github.com/codeigniter4/CodeIgniter4/pull/10606
57+
* fix: widen accepted values in `set_value()`'s `$default` by @paulbalandan in https://github.com/codeigniter4/CodeIgniter4/pull/10641
58+
* fix: fix array handling in ContentSecurityPolicy::setDefaultSrc() and add addDefaultSrc() by @gr8man in https://github.com/codeigniter4/CodeIgniter4/pull/10635
59+
* fix: reject missing keys in `CLI::promptByMultipleKeys()` by @paulbalandan in https://github.com/codeigniter4/CodeIgniter4/pull/10654
60+
* fix: normalize string values and keys in `ContentSecurityPolicy::addOption()` by @gr8man in https://github.com/codeigniter4/CodeIgniter4/pull/10636
61+
* fix(HTTP): read request body when `post_max_size` is unlimited by @gr8man in https://github.com/codeigniter4/CodeIgniter4/pull/10646
62+
* fix: apply `ContentSecurityPolicy::reportOnly()` to config sources after construction by @paulbalandan in https://github.com/codeigniter4/CodeIgniter4/pull/10663
63+
* fix: stop prompts from asking forever when the input ends by @paulbalandan in https://github.com/codeigniter4/CodeIgniter4/pull/10658
64+
* fix: ignore media ranges without a subtype in `Negotiate::media()` by @wleeaf in https://github.com/codeigniter4/CodeIgniter4/pull/10660
65+
* fix: clear transaction state when reconnect() replaces the socket by @KevinBlakeLopez in https://github.com/codeigniter4/CodeIgniter4/pull/10650
66+
* fix: do not let wildcards select values excluded with q=0 in `Negotiate` by @wleeaf in https://github.com/codeigniter4/CodeIgniter4/pull/10661
67+
* fix: keep writes transactional after MySQL deadlock 1213 by @KevinBlakeLopez in https://github.com/codeigniter4/CodeIgniter4/pull/10651
68+
* fix(Cache): isolate the factories cache files used by the tests by @gr8man in https://github.com/codeigniter4/CodeIgniter4/pull/10647
69+
* fix: restore the timezone, locale and string format when unserializing `Time` by @paulbalandan in https://github.com/codeigniter4/CodeIgniter4/pull/10682
70+
* fix: preserve subclass types in route group callbacks by @maniaba in https://github.com/codeigniter4/CodeIgniter4/pull/10644
71+
* fix(HTTP): remove invalid `CURLOPT_HTTPHEADER` string assignment in `CURLRequest` by @gr8man in https://github.com/codeigniter4/CodeIgniter4/pull/10695
72+
73+
### Refactoring
74+
75+
* refactor: remove `@see` test annotations in source by @paulbalandan in https://github.com/codeigniter4/CodeIgniter4/pull/10624
76+
* refactor: fix `null` checks that are always `false` by @paulbalandan in https://github.com/codeigniter4/CodeIgniter4/pull/10670
77+
378
## [v4.7.5](https://github.com/codeigniter4/CodeIgniter4/tree/v4.7.5) (2026-10-09)
479
[Full Changelog](https://github.com/codeigniter4/CodeIgniter4/compare/v4.7.4...v4.7.5)
580

‎admin/generate-changelog.php‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,13 @@
140140
exit(0);
141141
}
142142

143-
$updated = preg_replace('/\A# Changelog\n\n/', "# Changelog\n\n{$entry}\n", $changelog, 1, $count);
143+
$updated = preg_replace_callback(
144+
'/\A# Changelog\n\n/',
145+
static fn (): string => "# Changelog\n\n{$entry}\n",
146+
$changelog,
147+
1,
148+
$count,
149+
);
144150

145151
if ($count !== 1) {
146152
echo 'Could not find the "# Changelog" header in CHANGELOG.md.' . "\n";

‎admin/update-upgrade-guide.php‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,23 @@ function bullets(array $items): string
7979
// Paths that are not part of the project space. Keep in sync with the
8080
// distribution repos: `tests/` is not used there, see "admin/starter/tests".
8181
$excludes = [
82-
':!.github/', ':!admin/', ':!changelogs/', ':!contributing/',
83-
':!system/', ':!tests/', ':!user_guide_src/', ':!utils/',
84-
':!*.json', ':!*.xml', ':!*.dist', ':!rector.php', ':!structarmed.php',
85-
':!phpstan*', ':!psalm*', ':!.php-cs-fixer.*', ':!LICENSE', ':!CHANGELOG.md',
82+
':!.github/',
83+
':!admin/',
84+
':!changelogs/',
85+
':!contributing/',
86+
':!system/',
87+
':!tests/',
88+
':!user_guide_src/',
89+
':!utils/',
90+
':!.*',
91+
':!*.md',
92+
':!*.json',
93+
':!*.xml',
94+
':!phpstan*',
95+
':!psalm*',
96+
':!rector.php',
97+
':!structarmed*',
98+
':!LICENSE',
8699
];
87100

88101
$command = sprintf(

‎composer.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"psr/log": "^3.0"
1818
},
1919
"require-dev": {
20-
"boundwize/structarmed": "^0.19",
20+
"boundwize/structarmed": "^0.20",
2121
"codeigniter/phpstan-codeigniter": "^2.1",
2222
"fakerphp/faker": "^1.24",
2323
"kint-php/kint": "^6.1",

‎phpdoc.dist.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<output>api/build/</output>
1111
<cache>api/cache/</cache>
1212
</paths>
13-
<version number="4.7.5">
13+
<version number="4.7.6">
1414
<api format="php">
1515
<source dsn=".">
1616
<path>system</path>

‎system/BaseModel.php‎

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ abstract class BaseModel
130130

131131
/**
132132
* Determines whether the model should protect field names during
133-
* mass assignment operations such as $this->insert(), $this->update().
133+
* mass assignment operations such as $this->insert(), $this->update(), $this->replace().
134134
*
135135
* When set to `true`, only the fields explicitly defined in the `$allowedFields`
136136
* property will be allowed for mass assignment. This helps prevent
@@ -149,7 +149,7 @@ abstract class BaseModel
149149

150150
/**
151151
* An array of field names that are allowed
152-
* to be set by the user in inserts/updates.
152+
* to be set by the user in inserts/updates/replaces.
153153
*
154154
* @var list<string>
155155
*/
@@ -1328,6 +1328,8 @@ public function onlyDeleted()
13281328
* @param bool $returnSQL `true` means SQL is returned, `false` will execute the query.
13291329
*
13301330
* @return BaseResult|false|Query|string
1331+
*
1332+
* @throws DataException
13311333
*/
13321334
public function replace(?array $row = null, bool $returnSQL = false)
13331335
{
@@ -1336,7 +1338,14 @@ public function replace(?array $row = null, bool $returnSQL = false)
13361338
return false;
13371339
}
13381340

1339-
$row = (array) $row;
1341+
$row = (array) $row;
1342+
$hasData = $row !== [];
1343+
$row = $this->doProtectFieldsForReplace($row);
1344+
1345+
if ($hasData && $row === []) {
1346+
throw DataException::forEmptyDataset('replace');
1347+
}
1348+
13401349
$row = $this->setCreatedField($row, $this->setDate());
13411350
$row = $this->setUpdatedField($row, $this->setDate());
13421351

@@ -1591,6 +1600,20 @@ protected function doProtectFieldsForUpdate(array $row): array
15911600
return $this->doProtectFields($row);
15921601
}
15931602

1603+
/**
1604+
* Protects replacement data before generated timestamps are added.
1605+
*
1606+
* @param row_array $row
1607+
*
1608+
* @return row_array
1609+
*
1610+
* @throws DataException
1611+
*/
1612+
protected function doProtectFieldsForReplace(array $row): array
1613+
{
1614+
return $this->doProtectFields($row);
1615+
}
1616+
15941617
/**
15951618
* Sets the timestamp or current timestamp if null value is passed.
15961619
*

‎system/Cache/Handlers/FileHandler.php‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
use CodeIgniter\Cache\LockStores\FileLockStore;
2020
use CodeIgniter\I18n\Time;
2121
use Config\Cache;
22+
use FilesystemIterator;
2223
use Throwable;
24+
use UnexpectedValueException;
2325

2426
/**
2527
* File system cache handler
@@ -124,10 +126,25 @@ public function delete(string $key): bool
124126

125127
public function deleteMatching(string $pattern): int
126128
{
129+
// The pattern is matched against file names only and never becomes part
130+
// of a path, so it cannot reach files outside the cache directory.
131+
// Passing the cache path to glob() would also interpret special
132+
// characters in the path (e.g. "[") as part of the pattern.
133+
try {
134+
$iterator = new FilesystemIterator($this->path, FilesystemIterator::SKIP_DOTS);
135+
} catch (UnexpectedValueException) {
136+
return 0;
137+
}
138+
127139
$deleted = 0;
128140

129-
foreach (glob($this->path . $pattern, GLOB_NOSORT) as $filename) {
130-
if (is_file($filename) && @unlink($filename)) {
141+
foreach ($iterator as $file) {
142+
// FNM_PERIOD keeps glob() semantics: wildcards don't match a leading dot.
143+
if (! fnmatch($pattern, $file->getFilename(), FNM_PERIOD)) {
144+
continue;
145+
}
146+
147+
if ($file->isFile() && @unlink($file->getPathname())) {
131148
$deleted++;
132149
}
133150
}

‎system/Database/BaseBuilder.php‎

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3586,9 +3586,6 @@ protected function _deleteBatch(string $table, array $keys, array $values): stri
35863586
),
35873587
);
35883588

3589-
// convert binds in where
3590-
$this->convertWhereBindsForBatch();
3591-
35923589
$sql .= ' ' . $this->compileWhereHaving('QBWhere');
35933590

35943591
$this->QBOptions['sql'] = trim($sql);
@@ -3610,35 +3607,50 @@ protected function _deleteBatch(string $table, array $keys, array $values): stri
36103607
) . "\n";
36113608
}
36123609

3613-
return str_replace('{:_table_:}', $data, $sql);
3610+
return $this->compileBatchBinds(str_replace('{:_table_:}', $data, $sql));
36143611
}
36153612

36163613
/**
3617-
* Escapes and substitutes the WHERE binds into the QBWhere conditions
3618-
* for batch delete queries.
3614+
* Escapes and substitutes the binds into a compiled batch query.
36193615
*
3620-
* The bound values respect their escape flag and are escaped the same way
3621-
* as a regular query (see Query::matchNamedBinds()), instead of being
3622-
* injected into the SQL as raw, unescaped values.
3616+
* This must run after the batch data has been rendered into the SQL, so
3617+
* that a bound value containing `{:_table_:}` is never mixed with the
3618+
* batch data. The bound values are substituted by Query, the same way as
3619+
* in a regular query (see Query::matchNamedBinds()), so they respect their
3620+
* escape flag and placeholders inside the already escaped batch data are
3621+
* left untouched.
36233622
*
36243623
* @used-by _deleteBatch()
36253624
*/
3626-
protected function convertWhereBindsForBatch(): void
3625+
protected function compileBatchBinds(string $sql): string
36273626
{
3628-
$replacers = [];
3627+
if ($this->binds === []) {
3628+
return $sql;
3629+
}
36293630

3630-
foreach ($this->binds as $field => $bind) {
3631-
$escapedValue = $bind[1] ? $this->db->escape($bind[0]) : $bind[0];
3631+
return (new Query($this->db))
3632+
->setQuery($sql, $this->binds, false)
3633+
->getQuery();
3634+
}
36323635

3633-
if (is_array($bind[0])) {
3634-
$escapedValue = '(' . implode(',', $escapedValue) . ')';
3635-
}
3636+
/**
3637+
* Escapes and substitutes the WHERE binds into the QBWhere conditions
3638+
* for batch delete queries.
3639+
*
3640+
* @deprecated 4.7.6 No longer used. The binds are substituted into the
3641+
* compiled batch query by compileBatchBinds() instead.
3642+
*/
3643+
protected function convertWhereBindsForBatch(): void
3644+
{
3645+
foreach ($this->QBWhere as $key => $where) {
3646+
$condition = $where['condition'];
36363647

3637-
$replacers[':' . $field . ':'] = (string) $escapedValue;
3638-
}
3648+
$sql = (new Query($this->db))
3649+
->setQuery((string) $condition, $this->binds, false)
3650+
->getQuery();
36393651

3640-
foreach ($this->QBWhere as $key => $where) {
3641-
$this->QBWhere[$key]['condition'] = strtr($where['condition'], $replacers);
3652+
// Keep RawSql conditions as RawSql, as they are compiled differently.
3653+
$this->QBWhere[$key]['condition'] = $condition instanceof RawSql ? $condition->with($sql) : $sql;
36423654
}
36433655
}
36443656

‎system/Database/OCI8/Builder.php‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -491,9 +491,6 @@ protected function _deleteBatch(string $table, array $keys, array $values): stri
491491
),
492492
);
493493

494-
// convert binds in where
495-
$this->convertWhereBindsForBatch();
496-
497494
$sql .= ' ' . str_replace(
498495
'WHERE ',
499496
'AND ',
@@ -526,7 +523,7 @@ protected function _deleteBatch(string $table, array $keys, array $values): stri
526523
) . " FROM DUAL\n";
527524
}
528525

529-
return str_replace('{:_table_:}', $data, $sql);
526+
return $this->compileBatchBinds(str_replace('{:_table_:}', $data, $sql));
530527
}
531528

532529
/**

‎system/Database/Postgre/Builder.php‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -700,9 +700,6 @@ static function ($key, $value) use ($table, $alias, $that): RawSql|string {
700700
),
701701
);
702702

703-
// convert binds in where
704-
$this->convertWhereBindsForBatch();
705-
706703
$sql .= ' ' . str_replace(
707704
'WHERE ',
708705
'AND ',
@@ -734,6 +731,6 @@ static function ($key, $value) use ($table, $alias, $that): RawSql|string {
734731
) . "\n";
735732
}
736733

737-
return str_replace('{:_table_:}', $data, $sql);
734+
return $this->compileBatchBinds(str_replace('{:_table_:}', $data, $sql));
738735
}
739736
}

0 commit comments

Comments
 (0)