Repository navigation
fix: escape output at echo site (#18) - #19
Conversation
Wraps every echoed variable in a visible escape function and removes the phpcs:ignore EscapeOutput suppressions the wp.org review flagged. - updated_pill: refactor to void-emit so SVG viewBox survives intact - policy content: wp_kses_post on the_content output - paginate_links, contact lines, joined date parts: wp_kses with narrow allow-lists at the echo - admin printf with $attr_html builder: inline esc_attr on each attr - cert/policy media buttons: class-toggle (.ot-hidden) instead of conditional inline style - SSE writer: JSON_HEX_* flags plus esc_html (byte-identical) - version meta box: %d is the escape, drop intval - bump DB_VERSION to 4 so invalidate_cache fires on upgrade Out of scope: inline-asset and JSON-LD echo sites covered by #11.
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughEscape output at echo sites across admin pages, templates, and chat; replace inline visibility styles with ChangesOutput Escaping and Visibility Toggle Hardening
🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@templates/chat.php`:
- Around line 266-275: The SVG allow-list in $ot_icon_allowed uses the
mixed-case attribute key 'viewBox' which wp_kses will reject; update the 'svg'
array in the $ot_icon_allowed declaration to use the lowercase 'viewbox' key
instead of 'viewBox' so the SVG viewport attribute is permitted by wp_kses
(leave all other keys unchanged).
In `@templates/trust-center.php`:
- Around line 19-21: The code uses direct array access when building
$ot_page_title and $ot_tagline which can emit "undefined index" notices; update
the expressions to guard the keys with null-coalescing before the ?: fallback
(e.g. use ($ot_settings['page_title'] ?? '') ?: __('Trust Center', 'opentrust')
and similarly for $ot_tagline) while leaving $ot_company_name's existing
($ot_settings['company_name'] ?? '') intact so missing keys won't trigger
notices.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 84145098-4616-421a-9288-9fecfdb8b8f9
📒 Files selected for processing (18)
assets/css/admin.cssincludes/class-opentrust-admin-ai.phpincludes/class-opentrust-admin-questions.phpincludes/class-opentrust-admin-settings.phpincludes/class-opentrust-chat.phpincludes/class-opentrust-cpt.phpincludes/class-opentrust-render.phpincludes/class-opentrust-version.phpincludes/class-opentrust.phpopentrust.phptemplates/chat.phptemplates/partials/certifications.phptemplates/partials/contact.phptemplates/partials/data-practices.phptemplates/partials/policies.phptemplates/partials/policy-single.phptemplates/partials/subprocessors.phptemplates/trust-center.php
wp_kses lowercases attribute names for allow-list matching, so the camelCase 'viewBox' key in $ot_icon_allowed never matched and the attribute got stripped — chat suggestion-chip icons rendered cropped. Lowercase 'viewbox' matches; HTML5 case-fixes 'viewbox' to 'viewBox' on SVG-in-HTML during parse, so the rendered SVG scales correctly. POT regenerated to capture the admin-ai.php msgid change (embedded <strong>%s</strong>) and pick up admin-questions.php line shifts. nl_NL PO updated to match the new msgid; MO recompiled with --use-fuzzy to preserve existing partial translations.
Plugin Check flagged the bare $current_version in printf %d at version.php:150. WPCS treats (int)/(bool)/(float) casts as escape casts but does not recognize the %d format specifier as escape on its own. Add the explicit cast.
Claude Code reviewVerdict: Approve. Verified against What I checkedAll 9 reviewer-cited sites get a visible late escape at the echo:
Pattern coverage beyond cited sites
Smart bits worth calling out:
Non-blocking observations
Tests not run locallyCI's — Claude (automated review on behalf of @nolderoos) |
…late Wrap $ot_settings['page_title'] and $ot_settings['tagline'] with `?? ''` before the `?:` fallback so PHP 8+ does not emit an "undefined array key" notice when those keys are not present in the stored settings array. Pure notice-guard; the existing fallback strings still apply for empty values. Addresses #19 (comment) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
JSON_HEX_QUOT only escapes " inside string values (to \u0022); structural " delimiters around JSON keys stay raw, so esc_html converts them to " on the wire. JSON.parse silently fails in chat.js, producing empty token data and the 'No content returned by the model' symptom. SSE is text/event-stream, not HTML. Restore the phpcs:ignore silencers justified by $event being regex-sanitized and $json being wp_json_encode output — the right contract for this context.
…s:ignore Round-1 reviewer flagged includes/class-opentrust-chat.php:502, 504 and explicitly stated phpcs:ignore is not a fix. This applies the wporg-review/06-escape-output/analysis.md recommendation verbatim: wp_kses($line, []) wrapper with JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT flags on wp_json_encode. The HEX flags hex-escape every <, &, ', " inside JSON string values to \u00XX. The structural " around keys stays raw (JSON grammar requires it). wp_kses($json, []) then sees no tag-like characters and is byte-identical — verified against 21 representative SSE payloads + exhaustive ASCII sweep + Unicode/emoji/RTL/BOM. JSON.parse on the client round-trips cleanly. ~2µs per call, acceptable for live streaming. Drops both phpcs:ignore lines that the previous fix (96dbe5a) restored. wp_kses is in WPCS's EscapingFunctionsTrait allowlist so the WordPress.Security.EscapeOutput.OutputNotEscaped sniff accepts it natively.
Closes #18.
Wraps every echoed variable in a visible escape function and removes the
phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscapedsuppressions the wp.org reviewer flagged in category 6 — "Variables and options must be escaped when echo'd."What changed
updated_pill: refactored to void-emit so the static SVGviewBoxattribute survives intact (wp_kses lowercases attribute names and would strip the camelCaseviewBox). Four template call sites simplified.policy-single.php:wp_kses_poston the Gutenbergthe_contentoutput. Two-branch<span>/<a>restructure replaces the dynamic$ot_tagecho.trust-center.php: pre-escape removed from the variable assigns; raw value held,esc_html/esc_attrapplied at every echo site.contact.php,certifications.php:wp_kseswith narrow allow-lists wrap the echoes of pre-assembled HTML fragments.admin-settings.php:$attr_htmlbuilder dropped — each attribute emitted inline viaesc_attr. Class ternaries wrapped withesc_attr. Media preview/remove buttons switched to anot-hiddenclass toggle.admin-questions.php:paginate_linkswrapped withwp_ksesallow-list covering every WP-core variant (<a class href>,<span aria-current class>,<span class="dots">, prev/next anchors). Inline-style ternary wrapped withesc_attr.admin-ai.php: printf format moved intowp_kses(__('… <strong>%s</strong> …'), ['strong'=>[]]);%sargument getsesc_html. Matches the existing pattern atadmin-ai.php:93.cpt.php: sixdisplay:noneternaries refactored toot-hiddenclass toggle. New.ot-hidden { display: none; }rule inadmin.css— works correctly with jQuery.show()/.hide()since inline style overrides class CSS.chat.phpSSE writer: addedJSON_HEX_*flags then wrapped echoes inesc_html— byte-identical wire output, satisfies the literal "escape everything echoed" rule fortext/event-streamoutput.version.php: droppedintval()— the%dformat specifier is the escape.OPENTRUST_DB_VERSIONbumped 3 → 4 soinvalidate_cache()fires on plugin update.Out of scope (deliberately)
Sites already covered by #11 (
fix/wp-enqueue-assets) are not touched here:templates/trust-center.php:105(inline CSS) — moved to real enqueue in fix: enqueue assets via real $src (#10) #11templates/trust-center.php:242(inline JS) — moved to real enqueue in fix: enqueue assets via real $src (#10) #11templates/chat.php:99(inline CSS) — moved to real enqueue in fix: enqueue assets via real $src (#10) #11templates/chat.php:332(JSON config) — routed throughwp_print_inline_script_tagin fix: enqueue assets via real $src (#10) #11templates/chat.php:367(inline JS chat.js) — moved to real enqueue in fix: enqueue assets via real $src (#10) #11templates/partials/faq.php:69(FAQPage JSON-LD) — routed throughwp_print_inline_script_tagin fix: enqueue assets via real $src (#10) #11Two
phpcs:ignore EscapeOutputlines therefore remain on this branch (chat.php:331, faq.php:69). Both vanish when #11 lands.Net
35
phpcs:ignore.*EscapeOutputsuppressions before → 2 surviving on this branch → 0 after #11 merges.Smoke test
Verified against local WordPress Studio site:
updated_pillSVG now keepsviewBox="0 0 20 20"(was being stripped by wp_kses).wp_kses_post(headings, paragraphs, lists, entities).ot-hiddenclass toggle on PDF preview/remove.$ot_iconsSVGs survivewp_ksesallow-list.Summary by CodeRabbit
Bug Fixes
Improvements
Chores
Localization