T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/sw_api.py:89
- Finding
- Unconditional Closure of Unrelated SOLIDWORKS Documents## Vulnerability Details **File Location**: `scripts/sw_api.py:89-93`, invoked by all supplied build scripts immediately after connecting to SOLIDWORKS **Vulnerability Type**: Unconfirmed destructive operation affecting unrelated application state **Risk Level**: Medium ### Complete Code Snippet ```python def close_all(sw): try: sw.CloseAllDocuments(True) except Exception: pass ``` Representative invocation: ```python sw = connect() close_all(sw) ``` The invocation occurs at: - `scripts/build_assembly.py:25-26` - `scripts/build_cup_shell.py:10-11` - `scripts/build_drawing.py:12-13` - `scripts/build_flange.py:10-11` - `scripts/build_flower.py:25-26` - `scripts/build_gear.py:98-99` - `scripts/build_hook.py:16-17` - `scripts/build_hook_loft.py:24-25` - `scripts/build_mug.py:21-22` - `scripts/build_spring.py:10-11` ### Technical Analysis The connection helper can attach to an already-running SOLIDWORKS instance. Every supplied build script then calls `close_all(sw)` unconditionally. The helper invokes `CloseAllDocuments(True)` without checking which documents were opened by the Skill, whether existing documents contain unsaved changes, or whether the user authorized closing unrelated work. The Skill documentation describes modeling and file-conversion operations, but the executable path expands a request to build one model into a bulk operation against all documents in the attached SOLIDWORKS session. There is no explicit opt-in flag, confirmation gate, dry-run mode, ownership tracking, or backup step. The broad exception handler also suppresses failures, reducing visibility into whether documents were partially closed. This is a reachable destructive behavior rather than evidence of malicious intent. ### Attack Path 1. The user has one or more documents open in an existing SOLIDWORKS session, potentially with unsaved changes. 2. The user invokes any supplied build script to create the script's advertised model. 3. `connect()` at ...[truncated 820 chars]
- Remediation
- ## Remediation Suggestions - Remove the unconditional `close_all(sw)` calls from the build scripts. - Track documents created or opened by the current script and close only those documents by exact title or document identity. - Before closing any pre-existing document, inspect its modified or unsaved state and request explicit user confirmation. - If bulk closure is operationally necessary, require an explicit command-line opt-in such as `--close-all-documents`; default to preserving existing documents. - Provide a dry-run or enumeration mode that lists affected documents before performing closure. - Do not suppress all exceptions. Report closure failures and stop safely if document ownership or save state cannot be established. - Consider launching a dedicated SOLIDWORKS instance for automation where supported, isolating the task from the user's interactive session.
