Skip to content

fix(Helpers): escape src and attribute values in img() and script_tag() - #10832

Open
banghamid wants to merge 1 commit into
codeigniter4:developfrom
banghamid:fix/html-helper-escape-img-script-tag
Open

banghamid wants to merge 1 commit into
codeigniter4:developfrom
banghamid:fix/html-helper-escape-img-script-tag

Conversation

@banghamid

Copy link
Copy Markdown
Contributor

Description
Fixes #10813

In html_helper:

  • img() escaped its third $attributes parameter via stringify_attributes(), but concatenated values from the $src array (such as alt or other attributes) and relative src paths unescaped.
  • script_tag() concatenated both src and attribute values unescaped, unlike link_tag() and HTML media helpers which escape attribute values with esc().

This PR:

  • Escapes src and attribute values in img() using esc().
  • Escapes src and non-null attribute values in script_tag() using esc() while preserving null boolean attributes (e.g. async).
  • Adds regression tests in tests/system/Helpers/HTMLHelperTest.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 src and non-null attribute values in img() and script_tag() using esc() to prevent malformed HTML and attribute injection, consistent with link_tag() and stringify_attributes().
@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: img() and script_tag() insert array values into the tag unescaped

1 participant