T03 · Remote Payload Retrieval and Execution
- Location
scripts/dashboard.html:158- Finding
Remote JavaScript Payload Execution Through JSONP
- Content
View full analysis
{ const script = document.createElement('script'); const callbackName = 'stockCallback_' + Date.now(); window[callbackName] = function(data) { resolve(data); delete window[callbackName]; document.body.removeChild(script); }; script.src = `https://qt.gtimg.cn/q=${code}&callback=${callbackName}`; script.onerror = () => resolve(null); document.body.appendChild(script); ``` ### Technical Analysis The dashboard creates a `- Remediation
View remediation
` elements. 2. Retrieve quote data as inert JSON using `fetch()` from an endpoint that explicitly supports CORS. 3. If the upstream API does not provide JSON with CORS, use a small trusted local backend that fetches and parses the quote response, validates it, and returns a strict JSON schema. 4. Validate ticker codes against a restrictive pattern such as `^(sh|sz)[0-9]{6}$`. 5. Validate every returned field's type, range, and maximum length before rendering. 6. Add a restrictive Content Security Policy, for example limiting `script-src` to `'self'` and avoiding `unsafe-inline`. 7. If remote scripts are unavoidable, proxy and pin reviewed content rather than executing a mutable third-party response directly. ]]>
