T09 · Insecure Skill Coding Practices
- Location
scripts/format_sgcc.py:368- Finding
Automatic Updating of Untrusted Word Fields
- Content
View full analysis
Vulnerability Details
File Location:
scripts/format_sgcc.py, lines 368–372
Vulnerability Type: Global activation of fields preserved from an untrusted DOCX file
Risk Level: MediumVulnerable Code
python settings = doc.settings.element uf = settings.find(qn("w:updateFields")) if uf is None: uf = OxmlElement("w:updateFields") settings.append(uf) uf.set(qn("w:val"), "true")Technical Analysis
The script accepts a user-supplied DOCX file at line 240, modifies it, and enables the document-wide
w:updateFieldssetting before saving the result. This setting is not limited to the TOC and page-number fields generated by the script. It also applies to pre-existing fields retained from the untrusted input.The implementation does not inspect or remove existing field instructions, external relationships, or linked content before enabling automatic field updates. Consequently, a malicious input can contain attacker-controlled external fields or links that remain in the output and may be processed by Microsoft Word when the recipient opens it.
The vulnerability does not grant privileges to the formatting script itself. Exploitation depends on the recipient opening the generated file in a Word environment that permits or attempts the relevant field or external-content update.
Attack Path
- An attacker creates a DOCX containing a field or linked object that references an attacker-controlled external resource.
- The attacker submits the document for formatting.
- The script loads the untrusted document and preserves its existing field instructions and relationships.
- The script sets the global
w:updateFieldsoption totrue. - The generated DOCX is returned to the recipient through the documented file-delivery workflow.
- The recipient opens the output in Microsoft Word.
- Word attempts to update the preserved attacker-controlled content, subject to the recipient's Word security configuration and prompts.
- The ex ...[truncated 764 chars]
- Remediation
View remediation
Remediation Suggestions
- Do not enable document-wide automatic field updates for untrusted input files. Remove the
w:updateFieldssetting and instruct recipients to update the generated TOC manually. - Before saving, enumerate all existing field instructions and reject or remove fields not explicitly generated by this formatter.
- Allow only a narrow field allowlist, such as the locally generated
TOCandPAGEfields. - Inspect the DOCX relationship files and remove or reject external relationships, including externally linked images, templates, OLE objects, and other linked content.
- If automatic TOC refresh is essential, generate a sanitized document from approved content rather than mutating an untrusted package while preserving its original relationships.
- Add regression tests using DOCX fixtures containing external fields and relationships. Verify that the output contains no unapproved external targets and does not globally request field updates.
- Do not enable document-wide automatic field updates for untrusted input files. Remove the
