//nefariousplan

CVE-2026-48062: CodeIgniter4's ext_in Is Named For the Filename. It Reads finfo.

vendor

pattern

cve

proof of concept

CodeIgniter4 ships a file upload validation rule called ext_in. The user guide for v4.7.2 describes it as "Fails if the file's extension is not one listed in the parameters," with the example ext_in[field_name,png,jpg,gif]. The implementation does not read the file's extension. It calls $file->guessExtension(), which runs finfo_file() against the uploaded bytes, asks Config\Mimes::guessExtensionFromType() to map the sniffed MIME back to an extension, and returns whichever extension the framework's mime table says the bytes are consistent with. A file uploaded as shell.php with GIF87a in the first eight bytes satisfies ext_in[avatar,gif]. The filename the application is about to save the bytes under is never read. CVE-2026-48062 is what happens when the rule named for the client filename stops reading the client filename and the framework's own documentation is what told it to.

The rule named for the filename does not read the filename

In CodeIgniter 4.7.2's system/Validation/StrictRules/FileRules.php, the ext_in method ends in three lines that do all of the validating:

public function ext_in(?string $blank, string $params): bool
{
    $params = explode(',', $params);
    $name   = array_shift($params);

    $files = $this->request->getFileMultiple($name);
    if ($files === null) {
        $files = [$this->request->getFile($name)];
    }

    foreach ($files as $file) {
        if ($file === null) {
            return false;
        }

        if ($file->getError() === UPLOAD_ERR_NO_FILE) {
            return true;
        }

        if (! in_array($file->guessExtension(), $params, true)) {
            return false;
        }
    }

    return true;
}

The check is in_array($file->guessExtension(), $params, true). The filename the developer will pass to move_uploaded_file() after validation, whether they read it via $file->getName(), $file->getClientName(), or $file->getClientExtension(), never enters this function. The rule asks guessExtension() and accepts whatever extension that function nominates as consistent with the uploaded bytes.

The patch that lands in 4.7.3, committed on 2026-05-20 with the GitHub-private-security-fork signature "Merge commit from fork":

