-
Notifications
You must be signed in to change notification settings - Fork 48
Open
Serhan-Asad/pdd
#121Description
Summary
During pdd sync, when a PDD-generated example file crashes with a ModuleNotFoundError, the function _try_auto_fix_import_error() automatically runs pip install <package_name> for any package name extracted from the error message — with no user confirmation, no allowlist, and no logging of what was installed.
Reproduction
- Create a prompt that causes the LLM to generate an example importing a package not in your environment (this happens naturally ~5-15% of the time when LLMs hallucinate imports)
- Run
pdd sync <basename> - During the
crashoperation, if the example has aModuleNotFoundError, PDD silently runspip installfor the missing package name
Affected Code
The vulnerable pattern exists in two files:
sync_orchestration.py lines 519-532:
# It's an external package - try pip install
try:
result = subprocess.run(
[sys.executable, '-m', 'pip', 'install', top_level_package],
capture_output=True,
text=True,
timeout=120
)pin_example_hack.py lines 561-574: (identical copy)
Impact
- Environment contamination:
pdd syncinstalls packages the user never asked for. These don't appear inrequirements.txtorpyproject.toml, making environments non-reproducible. - User surprise: No developer expects a code generation tool to modify their Python environment. Violates the principle of least astonishment.
- CI/CD pollution: Teams running
pdd sync --forcein CI get phantom dependencies that aren't tracked in lockfiles. Builds work today, break tomorrow when recreated from scratch. - Security (low probability): Since the package name comes from LLM-generated code, hallucinated package names could theoretically match typosquat packages on PyPI, though this is unlikely in practice.
Suggested Fix
At minimum, add a click.confirm() prompt before running pip install:
if click.confirm(f"Install missing package '{ top_level_package}'?", default=False):
subprocess.run([sys.executable, '-m', 'pip', 'install', top_level_package], ...)Better options:
- Add an
--allow-installCLI flag (off by default) - Maintain an allowlist of common safe packages for
--forcemode - Log what was installed so users can review and uninstall
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels