diff --git a/src/DonationForms/Properties/FormSettings.php b/src/DonationForms/Properties/FormSettings.php
index cd590c0e83..c8cfdcdfb7 100644
--- a/src/DonationForms/Properties/FormSettings.php
+++ b/src/DonationForms/Properties/FormSettings.php
@@ -246,6 +246,7 @@ class FormSettings implements Arrayable, Jsonable
* @since 3.7.0 Added formExcerpt
/**
+ * @unreleased Sanitize customCSS property
* @since 3.2.0 Added registrationNotification
* @since 3.0.0
*/
@@ -273,7 +274,7 @@ public static function fromArray(array $array): self
$self->secondaryColor = $array['secondaryColor'] ?? '#f49420';
$self->goalAmount = $array['goalAmount'] ?? 0;
$self->registrationNotification = $array['registrationNotification'] ?? false;
- $self->customCss = $array['customCss'] ?? '';
+ $self->customCss = wp_strip_all_tags($array['customCss'] ?? '');
$self->pageSlug = $array['pageSlug'] ?? '';
$self->goalAchievedMessage = $array['goalAchievedMessage'] ?? __(
'Thank you to all our donors, we have met our fundraising goal.',
diff --git a/src/DonationForms/ViewModels/DonationConfirmationReceiptViewModel.php b/src/DonationForms/ViewModels/DonationConfirmationReceiptViewModel.php
index 507a4211d6..f8928d3770 100644
--- a/src/DonationForms/ViewModels/DonationConfirmationReceiptViewModel.php
+++ b/src/DonationForms/ViewModels/DonationConfirmationReceiptViewModel.php
@@ -84,6 +84,7 @@ public function formExports(): array
}
/**
+ * @unreleased Sanitize customCSS property
* @since 3.0.0
*/
public function render(): string
@@ -111,7 +112,7 @@ public function render(): string
-
+
diff --git a/src/DonationForms/ViewModels/DonationFormViewModel.php b/src/DonationForms/ViewModels/DonationFormViewModel.php
index ada297efb4..2835ce1252 100644
--- a/src/DonationForms/ViewModels/DonationFormViewModel.php
+++ b/src/DonationForms/ViewModels/DonationFormViewModel.php
@@ -247,6 +247,7 @@ public function exports(): array
* 5. Finally, call the specific WP function wp_print_footer_scripts()
* - This will only print the footer scripts that are enqueued within our route.
*
+ * @unreleased Sanitize customCSS property
* @since 3.0.0
*/
public function render(): string
@@ -266,7 +267,7 @@ public function render(): string
previewMode || $this->formSettings->customCss): ?>
+ echo wp_strip_all_tags($this->formSettings->customCss); ?>
diff --git a/tests/Unit/DonationForms/Properties/FormSettingsTest.php b/tests/Unit/DonationForms/Properties/FormSettingsTest.php
new file mode 100644
index 0000000000..bf551a53a7
--- /dev/null
+++ b/tests/Unit/DonationForms/Properties/FormSettingsTest.php
@@ -0,0 +1,30 @@
+ '',
+ ]);
+
+ $this->assertEmpty($formSettings->customCss);
+ }
+
+ public function testSanitizationPreservesCssWhileRemovingHtmlTags()
+ {
+ $formSettings = FormSettings::fromArray([
+ 'customCss' => '.test { color: green; }