Add hook hijacking detection for Claude Code (CVE-2025-59536)#64
Conversation
Detect malicious hooks in .claude/settings.json and .claude/hooks/ that execute network commands, read sensitive files, or tamper with security settings. Checks for project-level security overrides (bypassPermissions, autoApprove) and unrestricted Bash permissions. 5 new checks: CHK-001 through CHK-005. Maps to OWASP ASI01 (Hijack), ASI02 (Agency), ASI05 (Secrets), ASI06 (Memory). Signed-off-by: debu-sinha <debusinha2009@gmail.com>
| ), | ||
| ) | ||
| ) | ||
| except (json.JSONDecodeError, OSError): |
Check notice
Code scanning / CodeQL
Empty except Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 2 months ago
In general, an empty except should either (a) handle the error in a meaningful way (e.g., logging, fallback behavior, metrics) or (b) narrow the caught exception and re-raise if it cannot be safely ignored. Here, the scanner should not crash if a single settings file is unreadable, but it also should not fail silently.
Best minimal fix without changing existing functionality: keep the behavior of “no findings if the file is unreadable/unparsable”, but add a log entry inside the except block explaining that the project settings at project_settings could not be processed and why. We already have a logger defined at the top of the file, so we can reuse it without new imports. We should log at warning (or possibly debug); given this is an unexpected I/O/JSON failure on a security config, warning is reasonable and visible but not fatal.
Concretely, in src/agentsec/scanners/installation.py, in the _scan_hook_hijacking method region around lines 2156–2216, replace:
except (json.JSONDecodeError, OSError):
passwith something like:
except (json.JSONDecodeError, OSError) as exc:
logger.warning(
"Failed to read or parse project settings at %s: %s",
project_settings,
exc,
)This maintains flow (no exception is propagated) but removes the empty except and improves diagnosability.
| @@ -2212,8 +2212,12 @@ | ||
| ), | ||
| ) | ||
| ) | ||
| except (json.JSONDecodeError, OSError): | ||
| pass | ||
| except (json.JSONDecodeError, OSError) as exc: | ||
| logger.warning( | ||
| "Failed to read or parse project settings at %s: %s", | ||
| project_settings, | ||
| exc, | ||
| ) | ||
|
|
||
| return findings | ||
|
|
Signed-off-by: debu-sinha <debusinha2009@gmail.com>
Signed-off-by: debu-sinha <debusinha2009@gmail.com>
Signed-off-by: debu-sinha <debusinha2009@gmail.com>
Closes #56
What changed
Added hook hijacking detection to the installation scanner. Detects malicious hooks in
.claude/settings.json,.claude/settings.local.json, and.claude/hooks/directory.New checks
OWASP mapping
Testing
Tested against a malicious fixture with:
Result: 4 CRITICAL + 4 HIGH findings detected. Security grade F (12/100).