fix(security): Resolve symlinks before checking deny rules (CVE-2025-59829)

This commit fixes a security vulnerability where deny rules could be
bypassed by creating symbolic links to restricted files.

Changes:
- Add symlink resolution in rule_engine.py _extract_field method
- Add symlink resolution in security_reminder_hook.py check_patterns
- Create new symlink_deny_hook.py for blocking symlinks to system paths
- Include Read tool in file event handlers for deny rule checking
- Update hooks.json to apply security hooks to Read tool

The vulnerability allowed attackers to bypass deny rules like
Read(/etc/passwd) by creating a symlink (e.g., ln -s /etc/passwd test.txt)
and then reading the symlink instead of the restricted file directly.

The fix uses os.path.realpath() to resolve all symlinks to their canonical
paths before checking against deny patterns, ensuring that deny rules are
enforced regardless of whether the path is accessed directly or via symlink.
This commit is contained in:
Claude
2026-01-08 20:08:08 +00:00
parent f34e2535b4
commit ff0fdc0676
5 changed files with 235 additions and 7 deletions

View File

@@ -1,7 +1,16 @@
{
"description": "Security reminder hook that warns about potential security issues when editing files",
"description": "Security hooks for file access validation and security pattern warnings",
"hooks": {
"PreToolUse": [
{
"hooks": [
{
"type": "command",
"command": "python3 ${CLAUDE_PLUGIN_ROOT}/hooks/symlink_deny_hook.py"
}
],
"matcher": "Edit|Write|MultiEdit|Read"
},
{
"hooks": [
{
@@ -9,7 +18,7 @@
"command": "python3 ${CLAUDE_PLUGIN_ROOT}/hooks/security_reminder_hook.py"
}
],
"matcher": "Edit|Write|MultiEdit"
"matcher": "Edit|Write|MultiEdit|Read"
}
]
}