-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The rule named for the filename does not read the filename\n\nIn CodeIgniter 4.7.2's `system/Validation/StrictRules/FileRules.php`, the `ext_in` method ends in three lines that do all of the validating:\n\n```php\npublic function ext_in(?string $blank, string $params): bool\n{\n $params = explode(',', $params);\n $name = array_shift($params);\n\n $files = $this->request->getFileMultiple($name);\n if ($files === null) {\n $files = [$this->request->getFile($name)];\n }\n\n foreach ($files as $file) {\n if ($file === null) {\n return false;\n }\n\n if ($file->getError() === UPLOAD_ERR_NO_FILE) {\n return true;\n }\n\n if (! in_array($file->guessExtension(), $params, true)) {\n return false;\n }\n }\n\n return true;\n}\n```\n\nThe 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.\n\nThe patch that lands in 4.7.3, committed on 2026-05-20 with the GitHub-private-security-fork signature \"Merge commit from fork\":\n\n```diff\n- if (! in_array($file->guessExtension(), $params, true)) {\n+ // Check the real filename extension, not only the guessed extension.\n+ $clientExtension = strtolower($file->getClientExtension());\n+\n+ if ($clientExtension === '' || ! in_array($clientExtension, $params, true)) {\n+ return false;\n+ }\n+\n+ if ($file->guessExtension() !== $clientExtension) {\n return false;\n }\n```\n\nTwo 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.\n\n## `getClientExtension()` has said \"not trusted\" since 2016\n\n`system/HTTP/Files/UploadedFile.php` was added in commit `940096d2b` on 2016-03-30. The docstring on `getClientExtension()` in that commit:\n\n```php\n/**\n * Returns the original file extension, based on the file name that\n * was uploaded. This is NOT a trusted source.\n * For a trusted version, use guessExtension() instead.\n *\n * @return string|null\n */\npublic function getClientExtension(): string\n{\n return pathinfo($this->path, PATHINFO_EXTENSION);\n}\n```\n\nThat 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.\n\nIn 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:\n\n> `Config\\Mimes::guessExtensionFromType` now only reverse searches the `$mimes` array if no extension is proposed (i.e., usually not for uploaded files).\n>\n> 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()`.\n>\n> These changes increase security when handling uploaded files as the client can no longer force a wrong mime type on the application.\n\nThe 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.\n\nTwo 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.\n\n## `guessExtension` is `finfo` all the way down\n\n`$file->guessExtension()` in 4.7.2 is two lines:\n\n```php\npublic function guessExtension(): string\n{\n return Mimes::guessExtensionFromType($this->getMimeType(), $this->getClientExtension()) ?? '';\n}\n```\n\n`$file->getMimeType()` in `system/Files/File.php`:\n\n```php\npublic function getMimeType(): string\n{\n if (! function_exists('finfo_open')) {\n return $this->originalMimeType ?? 'application/octet-stream';\n }\n\n $finfo = finfo_open(FILEINFO_MIME_TYPE);\n\n return finfo_file($finfo, $this->getRealPath() ?: $this->__toString());\n}\n```\n\n`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.\n\n`Mimes::guessExtensionFromType()` in `app/Config/Mimes.php`:\n\n```php\npublic static function guessExtensionFromType(string $type, ?string $proposedExtension = null)\n{\n $type = trim(strtolower($type), '. ');\n\n $proposedExtension = trim(strtolower($proposedExtension ?? ''));\n\n if (\n $proposedExtension !== ''\n && array_key_exists($proposedExtension, static::$mimes)\n && in_array($type, (array) static::$mimes[$proposedExtension], true)\n ) {\n // The detected mime type matches with the proposed extension.\n return $proposedExtension;\n }\n\n // Reverse check the mime type list if no extension was proposed.\n // This search is order sensitive!\n foreach (static::$mimes as $ext => $types) {\n if (in_array($type, (array) $types, true)) {\n return $ext;\n }\n }\n\n return null;\n}\n```\n\nThe 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.\n\nThe 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.\n\nThe 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.\n\n## Two extensions live in every upload\n\nThe Ninja Forms File Uploads plugin shipped this shape in May. [CVE-2026-0740](/posts/ninja-forms-cve-2026-0740-two-patches) 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.\n\nCodeIgniter4'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.\n\nThe 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.\n\n## `mime_in` and `is_image` inherit the same disconnect\n\nThe patch closed `ext_in`. The same file ships two other validation rules with the same shape.\n\n`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.\n\n`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.\n\nThe 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.\n\nPoC: [GHSA-2gr4-ppc7-7mhx](https://github.com/codeigniter4/CodeIgniter4/security/advisories/GHSA-2gr4-ppc7-7mhx)","closing_line":"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.","hook_md":"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.","post_id":630,"slug":"codeigniter4-ext-in-named-for-the-filename","title":"CVE-2026-48062: CodeIgniter4's ext_in Is Named For the Filename. It Reads finfo.","type":"initial","unreadable_sentence":"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."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCat45fwAKCRDeZjl4jgkQ JpZOAQDY3yi3XoCnJklD21ERJiGH3gdS7FkHNlQWlvwAFqZlIQEAtLjllhxsmRiP gNn0XAdJ5HMgItVe0YDphsJZOy3T4wU= =09Zy -----END PGP SIGNATURE-----