From 5f846543f08e35cc1a5ea992f9871151fd8747eb Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 24 Oct 2026 13:07:31 +0000 Subject: [PATCH 1/2] Escape the log shown on the settings page's Logging tab The log holds text sent by visitors (for example the plan ID in a /join request), and was printed into the page as HTML, so markup in it ran in the admin's browser. Show it as text instead. JOIN-168. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BL2bFrTk84JMy3CPAsCTV9 --- packages/join-block/src/Settings.php | 4 +++- packages/join-e2e/tests/log-viewer.spec.ts | 26 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 packages/join-e2e/tests/log-viewer.spec.ts diff --git a/packages/join-block/src/Settings.php b/packages/join-block/src/Settings.php index 78520a7..047c5c6 100644 --- a/packages/join-block/src/Settings.php +++ b/packages/join-block/src/Settings.php @@ -290,7 +290,9 @@ public static function init() if (!$log) { $log = 'Could not load error log. Please contact Common Knowledge support.'; } - return "
$log
"; + // The log holds text sent by visitors (join and step requests), so + // it must be shown as text, never as markup. + return '
' . esc_html($log) . '
'; }); /** @var Html_Field $logRetentionField */ $logRetentionField = Field::make('html', 'ck_join_flow_log_retention'); diff --git a/packages/join-e2e/tests/log-viewer.spec.ts b/packages/join-e2e/tests/log-viewer.spec.ts new file mode 100644 index 0000000..6fec05d --- /dev/null +++ b/packages/join-e2e/tests/log-viewer.spec.ts @@ -0,0 +1,26 @@ +import { test, expect } from '@playwright/test'; +import { loginAsAdmin } from './helpers'; + +/** + * The plugin's log, shown on WP Admin > Join > Logging, holds text that + * visitors send. It must be shown as text: markup in it must never run in the + * admin's browser. + */ +test('markup sent by a visitor is shown as text in the log viewer, not run', async ({ page, request }) => { + const probe = `log-viewer-probe-${Date.now()}`; + const markup = ``; + + // A join on a plan that doesn't exist logs the plan's ID as sent. + const response = await request.post('/wp-json/join/v1/join', { + data: { email: 'someone@example.com', membership: markup }, + }); + expect(response.status()).toBe(500); + + await loginAsAdmin(page); + await page.goto('/wp-admin/admin.php?page=crb_carbon_fields_container_ck_join_flow.php'); + await page.getByRole('tab', { name: 'Logging', exact: true }).click(); + + await expect(page.locator('pre', { hasText: `Invalid membership plan: ${markup}` })).toBeVisible(); + await expect(page.locator(`#${probe}`)).toHaveCount(0); + expect(await page.evaluate((name) => (window as any)[name], probe.replace(/-/g, '_'))).toBeUndefined(); +}); From c795a8f71aa446b1a27237a643558bfbc7ba1e2e Mon Sep 17 00:00:00 2001 From: Joaquim de Souza Date: Tue, 10 Nov 2026 10:49:05 +0000 Subject: [PATCH 2/2] Keep the log visible when it contains invalid UTF-8 esc_html() returns an empty string for any input that is not valid UTF-8, so one bad byte from a visitor's request blanked the whole Logging tab. Substitute invalid bytes with U+FFFD instead. Co-Authored-By: Claude Opus 5.5 --- packages/join-block/src/Settings.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/join-block/src/Settings.php b/packages/join-block/src/Settings.php index 047c5c6..69a8cb7 100644 --- a/packages/join-block/src/Settings.php +++ b/packages/join-block/src/Settings.php @@ -291,8 +291,13 @@ public static function init() $log = 'Could not load error log. Please contact Common Knowledge support.'; } // The log holds text sent by visitors (join and step requests), so - // it must be shown as text, never as markup. - return '
' . esc_html($log) . '
'; + // it must be shown as text, never as markup. esc_html() returns an + // empty string if any byte is invalid UTF-8, which would let one bad + // request blank the whole log, so invalid bytes are replaced with + // U+FFFD instead. + return '
' .
+                htmlspecialchars($log, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8') .
+                '
'; }); /** @var Html_Field $logRetentionField */ $logRetentionField = Field::make('html', 'ck_join_flow_log_retention');