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

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.
  • Adds a changelog entry in docs/changelogs/v4.7.7.md.

Checklist:

  • Securely signed commits
  • Component-specific tests which fail without the change
  • Conforms to style guide and static analysis checks
  • User guide and changelog updated

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.
@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

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

1 participant