T08 · Insecure Dependencies
- Location
scripts/analyzer.py:17- Finding
Untrusted External Python Module Loading Through Parent-Directory Search Path
- Content
View full analysis
Vulnerability Details
File Location:
scripts/analyzer.py, lines 17-24
Vulnerability Type: Python dependency or module hijacking
Risk Level: MediumVulnerable 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 c_security_rules import CSecurityChecker C_SUPPORT_AVAILABLE = True except ImportError: C_SUPPORT_AVAILABLE = FalseTechnical Analysis
The analyzer constructs a path outside the audited project package, inserts that directory at the beginning of
sys.path, and importsc_parserandc_security_rulesfrom it. Neither module is included or integrity-pinned by this project.Because Python executes module-level code during import, control over the external
c-support/libdirectory is equivalent to control over code executed whenscripts/analyzer.pyis loaded. Prepending the directory tosys.pathgives files at that location priority over modules available from lower-priority search locations.The
except ImportErrorblock does not provide a security boundary. It only handles import failures and does not prevent arbitrary module-level instructions from running before or during import.Attack Path
- An attacker obtains write access to the calculated external
c-support/libdirectory or can create that directory in the expected parent location. - The attacker places a malicious
c_parser.pyorc_security_rules.pyfile there. - A user invokes
scripts/main.py, executesscripts/analyzer.py, or otherwise imports the analyzer module. - The analyzer prepends the attacker-influenced directory to
sys.path. - Python imports the malicious module and immediately executes its module-level payload.
- The payload runs with the same operating-syst ...[truncated 932 chars]
- An attacker obtains write access to the calculated external
- Remediation
View remediation
Remediation Suggestions
- Package the C-support modules within the Skill's own trusted Python package and load them using explicit relative imports.
- Remove the mutation of
sys.path, especially insertion of a mutable directory outside the project package. - If the components are third-party dependencies, distribute them through a trusted package repository, pin exact versions and hashes, and verify them during installation.
- If external plugin loading is an intentional feature, require an explicit administrator-controlled configuration rather than deriving a parent-directory path implicitly.
- Before loading an external plugin, validate the canonical path, ownership, permissions, and expected cryptographic digest or signature.
- Run the analyzer with least privilege and in a sandbox when reviewing untrusted projects.
- Add a regression test confirming that modules placed in adjacent or parent directories cannot be imported automatically.
