Home/ Engineering Insights/ CodeIgniter 4 SQL Injection (GHSA-25rf-99hr-7pmr): Fixed in 4.7.6

CodeIgniter 4 SQL Injection (GHSA-25rf-99hr-7pmr): Fixed in 4.7.6

Source. This article is based on GitHub Security Advisory GHSA-25rf-99hr-7pmr: SQL injection in CodeIgniter4 Query Builder and db->query(). Details were checked against it on December 1, 2026; check the source for later changes.

On 1 November 2026 the CodeIgniter team released 4.7.6 of CodeIgniter 4, with four security fixes. The most serious is GHSA-25rf-99hr-7pmr, a SQL injection in the Query Builder and $db->query(). The advisory rates it High (CVSS 3.1 score 8.1) and lists 4.7.5 and earlier as affected. It has no CVE identifier at the time of writing. The Packagist advisory feed marks every release below 4.7.6 as affected for all four issues.

If you maintain an older CodeIgniter 4 application that nobody has touched in a while, this is a good moment to look at it.

What the SQL injection is

CodeIgniter lets you write named binds such as :name: in a query and supply the values separately. According to the advisory, the framework replaced these placeholders across the whole SQL string, including text that came from values already escaped and inserted into the query. If one escaped value contains a placeholder name, and an attacker controls the value bound to that name, the bound value can break out of a string literal and run arbitrary SQL.

The advisory lists the code paths where this applies:

  • subqueries passed to where(), having(), union(), unionAll(), fromSubquery() and selectSubquery()
  • custom where() or having() strings built with $db->escape()
  • deleteBatch() WHERE conditions
  • $db->query() calls that mix named binds with manually escaped fragments

The advisory states that plain where(), like(), whereIn(), insert() and update() were not affected. It also says there is no workaround other than removing one of the two patterns from each affected query. Upgrading is the fix.

The other three fixes in 4.7.6

The 4.7.6 changelog lists these security fixes alongside the SQL injection. We summarise them here and leave the details to the changelog and the linked advisories.

  • File cache (GHSA-9hf2-g3w9-pfmp): FileHandler::deleteMatching() now matches patterns only against cache file names. Patterns such as ../* could previously delete files outside the cache directory. Files in cache subdirectories are no longer deleted by it.
  • Model (GHSA-jv74-fx4h-m63x): replace() had a mass assignment problem. With field protection on, it now drops fields not in $allowedFields and keeps a supplied primary key. If filtering leaves no input, it throws a DataException.
  • Security helper (GHSA-9j59-qcxw-q7qm): sanitize_filename() had a path traversal flaw caused by how backslashes were removed. The same fix applies to Security::sanitizeFilename().

Two of these change behaviour, so read the upgrade notes before you ship. The changelog points to migration sections titled "File Cache deleteMatching() No Longer Matches Subdirectories", "Model Field Protection for replace()" and "Named Binds Are No Longer Replaced Inside Quoted Values". The changelog page does not reproduce their contents, so use the official upgrade guide for 4.7.5 to 4.7.6.

How to tell whether you are affected

First, check the installed version. If you use Composer:

composer show codeigniter4/framework

Anything below 4.7.6 is listed as affected. If you installed the framework by copying files rather than through Composer, check the version constant in your system/ directory and follow the manual upgrade steps in the official guide.

Second, find the risky query patterns. The advisory names them, so a plain text search over your application code is a reasonable starting point. These commands are our suggestion, not something from the advisory, and they will produce false positives:

grep -rnE "escape\(|fromSubquery|selectSubquery|unionAll|deleteBatch" app/
grep -rnE "\->query\(" app/

For each hit, ask one question: does this query combine a named bind with a value that was escaped by hand or built into a subquery? If it does, treat it as exposed on any release below 4.7.6, particularly where one of the values comes from a request.

The fix

Upgrade to 4.7.6 or later. On a Composer-managed project:

composer update codeigniter4/framework
composer show codeigniter4/framework

If your composer.json constrains the framework to an older minor version, loosen the constraint first. If Composer refuses because of your PHP version or other packages, read the error and do not force the install. A framework upgrade that will not resolve is often the first visible sign of a larger version problem, which we cover below.

After updating, run your test suite and exercise the code paths that use the changed APIs: cache clearing by pattern, Model::replace(), filename sanitising on uploads, and any query that mixes named binds with escaped fragments. Per the changelog, placeholders inside quoted strings, quoted identifiers and SQL comments are now ignored. A query that relied on the old substitution behaviour may now return different results, so compare before and after.

If you cannot upgrade right now

For the SQL injection, the advisory gives only one option: remove one of the two patterns from each affected query, so that a query never mixes named binds with already escaped values. In practice that means passing values as binds instead of building them into the SQL string with $db->escape(). The other three issues have no workaround in the sources we read, so plan the upgrade rather than relying on a stopgap. Until then, avoid passing request-controlled values into deleteMatching() patterns, replace() data and sanitize_filename() without your own validation. That is general hygiene on our part, not guidance taken from the advisories.

How to confirm the fix

Run composer show codeigniter4/framework on every environment that serves traffic, including staging and any forgotten admin or API hosts, and confirm it reports 4.7.6 or later. Check the version in production, not only in your repository, because a stale vendor/ directory on a server is a common gap. We have not tested the upgrade ourselves. We are relying on the maintainers' advisory and changelog for what the patch does.

When this points to a bigger legacy problem

A framework patch release should take an hour. It takes weeks when the app is pinned to an old PHP version, has no tests, and builds SQL by hand in hundreds of places. Those are the same conditions that make a SQL injection fix hard to verify. Our usual route is described in our legacy PHP modernisation roadmap: add characterisation tests first (how we add tests to legacy PHP code), then move the runtime forward in steps (upgrading from PHP 5.6 and 7 to PHP 8), and review database access as part of a security audit of the platform. If you own a CodeIgniter application that is stuck on an old release, our legacy PHP modernisation services cover exactly this work.

Frequently asked questions

Which CodeIgniter 4 version fixes GHSA-25rf-99hr-7pmr?

The advisory lists 4.7.5 and earlier as affected and 4.7.6 as the patched version. The 4.7.6 changelog is dated 1 November 2026.

Is there a workaround for the CodeIgniter named bind SQL injection?

The advisory offers no workaround other than removing one of the two risky patterns from each affected query, so that named binds are not mixed with already escaped values. Upgrading to 4.7.6 is the fix.

Which CodeIgniter queries are not affected?

The advisory states that plain where(), like(), whereIn(), insert() and update() calls were not affected. The affected paths are subqueries, hand-escaped where() or having() strings, deleteBatch() conditions and query() calls mixing named binds with escaped fragments.

Stuck on an old CodeIgniter release?

We upgrade legacy PHP applications in safe steps: tests first, then framework and PHP version upgrades, then a review of database access.

See our Legacy PHP Modernisation Services
Ravi Raghav, Founder & CEO of AllScript Lab
Written by Ravi Raghav Founder & CEO