diff --git a/docs/changelogs/v4.7.7.md b/docs/changelogs/v4.7.7.md index 39eddfb3664d..e2116a1120b2 100644 --- a/docs/changelogs/v4.7.7.md +++ b/docs/changelogs/v4.7.7.md @@ -36,6 +36,7 @@ Release Date: Unreleased - **Debug Toolbar:** Fixed a bug where `History::setFiles()` emitted a PHP warning when attempting to delete a debugbar history file that had already been removed. - **Helpers:** Fixed a bug in `ellipsize()` where `$position` was clamped after slicing the beginning of the string and where float `1.0` was not treated identically to integer `1`. - **Helpers:** Fixed a bug where `excerpt()` threw a `TypeError` when `$phrase` was not found in `$text` or when `$phrase` was `null` and `$radius` was an odd integer. When `$phrase` is not found, `excerpt()` now falls back to extracting an excerpt from the beginning of `$text`. +- **Helpers:** Fixed a bug where `form_open()` did not escape the `$action` attribute value, allowing quotes or HTML characters in absolute URLs to break out of the `action` attribute. - **Helpers:** Fixed a bug where `format_number()` with `$precision = 0` appended a trailing comma in locales using a comma as the decimal separator. - **Helpers:** Fixed a bug where `parse_subdomain()` incorrectly treated hostnames with ports (such as IP addresses and two-part TLD domains) as having unexpected subdomains. - **Helpers:** Fixed a bug in `plural()` where the regex for `matrix`, `vertex`, and `index` lacked non-capturing grouping and an end-of-string anchor for the `ix` alternative, causing incorrect pluralization of words like `complex`, `sex`, and strings containing `matrix` before the end. Expanded `plural()` and `singular()` to support additional words ending in `ix` or `ex` (`apex`, `appendix`, `codex`, `cortex`, `latex`, `murex`, `vortex`). diff --git a/system/Helpers/form_helper.php b/system/Helpers/form_helper.php index 19cc8eb949b9..34aeb829294a 100644 --- a/system/Helpers/form_helper.php +++ b/system/Helpers/form_helper.php @@ -58,7 +58,7 @@ function form_open(string $action = '', $attributes = [], array $hidden = []): s $attributes .= ' accept-charset="' . strtolower($config->charset) . '"'; } - $form = '
\n"; + $form = '\n"; // Add CSRF field if enabled, but leave it out for GET requests and requests to external websites $before = service('filters')->getFilters()['before']; diff --git a/tests/system/Helpers/FormHelperTest.php b/tests/system/Helpers/FormHelperTest.php index bfd3d12e0efe..e3741835d220 100644 --- a/tests/system/Helpers/FormHelperTest.php +++ b/tests/system/Helpers/FormHelperTest.php @@ -173,6 +173,24 @@ public function testFormOpenWithoutMethod(): void $this->assertSame($expected, form_open('foo/bar', $attributes)); } + public function testFormOpenEscapesAction(): void + { + $this->setRequest(); + + $payload = 'https://example.com/" onclick="alert(1)" data-x="'; + $expected = <<<'EOH' + + + EOH; + $this->assertSame($expected, form_open($payload)); + + $expectedQuery = <<<'EOH' + + + EOH; + $this->assertSame($expectedQuery, form_open('https://example.com/search?a=1&b=2')); + } + public function testFormOpenWithoutMethodWithCsrf(): void { $this->setRequest();