T09 · Insecure Skill Coding Practices
- Location
references/web-search-js.md:119- Finding
DOM-based cross-site scripting through unescaped search result fields
- Content
View full analysis
${result.properties.name}${result.properties.full_address || ''}
` ) ``` ```javascript resultsContainer.innerHTML = response.suggestions .map( (suggestion) => `${suggestion.name}` ) .join(''); ``` ```javascript resultsContainer.innerHTML = results .map( (result) => `${suggestion.place_formatted}${result.name}` ) .join(''); ``` ### Technical Analysis The examples interpolate Mapbox response fields directly into HTML strings and pass the resulting strings to `setHTML()` or `innerHTML`. These APIs parse their input as active HTML rather than plain text. The affected values include result names, formatted addresses, and identifiers. They originate outside the application’s trust boundary. If a malicious or compromised upstream record contains HTML event handlers, dangerous elements, or malformed attribute content, the browser can interpret that content in the application’s origin. The use of an unquoted `data-id` attribute increases the attack surface because specially formed identifier content could break out of the attribute even when it does not contain a complete HTML element. ### Attack Path 1. An attacker causes malicious markup to appear in a place name, formatted address, or other search-result field available through the upstream search service. 2. A victim searches for a term that returns the attacker-controlled record. 3. The application interpolates the returned value into an HTML template without contextual escaping. 4. The app ...[truncated 856 chars]${result.place_formatted || ''}
- Remediation
View remediation
