Jalpi sanitizes once, at save time, and escapes again at output. This page documents both passes and the capability model around them. Nothing here should be bypassed β the renderer is written to trust stored data precisely because the sanitizer already vetted it.
The trust boundary#
Jalpi_Sanitizer::sanitize_page_data() is the single entry point, called from Jalpi_API::save_page() before any database write. It is an allow-list at every level:
sanitize_page_data()
β version sanitize_text_field()
β globalStyles sanitize_global_styles()
β sections[] sanitize_node() (recursive)
β type must be in $allowed_types βͺ jalpi_widget_schema_types()
β id sanitize_key(); required; must be unique in this pass
β content sanitize_content( $type, β¦ ) one branch per type
β styles sanitize_styles() fixed property allow-list
β tabletStyles sanitize_styles()
β mobileStyles sanitize_styles()
β settings sanitize_settings( $type, β¦ )
β children[] sanitize_node() (depth++)
β hideOn three booleans
β locked boolean
β globalStyleRef sanitize_global_style_ref_data()
β interactions sanitize_interactions()Anything not named above is dropped. An unknown type returns [] and the caller filters the node out entirely.
Structural guards#
| Guard | Mechanism | Prevents |
|---|---|---|
| Depth limit | MAX_DEPTH = 20, tracked in self::$depth | Stack exhaustion from a deeply nested payload |
| Circular reference | self::$seen_ids; a repeated id returns [] | Infinite recursion from a duplicated id |
| Missing id | A node with no id returns [] | Unscopable CSS and unaddressable nodes |
| Class-attachment cap | array_slice( $keys, 0, 50 ) | Unbounded class lists |
| Demo-menu cap | Depth > 5 or 30 items stops recursion | Payload bloat in demoItems |
| Custom CSS cap | substr( $css, 0, 5000 ) | Unbounded per-element CSS |
Primitive sanitizers#
| Function | Accepts | Rejects |
|---|---|---|
sanitize_url() | http, https, mailto; {{tag}} placeholders pass through as text | Every other scheme, including javascript: and data: |
sanitize_dimension() | number + unit (%, px, em, rem, vw, vh, dvh, svh, lvh, s, ms, deg, fr, ch, ex); unitless numbers; the keywords auto/inherit/initial/unset/none/normal; strict clamp()/min()/max() | calc(), var(), arithmetic, anything else |
sanitize_dimension_shorthand() | 1β4 space-separated values, each validated individually | More than four parts, or any invalid part |
sanitize_color() | #rgbβ#rrggbbaa, rgb()/rgba(), hsl()/hsla(), 25 named keywords, and var(--name) with an optional validated fallback | Everything else |
sanitize_css_value() | Compound values after stripping the patterns below | expression(, -moz-binding:, javascript:, vbscript:, data:, @import, HTML comments |
sanitize_custom_css() | Raw CSS, capped at 5000 chars | expression(, -moz-binding:, javascript:, vbscript:, @import, </style, <script |
sanitize_icon_value() | {type,lib,name} with type in svg/font/img; the SVG body passes a strict wp_kses() element and attribute list | Unknown types; <script>, event handlers and unknown SVG attributes |
HTML handling#
Three different filters apply depending on the field:
- Rich text fields (heading text, text HTML, accordion bodies, FAQ answers, testimonial text, CTA subtitle, timeline textβ¦) use
wp_kses_post(). - The HTML widget branches on capability:
'html' => current_user_can( 'unfiltered_html' )
? wp_kses( $content['html'] ?? '', self::kses_html_block() )
: wp_kses_post( $content['html'] ?? '' ), kses_html_block() extends the post allow-list with structural tags, tables, <iframe>, <video>, <audio>, <picture>, <source> and inline SVG.
- Final output escaping β the entire rendered page is passed through
wp_kses( $html, Jalpi_Renderer::allowed_html() )before it is returned fromthe_content. Cached HTML is escaped before being written to the transient, so a cached value is already safe.
The net effect is defence in depth: even markup that passed kses_html_block() at save time is re-filtered against allowed_html() at output.
allowed_html()#
Built from wp_kses_allowed_html( 'post' ) plus:
- Global attributes on the common structural tags:
id,class,style,role,aria-hidden,aria-label,aria-labelledby,aria-current,data-*,title,tabindex, and the schema.org microdata attributesitemscope,itemtype,itemprop,itemid,itemref. <meta content>, so breadcrumb position data survives.- Media attributes on
<img>(srcset,sizes,loading),<video>,<source>and<iframe>(allow,allowfullscreen,loading). - Form elements:
<input>,<select>,<option>,<textarea>,<label>,<form>,<button>with their expected attributes. - SVG elements:
svg,path,circle,rect,line,polyline,polygon,g. <i>with the global attributes, for font-icon classes.
data-* being allowed globally is what lets the renderer ship data-jalpi-interact, data-jalpi-st and every widgetβs configuration through wp_kses() intact.
Capability model#
| Surface | Capability | Notes |
|---|---|---|
| Open the editor / admin menu | edit_posts, then edit_post on the target | Checked in both render_editor_page() and enqueue_editor() |
GET/POST /page/{id} | edit_post on that post | Jalpi_API::edit_permission() |
POST /page/{id}/publish | edit_post and the post typeβs publish_posts cap; plus edit_others_posts when the author differs | publish_permission() |
| Design System read/write | manage_options, filterable via jalpi_design_system_capability | Site-wide, so gated harder than page editing |
| Media upload | upload_files | MIME sniffed with finfo before media_handle_upload() |
| Website-kit import | manage_options | Creates pages, menus, templates and possibly installs WooCommerce |
| Templates | edit_posts to read, edit_posts/publish_posts to write | Jalpi_Templates::read_permission() / write_permission() |
| Reusable classes | edit_posts | Site-wide but authoring-level |
| Theme Builder | edit_theme_options | Mapped onto the CPTβs own capabilities |
| Revisions | edit_post on the post | |
| HTML widget extended tags | unfiltered_html | Otherwise wp_kses_post() |
| Shortcode widget | edit_posts at save time | Otherwise the shortcode is stored as an empty string |
| Role Manager permissions | A Jalpi permission and the WordPress capability | Checked on every editor REST route and on each save by the document guard, which drops or reverts changes the role may not make. Users with manage_options are never restricted. JALPI_PERMISSIONS_DISABLED switches the layer off. See Role Manager. |
CSRF and AJAX#
REST routes rely on the WordPress framework: the editor sends X-WP-Nonce, and the framework validates it before any permission_callback runs. admin-ajax.php handlers verify their own nonce explicitly:
| Action | Nonce action | Additional gate |
|---|---|---|
jalpi_pg_page | jalpi_pg | Post must be published, or the user must pass read_post |
jalpi_pg_cart | jalpi_pg | Self-guards on WooCommerce being loaded; runs woocommerce_add_to_cart_validation |
jalpi_template_preview | jalpi_template_preview | edit_posts; the id must match /^[A-Za-z0-9:_-]{1,120}$/ |
jalpi_site_preview | jalpi_preview_site | manage_options |
jalpi_support_diagnostics, jalpi_support_submit | jalpi_support | Rate-limited to 3 requests per user per hour |
Note that jalpi_pg_page and jalpi_pg_cart are registered for nopriv as well β they must be, since visitors paginate and add to cart. Neither accepts a query: the handler rebuilds it from the saved node, so only post, node and page travel over the wire.
SQL and file access#
- All direct queries use
$wpdb->prepare()with%d/%splaceholders; table names go throughesc_sql()before interpolation. - Saving is a single atomic
UPDATE β¦ SET version = version + 1, so concurrent saves cannot race the version counter. import_website()runssanitize_key()on the kit id and explicitly rejects/and\before building a path, blocking directory traversal.Jalpi_Template_Preview::handle()validates its id against a regex rather thansanitize_key(), because kit ids legitimately contain:.- Media uploads sniff the real MIME with
finfo( FILEINFO_MIME_TYPE )and accept onlyimage/jpeg,image/png,image/gif,image/webpandimage/avifβ the declared extension is not trusted.
There is no ZIP import path in the plugin. Template import accepts a JSON string over REST; website kits are read from files already inside the plugin directory.
Important
- Never call
Jalpi_Renderer::render_node()on data that has not been throughJalpi_Sanitizer. The renderer interpolates stored values into CSS strings on the assumption that they were validated at save time.
Source
Files
includes/class-jalpi-sanitizer.php includes/class-jalpi-renderer.php includes/class-jalpi-api.php includes/class-jalpi-woo-ajax.php includes/class-jalpi-template-preview.php includes/support/class-jalpi-support-center.php
Classes
Jalpi_Sanitizer Jalpi_Renderer Jalpi_API Jalpi_Woo_Ajax Jalpi_Template_Preview Jalpi_Support_Center
Functions
sanitize_page_data sanitize_node sanitize_content sanitize_styles sanitize_settings sanitize_url sanitize_color sanitize_dimension sanitize_css_value sanitize_custom_css sanitize_icon_value allowed_html kses_html_block
Last updated: November 2026