Repository navigation
Description
PHP Version
8.4
CodeIgniter4 Version
4.7.7-dev (commit 08039be). I also checked 4.7.6 and the same code is there.
CodeIgniter4 Installation Method
Git
Which operating systems have you tested for this bug?
Linux
Which server did you use?
cli
Environment
development
Database
Not required for the CLI reproduction.
What happened?
If the $action passed to form_open() contains ://, it is used as-is in the action attribute. Relative actions go through site_url(), but absolute ones don't. A double quote in the action breaks out of the attribute.
The docblock says $action is "The URI segments of the form destination", so maybe absolute URLs aren't expected. But the code explicitly supports them, and there's no escaping on that path.
Example:
$payload = 'https://example.com/" onclick="alert(document.domain)" data-x="';
echo form_open($payload);
Output:
<form action="https://example.com/" onclick="alert(document.domain)" data-x="" method="post" accept-charset="utf-8">
Steps to Reproduce
I left a runnable script at bug-reports/poc/f06-form-open-action-injection.php. It loads the real helper and stubs the few framework functions it needs, so no Composer install is required.
From the project root:
php bug-reports/poc/f06-form-open-action-injection.php
To check it in a browser, save the output to /tmp/f06.html and open it. Clicking inside the form runs the handler.
Expected Output
If the action is meant to be escaped:
<form action="https://example.com/" onclick="alert(document.domain)" data-x="" method="post" accept-charset="utf-8">
If absolute actions are intentionally raw, the docblock and the user guide should say that $action must be trusted and pre-validated, and that user input must not be passed in.
Anything else?
Escape the action for the HTML attribute context:
$form = '<form action="' . esc($action) . '"' . $attributes . ">\n";
I'd also restrict absolute actions to expected schemes:
if (str_contains($action, '://')) {
$scheme = strtolower((string) parse_url($action, PHP_URL_SCHEME));
if (! in_array($scheme, ['http', 'https'], true)) {
$action = site_url('/');
}
}
A test in tests/system/Helpers/FormHelperTest.php with the payload above would cover the regression.
Activity
neznaika0 commentedon Nov 23, 2026
Please fix the code and image formatting in all Issues. Use backticks "```" or tag panel in editor