Skip to content

fix(code-field): preserve script and iframe embeds in display output - #7581

Open
faisalahammad wants to merge 3 commits into
pods-framework:release/3.4.0from
faisalahammad:fix/7263-code-field-display-embed
Open

fix(code-field): preserve script and iframe embeds in display output#7581
faisalahammad wants to merge 3 commits into
pods-framework:release/3.4.0from
faisalahammad:fix/7263-code-field-display-embed

Conversation

@faisalahammad

Copy link
Copy Markdown
Contributor

Description

The Code (Syntax Highlighting) field flow stamped everything through wp_kses_post() starting in Pods 3.1.0, which strips external <script src> and arbitrary <iframe src> embeds. Third-party widgets (SimpleShop form embed, TikTok, Google Reviews, etc.) therefore rendered as visible markup instead of executing on the frontend.

This branches sanitize_output() on field type so only code gets the extended allow-list (wysiwyg, paragraph, heading, text keep the previous behaviour). The extended list adds script[src|type|async|defer|integrity|crossorigin|nonce|charset|data-*] and iframe[src|width|height|frameborder|allow|allowfullscreen|title|loading|referrerpolicy|sandbox|name|id|style|class|data-*]. No on* handlers, no object/embed, no javascript: URLs. A new pods_code_field_sanitize_allowed_html filter lets third parties tighten it.

Sibling: this also fixes #7319 (shortcodes not rendering in code field) because do_shortcode() still runs before sanitization in code.php.

Hardens PodsAdmin::add_debug_information():

  • Guard the session_auto_start['data'] lookup so filters cannot trigger Undefined array key warnings.
  • Cache session_save_path() once and skip the FS exists/is_writable checks when the path is empty or starts with tcp:// (memcached/redis handlers and open_basedir-restricted hosts).

Related GitHub issue(s)

Fixes #7263
Refs #7319

Testing instructions

  1. On a site running Pods 3.3.x, edit any pod with a Code field. Leave the sanitize toggle on (default 1).
  2. Paste <script src="https://example.com/widget.js"></script> into the field value and render it via a Pods template ({@field_code}).
  3. View the rendered page source: the <script src="..."> tag survives intact instead of disappearing.
  4. Paste an embed <iframe src="https://www.youtube.com/embed/abc123" width="560" height="315" allowfullscreen></iframe> and confirm it renders.
  5. Open Tools → Site Health → Info → Pods. Verify no PHP warnings on the debug-data request (previously emitted on hosts with open_basedir or tcp:// session handlers).
  6. Slic test group: slic run wpunit --group=pods-field and slic run wpunit --group=pods (guards + code embed preserved).

Screenshots / screencast

Not applicable to this change.

Changelog text for these changes

Bug: Code (Syntax Highlighting) fields now render third-party script and iframe embeds correctly; Site Health no longer emits PHP warnings for session_auto_start lookup or tcp:// session handlers.

PR checklist

The Code (Syntax Highlighting) field flow stamped everything through
wp_kses_post() starting in Pods 3.1.0, which strips external <script src>
and arbitrary <iframe src> embeds. Third-party widgets (SimpleShop form
embed, TikTok, Google Reviews, etc.) therefore rendered as visible markup
instead of executing on the frontend (issue pods-framework#7263).

- Branch sanitize_output() on field type so only 'code' gets the extended
  allow-list; wysiwyg/paragraph/heading/text keep the previous behaviour.
- Extend wp_kses_post() with script[src|type|async|defer|integrity|...] and
  iframe[src|width|height|allowfullscreen|...] for code-field output.
- Add a pods_code_field_sanitize_allowed_html filter for third parties.
  No on*/object/embed handlers, no javascript: URLs allowed.

Sibling issue pods-framework#7319 (shortcodes not rendering in code field) is also
covered -- do_shortcode() still runs before sanitization in code.php.

Also harden PodsAdmin::add_debug_information():

- Guard the session_auto_start ['data'] lookup so filters cannot trigger
  'Undefined array key' warnings.
- Cache session_save_path() once and skip the FS exists/is_writable
  checks when the path is empty or starts with tcp:// (memcached/redis
  handlers and open_basedir-restricted hosts).

Adds wpunit coverage for both behaviours.

Fixes pods-framework#7263
@what-the-diff

what-the-diff Bot commented Jul 26, 2026

Copy link
Copy Markdown

PR Summary

  • Enhanced Debug Information Method:
    • The add_debug_information method in PodsAdmin.php has been updated to better handle session settings automatically. This cuts down on unnecessary checks and potential warning alerts.
  • Boosted Input Cleanliness:
    • PodsField.php now has improved functions for tidying up string and array/object results. This effectively safeguards scripts and frames while allowing more diverse HTML elements for script and frame tags.
  • Newly Introduced Tests:
    • New tests added for the add_debug_information function in AdminDebugInformationTest.php to ensure the function could handle errors smoothly without causing any critical errors.
    • New set of unit tests for PodsField_Code in PodsField_CodeTest.php to confirm the consistent embedding and scripting capability

In general, this Pull Request enhances the stability and functionality of the system and builds a more robust foundation for future development.

@faisalahammad
faisalahammad changed the base branch from main to release/3.4.0 August 18, 2026 11:25
@faisalahammad

Copy link
Copy Markdown
Contributor Author

AI disclosure: this PR was written with Claude Opus 5 assistance, reviewed and tested by me.

faisalahammad and others added 2 commits August 19, 2026 23:43
get_post_with_embeds_allowed_html() added 'script' to the kses allow-list
unconditionally. wp_kses() filters tags and attributes but never the text
content of an element, so <script>...</script> bodies passed through intact --
meaning any user who could edit a Code field could store JavaScript that
executed for every visitor.

This is exactly inverted from intent: the allowance only applies when
code_sanitize_html is enabled, which is the option an admin turns on to get
sanitising in the first place.

The script allowance is now limited to users with unfiltered_html, matching the
capability WordPress already uses for raw HTML. Iframe embeds -- the common
widget case -- are unchanged and still work for everyone, and
pods_code_field_sanitize_allowed_html remains available for sites that
deliberately want public script embeds.

Refs pods-framework#7263
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shortcodes won't render via pods code syntax field form inserted via custom field Pods is no longer displayed

1 participant