T08 · Insecure Dependencies
- Location
scripts/transcribe.py:132- Finding
Dependency Confusion Through an Overly Broad Python Import Path
- Content
View full analysis
Vulnerability Details
File Location:
scripts/transcribe.py, lines 132-140
Vulnerability Type: Local dependency confusion and Python module path hijacking
Risk Level: HighVulnerable Code
python try: # Import heavy dependencies here current_dir = Path(__file__).resolve().parent project_root = current_dir.parent.parent.parent if str(project_root) not in sys.path: sys.path.insert(0, str(project_root)) from asr_skill import transcribe from asr_skill.core.device import get_device_with_fallbackTechnical Analysis
The script calculates
project_rootby traversing three parent directories from the directory containing the script and then prepends that location tosys.path. Given the reviewed project layout, this resolves outside the Skill package and may resolve to a broadly shared directory such as/tmp.The reviewed project does not contain the imported
asr_skillpackage. Consequently, the implementation executes whichever package namedasr_skillPython finds in the manually trusted ancestor directory. Importing a Python package executes its top-level code, so this behavior provides a direct code-execution primitive if an attacker can place a package in that directory.The
get_device_with_fallbackimport is also unused, unnecessarily increasing the number of modules whose initialization code is executed.Attack Path
- A local attacker determines the directory produced by
current_dir.parent.parent.parent. - The attacker creates an
asr_skillpackage in that directory, including an attacker-controlled__init__.py. - The victim starts either synchronous or asynchronous transcription.
run_worker()inserts the attacker-accessible ancestor directory at the beginning ofsys.path.- Python resolves
from asr_skill import transcribeto the attacker-controlled package. - The malicious package's top-level code executes with t ...[truncated 608 chars]
- A local attacker determines the directory produced by
- Remediation
View remediation
Remediation Suggestions
- Bundle the required implementation within the Skill package and use package-relative imports.
- Remove the manual insertion of an ancestor directory into
sys.path. - If
asr_skillis an external dependency, declare it through standard Python packaging with an exact or appropriately constrained version and verified package provenance. - Run the application from an isolated virtual environment whose dependencies are installed from a trusted, pinned lock file.
- Verify that the imported package resolves to the expected installation path before executing transcription.
- Remove the unused
get_device_with_fallbackimport to reduce unnecessary module execution. - Avoid placing or executing the project under shared writable directories such as
/tmp.