-            if (! in_array($file->guessExtension(), $params, true)) {
+            // Check the real filename extension, not only the guessed extension.
+            $clientExtension = strtolower($file->getClientExtension());
+
+            if ($clientExtension === '' || ! in_array($clientExtension, $params, true)) {
+                return false;
+            }
+
+            if ($file->guessExtension() !== $clientExtension) {
                 return false;
             }

Two new checks. The first reads the client filename's extension and requires it to appear in the allowlist. The second requires the MIME-derived guess to match the client extension exactly. The comment the patch author left reads "Check the real filename extension, not only the guessed extension." That comment is the closest the framework has come to acknowledging which one of these two strings ends up on disk.

getClientExtension() has said "not trusted" since 2016

system/HTTP/Files/UploadedFile.php was added in commit 940096d2b on 2016-03-30. The docstring on getClientExtension() in that commit:

/**
 * Returns the original file extension, based on the file name that
 * was uploaded. This is NOT a trusted source.
 * For a trusted version, use guessExtension() instead.
 *
 * @return string|null
 */
public function getClientExtension(): string
{
    return pathinfo($this->path, PATHINFO_EXTENSION);
}

That docstring predates the ext_in rule by six months. When ext_in was first written in September 2016 it called $file->getExtension(), which at the time was Mimes::guessExtensionFromType($this->getType()) and shared the same content-derived basis. The framework had decided which string was untrusted before the rule existed, and the rule was written to obey.

In January 2021, PR #4056 ("Solidate mime type guessing," by Alex Schmitz) landed under the heading Improve security of mime type guessing. The CHANGELOG entry the same PR added:

Config\Mimes::guessExtensionFromType now only reverse searches the $mimes array if no extension is proposed (i.e., usually not for uploaded files).

The fallback values of UploadedFile->getExtension() and UploadedFile->guessExtension() have been changed. UploadedFile->getExtension() now returns $this->getClientExtension() instead of ''; UploadedFile->guessExtension() now returns '' instead of $this->getClientExtension().

These changes increase security when handling uploaded files as the client can no longer force a wrong mime type on the application.

The PR did three things. It added the docstring on guessExtension() calling it the "more safe version." It changed guessExtension() to return '' instead of falling back to the client extension when the MIME guess failed, so that a caller asking the "safe" question would no longer be silently answered with the unsafe one. And it changed FileRules::ext_in() from $file->getExtension() to $file->guessExtension(), so the validation rule called the function that the framework now uniformly labelled as safe.

Two of those changes did exactly what the CHANGELOG said. The third one is the one that becomes CVE-2026-48062 five years later. A validation rule named for the client filename, written for an interface where the client filename is the input, was edited to stop reading the client filename, on the grounds that the client filename was not a trusted source. The framing was right about MIME spoofing in the abstract. The framing was wrong about which string the application is going to write to disk.

guessExtension is finfo all the way down

$file->guessExtension() in 4.7.2 is two lines:

public function guessExtension(): string
{
    return Mimes::guessExtensionFromType($this->getMimeType(), $this->getClientExtension()) ?? '';
}

$file->getMimeType() in system/Files/File.php:

public function getMimeType(): string
{
    if (! function_exists('finfo_open')) {
        return $this->originalMimeType ?? 'application/octet-stream';
    }

    $finfo = finfo_open(FILEINFO_MIME_TYPE);

    return finfo_file($finfo, $this->getRealPath() ?: $this->__toString());
}

finfo_file() reads the first bytes of the uploaded file on disk and matches against libmagic's signature database. For a shell.php whose body starts with GIF87a and continues with a PHP open tag, the returned MIME type is image/gif. The $_FILES-supplied originalMimeType (the value the client typed into the Content-Type header) is ignored whenever finfo_open is available, which is every recommended deployment.

Mimes::guessExtensionFromType() in app/Config/Mimes.php:

public static function guessExtensionFromType(string $type, ?string $proposedExtension = null)
{
    $type = trim(strtolower($type), '. ');

    $proposedExtension = trim(strtolower($proposedExtension ?? ''));

    if (
        $proposedExtension !== ''
        && array_key_exists($proposedExtension, static::$mimes)
        && in_array($type, (array) static::$mimes[$proposedExtension], true)
    ) {
        // The detected mime type matches with the proposed extension.
        return $proposedExtension;
    }

    // Reverse check the mime type list if no extension was proposed.
    // This search is order sensitive!
    foreach (static::$mimes as $ext => $types) {
        if (in_array($type, (array) $types, true)) {
            return $ext;
        }
    }

    return null;
}

The function takes the client extension as $proposedExtension. For shell.php with image/gif bytes: the proposed extension is php, the mime list registered for php is ['application/x-httpd-php', 'application/x-php', 'application/x-httpd-php-source', 'text/x-php', ...], the detected type image/gif is not in that list, the first branch returns nothing. Control falls through to the reverse-table scan, which returns the first extension in static::$mimes whose mime list contains image/gif. That extension is gif. guessExtension() returns the string 'gif'. in_array('gif', ['gif', 'jpg', 'png'], true) is true. ext_in[avatar,gif,jpg,png] passes.

The comment on the reverse-table scan reads "Reverse check the mime type list if no extension was proposed." The comment is wrong about its trigger condition. The reverse check also runs when an extension IS proposed and the proposal does not match the detected MIME. In every uploaded-file path that reaches guessExtension(), an extension IS proposed (it is the suffix of getClientExtension()), and the comment's stated trigger condition never holds. The reverse-table scan runs every time the proposed extension and the content sniff disagree, which is the case the bypass relies on.

The 2021 PR's CHANGELOG entry says of the same function: "Config\Mimes::guessExtensionFromType now only reverse searches the $mimes array if no extension is proposed (i.e., usually not for uploaded files)." That sentence and the function body do not agree, and they have not agreed since the PR landed.

Two extensions live in every upload

The Ninja Forms File Uploads plugin shipped this shape in May. CVE-2026-0740 accepted a source filename with one extension and a destination filename with a different extension in the same multipart request, validated the source against an allowlist, and wrote the bytes under the destination. The pattern the post named is Validated Source, Not Destination, and its canonical signature is that the request carries two filename-shaped fields and the validator and the writer read different ones.

CodeIgniter4's ext_in is the same pattern with the two filenames in different places. The validation reads a content-derived extension. The persistence code, whatever the application chooses to call after the rule returns true, reads the request-supplied filename. $file->getName() returns the request-supplied filename. $file->getClientName() returns the request-supplied filename. $file->getClientExtension() returns the suffix of the request-supplied filename. The framework's docstrings tell developers all three are untrusted, and the framework's own ext_in rule treats them as if they did not exist. The result is identical to Ninja Forms: validation effort concentrated on one representation of the upload, persistence applied to a different representation, and both representations are called "the file's extension" in the prose around the API.

The user-facing documentation reflects the ambiguity directly. The 4.7.2 user guide says of ext_in: "Fails if the file's extension is not one listed in the parameters." The 4.7.3 patch rewrote that line: "Fails if the client filename's extension is not one listed in the parameters, or if the detected MIME type does not match the MIME types associated with the extension." The phrase "the file's extension" was ambiguous; the implementation had resolved it as "the MIME-derived extension," and an application developer reading the user guide had been entitled to resolve it as "the suffix of the filename they will see on disk." The patch settles the question against the implementation.

mime_in and is_image inherit the same disconnect

The patch closed ext_in. The same file ships two other validation rules with the same shape.

mime_in (line 161 of FileRules.php) checks $file->getMimeType(), which is the same finfo_file() content sniff. It accepts mime_in[avatar,image/gif,image/png] for a shell.php body whose first bytes are GIF87a. The validator returns true; the persistence code writes shell.php. Same Validated Source, Not Destination disconnect, undefended, no CVE.

is_image (line 125 of FileRules.php) calls Mimes::guessTypeFromExtension($file->getExtension()). $file->getExtension() after the 2021 PR returns guessExtension() ?: getClientExtension(), so it returns the MIME-derived guess when one is available and falls back to the client extension when the MIME guess fails. For shell.php with image/gif bytes the MIME guess returns gif, guessTypeFromExtension('gif') returns image/gif, and the rule's mb_strpos($type, 'image') === 0 check passes. Same disconnect, same shape, no CVE.

The 4.7.3 patch made ext_in cross-check the client extension. It did not touch mime_in or is_image. The disconnect that produced CVE-2026-48062 is in the file, not in the function. An application following the framework's documentation by reaching for mime_in[avatar,image/gif] and is_image[avatar] together, the two rules an upload form is supposed to compose, accepts whatever filename the request supplied to the suffix the application uses to persist it. The patch closed the function the public PoC took. The pattern remains.

PoC: GHSA-2gr4-ppc7-7mhx

The 2021 PR that made this bug was titled "Solidate mime type guessing." The 2026 patch that fixed it was titled "validate client extension in ext_in upload rule." Both touched the same function. The five years between them are the window during which a CodeIgniter4 application following the framework's own validation guidance accepted shell.php with GIF87a in the body.