T09 · Insecure Skill Coding Practices
- Location
scripts/rkm.py:827- Finding
Microsoft Word COM Conversion Opens Documents Without Disabling Macros
- Content
View full analysis
Vulnerability Details
File Location:
scripts/rkm.py:827-848
Vulnerability Type: Unsafe processing of active document content
Risk Level: HighVulnerable Code
python file_format = 16 if output_path.suffix.lower() == DOCX_SUFFIX else 0 script = r""" $ErrorActionPreference = 'Stop' $word = $null $doc = $null try { $word = New-Object -ComObject Word.Application $word.Visible = $false $word.DisplayAlerts = 0 $doc = $word.Documents.Open($env:RKM_WORD_INPUT, $false, $true, $false) $doc.SaveAs2($env:RKM_WORD_OUTPUT, [int]$env:RKM_WORD_FORMAT) } finally { if ($doc -ne $null) { $doc.Close($false) | Out-Null } if ($word -ne $null) { $word.Quit() | Out-Null } } """ env = os.environ.copy() env["RKM_WORD_INPUT"] = str(input_path) env["RKM_WORD_OUTPUT"] = str(output_path) env["RKM_WORD_FORMAT"] = str(file_format) creationflags = getattr(subprocess, "CREATE_NO_WINDOW", 0) result = subprocess.run( [powershell, "-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-Command", script],Technical Analysis
The Windows conversion path starts Microsoft Word through COM and opens the user-supplied legacy document without first setting Word's
AutomationSecurityproperty to force-disable macros. Opening the document as read-only, hiding the Word interface, and disabling alerts do not provide a security boundary against active content.The PowerShell process also uses
-ExecutionPolicy Bypass. Although the PowerShell script itself is fixed and file paths are passed through environment variables rather than interpolated into the script, this setting does not mitigate malicious behavior originating from the document being opened.This functionality is relevant to the declared support for legacy
.docfiles, but opening potentially untrusted documents in a fully privileged desktop Word process exceeds the minimum safe processing model. Conversion should occur ...[truncated 1243 chars]- Remediation
View remediation
Remediation Suggestions
-
Set Word's automation security mode before opening any document:
powershell $word = New-Object -ComObject Word.Application $word.AutomationSecurity = 3 # msoAutomationSecurityForceDisable $word.Visible = $false $word.DisplayAlerts = 0 -
Prefer Protected View or another conversion mechanism that does not execute document active content.
-
Process untrusted legacy documents in a sandboxed, disposable worker with restricted filesystem access, no credentials, and no network access.
-
Consider rejecting macro-capable or legacy inputs unless the user explicitly opts into conversion after receiving a security warning.
-
Document that read-only mode does not make an untrusted Office document safe.
-
Add automated Windows tests confirming that macro execution remains disabled during COM conversion.
-
