fix(code-field): preserve script and iframe embeds in display output - #7581
Open
faisalahammad wants to merge 3 commits into
Open
fix(code-field): preserve script and iframe embeds in display output#7581faisalahammad wants to merge 3 commits into
faisalahammad wants to merge 3 commits into
Conversation
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
PR Summary
In general, this Pull Request enhances the stability and functionality of the system and builds a more robust foundation for future development. |
Contributor
Author
|
AI disclosure: this PR was written with Claude Opus 5 assistance, reviewed and tested by me. |
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 onlycodegets the extended allow-list (wysiwyg, paragraph, heading, text keep the previous behaviour). The extended list addsscript[src|type|async|defer|integrity|crossorigin|nonce|charset|data-*]andiframe[src|width|height|frameborder|allow|allowfullscreen|title|loading|referrerpolicy|sandbox|name|id|style|class|data-*]. Noon*handlers, noobject/embed, nojavascript:URLs. A newpods_code_field_sanitize_allowed_htmlfilter lets third parties tighten it.Sibling: this also fixes #7319 (shortcodes not rendering in code field) because
do_shortcode()still runs before sanitization incode.php.Hardens
PodsAdmin::add_debug_information():session_auto_start['data']lookup so filters cannot triggerUndefined array keywarnings.session_save_path()once and skip the FSexists/is_writablechecks when the path is empty or starts withtcp://(memcached/redis handlers andopen_basedir-restricted hosts).Related GitHub issue(s)
Fixes #7263
Refs #7319
Testing instructions
<script src="https://example.com/widget.js"></script>into the field value and render it via a Pods template ({@field_code}).<script src="...">tag survives intact instead of disappearing.<iframe src="https://www.youtube.com/embed/abc123" width="560" height="315" allowfullscreen></iframe>and confirm it renders.open_basedirortcp://session handlers).slic run wpunit --group=pods-fieldandslic 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