Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelogs/v4.7.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Release Date: Unreleased
- **Helpers:** Fixed a bug where `array_flatten_with_dots()` renumbered numeric keys when flattening nested arrays, potentially overwriting values.
- **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. See [Form Helper Escaping in `form_open()`](../installation/upgrade_477.md#form-helper-escaping-in-form_open) for behavior changes.
- **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 where `sanitize_filename()` preserved leading forward slashes when `$relativePath` was `true`, including slashes exposed by removing parent-directory sequences. The same applies to `CodeIgniter\Security\Security::sanitizeFilename()`.
Expand Down
3 changes: 3 additions & 0 deletions docs/helpers/form_helper.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ The above example would create a form that points to your site URL plus the curr
<form action="http://example.com/index.php/en/email/send" method="post" accept-charset="utf-8">
```

!!! note "Note"
Since v4.7.7, `form_open()` automatically escapes the `$action` attribute value using `esc()`. Pass a raw, unescaped URL or URI string; do not pass values that are already HTML-escaped, as they will be escaped again.

**Adding Attributes**

Attributes can be added by passing an associative array to the second parameter, like this:
Expand Down
8 changes: 8 additions & 0 deletions docs/installation/upgrade_477.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ With the default configuration most applications are unaffected, because `/`, `\

## Breaking Enhancements

## Behavior Changes

### Form Helper Escaping in `form_open()`

`form_open()` now escapes the `$action` attribute value using `esc()`.

Previously, `form_open()` concatenated `$action` directly into `<form action="...">` without escaping. `form_open()` now expects an unescaped URL or URI string. Applications that previously HTML-escaped `$action` (for example, pre-escaped with `esc()` or `htmlspecialchars()`) should remove that escaping, otherwise values such as `&amp;` will be double-escaped (becoming `&amp;amp;`).

## Project Files

Some files in the **project space** (root, app, public, writable) received updates. Due to these files being outside of the **system** scope they will not be changed without your intervention.
Expand Down
2 changes: 1 addition & 1 deletion system/Helpers/form_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function form_open(string $action = '', $attributes = [], array $hidden = []): s
$attributes .= ' accept-charset="' . strtolower($config->charset) . '"';
}

$form = '<form action="' . $action . '"' . $attributes . ">\n";
$form = '<form action="' . esc($action) . '"' . $attributes . ">\n";

// Add CSRF field if enabled, but leave it out for GET requests and requests to external websites
$before = service('filters')->getFilters()['before'];
Expand Down
18 changes: 18 additions & 0 deletions tests/system/Helpers/FormHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
<form action="https://example.com/&quot; onclick=&quot;alert(1)&quot; data-x=&quot;" method="post" accept-charset="utf-8">

EOH;
$this->assertSame($expected, form_open($payload));

$expectedQuery = <<<'EOH'
<form action="https://example.com/search?a=1&amp;b=2" method="post" accept-charset="utf-8">

EOH;
$this->assertSame($expectedQuery, form_open('https://example.com/search?a=1&b=2'));
}

public function testFormOpenWithoutMethodWithCsrf(): void
{
$this->setRequest();
Expand Down
Loading