T09 · Insecure Skill Coding Practices
- Location
scripts/twilio_comms.py:104- Finding
Unescaped Call Message Permits TwiML/XML Injection
- Content
View full analysis
{msg}' data["Twiml"] = twiml ``` ### Technical Analysis The user-controlled `--message` value is interpolated directly into an XML document without XML escaping or structural validation. An input containing XML metacharacters or TwiML elements can terminate the intended `` element and introduce additional TwiML verbs. Twilio parses the resulting document as executable call instructions. Consequently, an input intended only to provide spoken text may alter the call flow. Exploitability depends on an attacker being able to influence the value passed to `--message`, such as through an automation workflow that forwards untrusted content to this CLI. ### Attack Path 1. An attacker supplies or influences a message containing crafted TwiML markup. 2. An automation process invokes `call-make` and passes that content through `--message`. 3. The script inserts the content directly between `` and `` without escaping. 4. The generated TwiML is submitted to Twilio through the authenticated account. 5. Twilio interprets the injected elements as call instructions rather than spoken text. 6. The call may perform unintended actions allowed by the account and Twilio’s TwiML processing rules. ### Impact Assessment Successful exploitation can modify outbound call behavior under the privileges of the configured Twilio account. Depending on the injected TwiML and account configuration, this could cause calls to contact unintended destinations, redirect call processing, initiate recording behavior, disclose call content, or incur unexpected telephony charges. The issue does not grant local operating-system privileges or expose the Twilio au ...[truncated 116 chars]- Remediation
View remediation
` using a standard routine such as `xml.sax.saxutils.escape`. - Prefer Twilio’s supported TwiML response builder so user input is represented as text rather than concatenated markup. - Reject invalid XML control characters and enforce a reasonable message-length limit. - Keep raw TwiML support separate from plain-text message support. If raw TwiML is ever required, expose it only through an explicitly privileged option and validate allowed TwiML verbs and attributes. - Add tests using payloads containing `<`, `>`, `&`, quotes, closing `` tags, and additional TwiML elements to verify that they remain spoken text. Example hardening: ```python from xml.sax.saxutils import escape msg = args.message or "Hello, this is an automated call." safe_msg = escape(msg) twiml = ( '' f"{safe_msg}" ) data["Twiml"] = twiml ``` ]]>
