T09 · Insecure Skill Coding Practices
- Location
SKILL.md:182- Finding
DOM-Based Cross-Site Scripting Through Unsanitized Map Popup Content
- Content
View full analysis
{ const marker = new mapboxgl.Marker() .setLngLat([restaurant.lng, restaurant.lat]) .setPopup(new mapboxgl.Popup().setHTML(restaurant.name)) .addTo(map); }); ``` `SKILL.md:222-225`: ```javascript map.on('click', 'restaurants', (e) => { const feature = e.features[0]; new mapboxgl.Popup().setLngLat(feature.geometry.coordinates).setHTML(feature.properties.name).addTo(map); }); ``` `references/memory.md:48-50`: ```javascript map.on('click', 'restaurants', (e) => { new mapboxgl.Popup().setLngLat(e.lngLat).setHTML(e.features[0].properties.name).addTo(map); // Popup never removed! }); ``` `references/memory.md:55-58`: ```javascript let popup = new mapboxgl.Popup({ closeOnClick: true }); map.on('click', 'restaurants', (e) => { popup.setLngLat(e.lngLat).setHTML(e.features[0].properties.name).addTo(map); }); ``` ### Technical Analysis The examples pass map feature properties directly to `mapboxgl.Popup.setHTML()`. Values such as `restaurant.name` and `feature.properties.name` may originate from APIs, uploaded GeoJSON, third-party datasets, or other untrusted sources. `setHTML()` treats its argument as HTML rather than plain text. If an attacker can control a feature property, the attacker can insert active HTML, such as an element containing an event handler. When the popup is rendered and the relevant event is triggered, the payload can execute in the security context of the application origin. Reusing a popup instance addresses resource consumption but does not provide output encoding or sanitization. The recommended “good” memory-management example therefore preserves the injection ...[truncated 1747 chars]- Remediation
View remediation
