Skip to content

fix(Helpers): escape action attribute in form_open() - #10833

Open
banghamid wants to merge 1 commit into
codeigniter4:developfrom
banghamid:fix/form-open-escape-action
Open

banghamid wants to merge 1 commit into
codeigniter4:developfrom
banghamid:fix/form-open-escape-action

Conversation

@banghamid

@banghamid banghamid commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Description
Fixes #10817

In form_open(), when $action is an absolute URL (containing ://) or contains HTML special characters such as double quotes (") or ampersands (&), it was concatenated directly into <form action="..."> without escaping. This allowed double quotes in $action to break out of the action attribute and inject arbitrary HTML attributes.

This PR:

  • Escapes $action using esc($action) when building the <form action="..."> tag in form_open().
  • Preserves the raw $action for the CSRF internal-URL check (str_contains($action, base_url())).
  • Adds a regression test (testFormOpenEscapesAction) in tests/system/Helpers/FormHelperTest.php.
  • Documents the escaping behavior and double-escaping warning in docs/helpers/form_helper.md, docs/installation/upgrade_477.md, and docs/changelogs/v4.7.7.md.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@carson-codeigniter4 carson-codeigniter4 Bot added the bug Verified issues on the current code behavior or pull requests that will fix them label Nov 27, 2026

@michalsn michalsn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just like in the previous PR. Could we mention that form_open() now expects an unescaped URL? Applications that previously HTML-escaped $action should remove that escaping, otherwise values such as &amp; will be double-escaped.

PS. Please do not modify the checklist from our PR template. It's okay not to check all the items.

Escape the action attribute value in form_open() using esc() so quotes or HTML characters in absolute URLs cannot break out of the action attribute.
@banghamid
banghamid force-pushed the fix/form-open-escape-action branch from c31e976 to f794d3a Compare December 3, 2026 03:44
@banghamid

Copy link
Copy Markdown
Contributor Author

@michalsn Thank you for the review! I have updated the PR to address your feedback:

  • Added a note in \docs/helpers/form_helper.md\ and a \Behavior Changes\ entry in \docs/installation/upgrade_477.md\ (linked from \docs/changelogs/v4.7.7.md) explaining that \ orm_open()\ now expects an unescaped URL/URI string and that previously HTML-escaped \\ values should remove that escaping to avoid double-escaping.
  • Restored the checklist in the PR description to match the repository's PR template.

@banghamid
banghamid requested a review from michalsn December 3, 2026 04:01

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Verified issues on the current code behavior or pull requests that will fix them

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: form_open() inserts an absolute action into the form tag unescaped

2 participants