T09 · Insecure Skill Coding Practices
- Location
SKILL.md:184- Finding
Potential DOM-Based Cross-Site Scripting Through Unsanitized Popup HTML
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md, lines 184–190
Vulnerability Type: Unsanitized dynamic HTML rendering
Risk Level: Mediumjavascript map.on('click', 'points-layer', (e) => { const coordinates = e.features[0].geometry.coordinates.slice(); const description = e.features[0].properties.description; new mapboxgl.Popup().setLngLat(coordinates).setHTML(description).addTo(map); });Technical Analysis
The example reads
descriptionfrom a GeoJSON feature and passes it directly tomapboxgl.Popup.setHTML(). Unlike a text-only rendering method,setHTML()interprets the supplied value as markup.If the GeoJSON data originates from an untrusted or insufficiently validated source, an attacker may place malicious HTML in the
descriptionproperty. Applications that copy this pattern could render attacker-controlled elements or event handlers in their page. The example does not sanitize the value, restrict permitted markup, or warn developers that feature properties must be treated as untrusted input.Attack Path
- An application adopts the documented popup pattern.
- The application loads GeoJSON containing feature properties from a user-controlled, compromised, or otherwise untrusted data source.
- An attacker supplies a malicious value in a feature's
descriptionproperty, such as markup containing an executable event handler. - A user clicks the corresponding feature in
points-layer. - The event handler retrieves the malicious
description. setHTML(description)inserts the value into the popup as HTML.- If the browser and the application's Content Security Policy permit the payload, attacker-controlled script executes in the application's origin.
Impact Assessment
Successful exploitation could execute JavaScript with the privileges of the affected web application origin. Depending on the application's architecture and browser protections, the at ...[truncated 442 chars]
- Remediation
View remediation
Remediation Suggestions
- Use
setText(description)whenever popup content is intended to be plain text. - If rich HTML is required, sanitize the value with a maintained allowlist-based HTML sanitizer before passing it to
setHTML(). - Permit only the minimum necessary elements and attributes; remove script-capable elements, event-handler attributes, unsafe URL schemes, and dangerous embedded content.
- Validate and normalize GeoJSON properties when data enters the application rather than relying exclusively on rendering-time checks.
- Document explicitly that remote, uploaded, or user-generated feature properties are untrusted.
- Deploy a restrictive Content Security Policy as defense in depth, avoiding
unsafe-inlineand limiting script sources to trusted origins. - Add tests containing malicious markup and event-handler payloads to verify that popup content is rendered safely.
- Use
