Summary
FreeCAD can execute attacker-controlled Python module code when restoring a crafted FCStd document because serialized object metadata is used during module import and legacy object construction. An attacker may gain code execution in the context of the FreeCAD process if a user or automated workflow opens the malicious document.
Affected context
The vulnerability occurs in FreeCAD's PropertyPythonObject restoration logic when serialized XML or legacy pickle data contains attacker-controlled module information. It becomes risky when a crafted FCStd document is opened or otherwise restored by a FreeCAD process with access to sensitive files, credentials, or connected services.
Exploit preconditions
- Attack surface: FreeCAD document parsing and object restoration
- Required access: Ability to provide or influence an FCStd document that a target user or workflow will open
- Trigger point: Restoration of serialized PropertyPythonObject data during document loading
- Why exploitation is possible: The module attribute can reach Python module import and, in the legacy path, object construction without sufficiently restricting the referenced code
Why this happens
The underlying bug is the treatment of attacker-controlled serialized metadata as a trusted instruction for Python module loading and object construction. Property restoration passes a module name to an import operation, while the legacy pickle branch can import a chosen module and invoke a class constructor; these behaviors map to CWE-94: Improper Control of Generation of Code, because document data influences executable Python behavior rather than remaining passive application state.
Potential impact
- Arbitrary Python code may execute with the privileges of the FreeCAD process
- Local files or environment data could be read or modified
- Credentials, tokens, or project data may be exposed
- The workstation or automated document-processing environment could be compromised
- Malicious changes could be made to models or downstream engineering workflows
General mitigation guidance
Mitigation generally focuses on keeping document data separate from executable behavior and reducing trust in serialized object metadata.
Useful defensive patterns include:
- Restricting deserialization to an allowlisted set of inert types and modules
- Avoiding dynamic imports and constructor invocation based solely on document-provided values
- Applying explicit schemas and validation before restoring Python-backed properties
- Treating documents from external or untrusted sources as untrusted content
- Running automated document processing with least-privilege accounts, isolation, and limited filesystem and network access
- Disabling or removing legacy deserialization paths that permit executable object reconstruction where they are not required
How teams detect issues like this
Detection can combine static and runtime analysis, including:
- Searching for document-controlled values passed to dynamic import, reflection, constructor, or pickle APIs
- Reviewing restoration and parser code for executable behavior triggered before validation
- Flagging serialized fields that select modules, classes, callbacks, or other executable objects
- Monitoring FreeCAD processes for unexpected child processes, module loads, filesystem access, or network connections during document opening
- Enforcing repository policies that prohibit unsafe deserialization and unrestricted dynamic imports
- Using automated code review or security scanning tools to identify these patterns during development

