T09 · Insecure Skill Coding Practices
- Location
scripts/main.py:226- Finding
Unescaped User Input Enables XML Injection
- Content
View full analysis
') lines.append(f' {author.name}') if author.affiliation: lines.append(f' {author.affiliation}') for role_code in author.roles: role = CREDIT_ROLES[role_code] lines.append(f' ') lines.append(f' {role["en"]}') lines.append(f' ') ``` ### Technical Analysis The XML output is constructed through direct string interpolation. The `author.name` and `author.affiliation` fields originate from command-line, interactive, or JSON input and are inserted into XML without escaping XML metacharacters such as `<`, `>`, `&`, single quotes, and double quotes. An attacker can therefore terminate the expected element and introduce arbitrary XML elements or attributes into the generated document. For example, an author name containing: ```text Aliceattacker-controlled value ``` would produce attacker-controlled XML structure rather than a literal author name. The role name is selected from the fixed `CREDIT_ROLES` dictionary and is not directly attacker-controlled, but the author name and affiliation fields are sufficient to exploit the issue. ### Attack Path 1. An attacker prepares a JSON input file or command-line author value containing XML markup in the author name or affiliation. 2. The victim invokes the script with XML output, for example: ```bash python scripts/main.py --input malicious.json --format xml --output contributions.xml ``` 3. `generate_xml()` interpolates the malicious value directly into the XML document. 4. The generated file contains attack ...[truncated 1123 chars]- Remediation
View remediation
`, `&`, quotes, and attempted closing tags. Parse the resulting output with a standards-compliant XML parser and verify that injected markup remains literal text. 5. Document that XML output must not be treated as trusted merely because it was generated by this script. Downstream consumers should also use hardened XML parsers and avoid enabling external-entity resolution. ]]>
