T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/wps_word_automation.py:14
- Finding
- Untrusted Documents Are Opened Without Explicitly Disabling Active Content<![CDATA[ ## Vulnerability Details **File Location**: `scripts/wps_word_automation.py`, lines 14–29 **Vulnerability Type**: Unsafe processing of untrusted Office documents **Risk Level**: High ### Vulnerable Code ```python def get_app(app_name: str, visible: bool): import win32com.client # type: ignore progids = APP_PROGIDS.get(app_name, []) for pid in progids: try: app = win32com.client.Dispatch(pid) app.Visible = bool(visible) return app except Exception: continue # fallback to Word app = win32com.client.Dispatch("Word.Application") app.Visible = bool(visible) return app def open_doc(app, path: str): return app.Documents.Open(path, ReadOnly=False) ``` ### Technical Analysis The application creates a Microsoft Word or WPS Writer COM instance and opens a user-supplied document in writable mode. It does not explicitly force-disable macros, use Protected View, validate the input extension, or otherwise restrict active document content. Consequently, macro-enabled documents and other potentially active formats are passed directly to the installed Office application. Whether active content executes depends on the application version, trust-center configuration, trusted-location settings, document provenance, and related host security controls. Independently of macro behavior, opening an attacker-controlled document exposes the Office/WPS parser to potentially malicious content. The same `open_doc` function is used by document-processing commands such as `read`, `replace`, `insert`, `headings`, `header-footer`, `page-break`, `split`, `export`, and `image`. ### Attack Path 1. An attacker supplies or recommends a malicious Office or WPS document. 2. A user or agent invokes one of the Skill commands with the document as `--input`. 3. The script starts Word or WPS through COM. 4. `Documents.Open(path, ReadOnly=False)` opens the document without first enforcing ma ...[truncated 826 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Set the Office automation security policy to force-disable macros before opening any untrusted document. Preserve the previous value and restore it during cleanup. 2. Open untrusted documents through Protected View where supported, or reject them if Protected View cannot be enforced. 3. Implement an explicit extension allowlist for ordinary non-macro formats. Reject macro-enabled formats such as `.docm`, `.dotm`, and equivalent WPS formats unless the caller explicitly authorizes them. 4. Consider opening source documents read-only when a command does not need in-place modification. 5. Disable automatic link updates and other external-content processing when opening documents. 6. Run document automation in a sandboxed, low-privilege process or isolated environment, particularly for documents from untrusted sources. 7. Use `try/finally` cleanup to ensure documents and the application are closed and security settings are restored after errors. 8. Document that Office/WPS security updates must be maintained because document parsing itself remains an attack surface. ]]>
