T08 · Insecure Dependencies
- Location
scripts/generator.py:18- Finding
Unverified Sibling Directory Is Added to the Python Import Path
- Content
View full analysis
Vulnerability Details
File Location:
scripts/generator.py, lines 18-29
Vulnerability Type: Unsafe local dependency loading and Python path manipulation
Risk Level: HighVulnerable Code
python # Import C support library c_support_path = Path(__file__).parent.parent.parent / 'c-support' / 'lib' if c_support_path.exists(): sys.path.insert(0, str(c_support_path)) try: from c_parser import CParser from unity_templates import UnityTestGenerator, UnityCMakeTemplates C_SUPPORT_AVAILABLE = True except ImportError: C_SUPPORT_AVAILABLE = False else: C_SUPPORT_AVAILABLE = FalseTechnical Analysis
The module constructs a path outside the Skill package, adds that directory to the beginning of
sys.path, and imports modules from it based only on whether the directory exists. No package identity, ownership, integrity, or trusted-origin validation is performed.Placing the directory at index zero gives modules in that directory precedence during import resolution. Importing
c_parserandunity_templatesexecutes their module-level Python code immediately. This occurs whengenerator.pyis imported, even when the requested operation only concerns Python source code and does not require C support.An attacker who can create or modify the expected sibling directory can therefore convert a normal test-generation invocation into arbitrary Python code execution. This represents an unsafe local dependency and supply-chain trust boundary.
Attack Path
- The attacker obtains write access to the directory containing the Skill's parent directory, a shared Skill installation, an extraction directory, or the existing
c-support/libdirectory. - The attacker creates or modifies either:
c-support/lib/c_parser.py, orc-support/lib/unity_templates.py.
- The malicious module includes arbitrary top-level Python code.
- A user or Agent invokes a generation command such as:
bash py ...[truncated 970 chars]- The attacker obtains write access to the directory containing the Skill's parent directory, a shared Skill installation, an extraction directory, or the existing
- Remediation
View remediation
Remediation Suggestions
- Do not prepend an implicitly trusted sibling directory to
sys.path. - Package C support as a normal, uniquely named Python package and install it through a controlled dependency mechanism.
- Pin the dependency to a reviewed version and verify its integrity through hashes, lock files, or signed release artifacts.
- Import C-specific dependencies lazily, only after confirming that the requested input is a C or header file.
- If local loading is unavoidable:
- Resolve the expected path canonically.
- Require it to remain under an explicitly configured trusted installation root.
- Validate directory and file ownership and reject group- or world-writable locations.
- Verify module hashes against a trusted manifest before import.
- Avoid generic top-level module names such as
c_parser.
- Execute optional parsers in a restricted subprocess if they may originate outside the core Skill package.
- Do not prepend an implicitly trusted sibling directory to
