fix: Docker API hook manager crashes for all user-provided hooks (#1878)#1879
Open
hafezparast wants to merge 1 commit intounclecode:developfrom
Open
fix: Docker API hook manager crashes for all user-provided hooks (#1878)#1879hafezparast wants to merge 1 commit intounclecode:developfrom
hafezparast wants to merge 1 commit intounclecode:developfrom
Conversation
…lecode#1878) PR unclecode#1712 removed `__import__` from the safe builtins for security, but the hook compiler still used `exec("import asyncio", namespace)` which requires `__import__`. This broke ALL user-provided hooks. Fix: inject commonly-needed modules (asyncio, json, re, typing) directly into the namespace instead of using exec-based imports. Also add standard exception classes (ValueError, TypeError, KeyError, etc.) to the safe builtins so hooks can use try/except properly. Security: `__import__` remains blocked — users still cannot import arbitrary modules at runtime. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Collaborator
|
@hafezparast , thanks for the solid fix — the approach of replacing exec("import ...") with direct module injection is clean and correctly preserves the security intent of PR #1712. Tests are thorough. A few things to address before the merge: Must fix (critical):
Should fix:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
__import__from safe builtins for security, but the hook compiler still usedexec("import asyncio", namespace)which requires__import__— breaking ALL user-provided hooksexec-based imports with direct module injection into the namespace (namespace['asyncio'] = asyncio, etc.)ValueError,TypeError,KeyError, etc.) to safe builtins so hooks can usetry/exceptproperly__import__remains blocked — users still cannot import arbitrary modules at runtimeChanges
deploy/docker/hook_manager.py: Fix module injection + add exception classes to allowed builtinstests/docker/test_hook_manager_unit.py: 36 unit tests covering:__import__/exec/eval/open all blockedTest plan
pytest tests/docker/test_hook_manager_unit.py -v)__import__still blocked at runtime (security preserved)🤖 Generated with Claude Code