T03 · Remote Payload Retrieval and Execution
- Location
reference/composable-design-patterns.md:485- Finding
Dynamic Third-Party Script Execution Through JSONP
- Content
View full analysis
Vulnerability Details
File Location:
reference/composable-design-patterns.md:485-488
Vulnerability Type: Dynamic remote JavaScript retrieval and execution
Risk Level: HighVulnerable Code
typescript const url = currentEngine.value.suggestionUrl(keyword, callbackName) scriptEl = document.createElement('script') scriptEl.src = url document.head.appendChild(scriptEl)Technical Analysis
The documented production-grade composable constructs a URL from the active search engine and assigns it to the
srcproperty of a dynamically createdscriptelement. Appending that element to the document causes the browser to retrieve the response and execute it as JavaScript in the application's page context.Unlike a normal JSON request, JSONP does not treat the response as inert data. The remote endpoint can return arbitrary executable JavaScript. The example does not enforce HTTPS, validate the URL scheme, restrict the destination to an explicit hostname allowlist, or otherwise establish that the selected endpoint is trusted. Removing the element afterward does not reverse code that has already executed.
This is classified as remote payload retrieval and execution because the effective executable payload is hosted externally and can change independently after the Skill has been reviewed.
Attack Path
- An attacker compromises a configured suggestion service, controls an engine configuration, or causes
currentEngine.value.suggestionUrl(...)to return an attacker-controlled URL. - A user enters a non-empty search term and the application invokes
fetch(keyword). - The composable creates a
scriptelement whose source is the generated URL. - The browser retrieves and executes the endpoint's response in the application's page context.
- The malicious response performs actions available to page JavaScript before the cleanup routine removes the script element.
Impact Assessment
Su ...[truncated 757 chars]
- An attacker compromises a configured suggestion service, controls an engine configuration, or causes
- Remediation
View remediation
Remediation Suggestions
- Replace JSONP with
fetch()or a trusted HTTP client and require the endpoint to return JSON rather than executable JavaScript. - Parse the response as data and validate its schema before assigning it to reactive state. Confirm that the response is an array of strings and enforce length and size limits.
- Require HTTPS and reject all other URL schemes.
- Maintain an explicit allowlist of trusted origins and validate the URL with the
URLAPI before making a request. - Avoid deriving an executable script URL from mutable store data or user-controlled configuration.
- Deploy a restrictive Content Security Policy, particularly
script-src, that prevents execution from unauthorized origins. Do not weaken it with broad wildcards orunsafe-inline. - If JSONP cannot be removed, use a fixed, audited endpoint and fixed callback protocol, strictly validate configuration, document the residual remote-code-execution risk, and handle script load errors. These controls reduce exposure but cannot make untrusted JSONP equivalent to inert JSON.
- Replace JSONP with
