Skip to content

fix: harden Python hooks (injection, logging, audit)#5

Open
riaworks wants to merge 1 commit intothiagofinch:mainfrom
riaworks:fix/hooks-security-hardening
Open

fix: harden Python hooks (injection, logging, audit)#5
riaworks wants to merge 1 commit intothiagofinch:mainfrom
riaworks:fix/hooks-security-hardening

Conversation

@riaworks
Copy link

@riaworks riaworks commented Mar 1, 2026

Summary

  • M-03: Fix AppleScript injection in notification_system.py — added _escape_applescript() to sanitize \ and " before interpolation
  • M-07: Reduce data leakage in continuous_save.py — truncate from 2000/500 to 200 chars, log only safe metadata keys
  • M-10: Add audit trail to memory_updater.pyaudit_file_modification() writes to logs/memory-audit.jsonl
  • L-07: Already covered by .gitignore (__pycache__/ + *.py[cod]) — no tracked .pyc files found
  • L-11: Replace execSync with execFileSync in gsd-check-update.js — no shell invocation, added error handling

Files Changed

  • .claude/hooks/notification_system.py
  • .claude/hooks/continuous_save.py
  • .claude/hooks/memory_updater.py
  • .claude/hooks/gsd-check-update.js

Security Frameworks

Finding OWASP LLM MITRE ATLAS
M-03 LLM02 (Insecure Output Handling) AML.T0051
M-07 LLM06 (Sensitive Information Disclosure) AML.T0024
M-10 LLM09 (Misinformation) AML.T0018
L-11 LLM02 (Insecure Output Handling) AML.T0040

Test Plan

  • Verify notification_system.py handles " and \ in title/message without AppleScript breakout
  • Verify continuous_save.py logs max 200 chars per field, only metadata keys for tool_use
  • Verify memory_updater.py writes audit entries to logs/memory-audit.jsonl on file modification
  • Verify gsd-check-update.js uses execFileSync (no shell), handles npm/cache errors gracefully
  • Confirm all hooks still function normally after changes

🤖 Generated with Claude Code

- notification_system.py: Escape backslashes and double quotes in
  AppleScript strings to prevent command injection via notification
  title/message (M-03)
- continuous_save.py: Reduce log truncation from 2000/500 to 200 chars,
  log only safe metadata keys from tool inputs instead of full content
  to prevent sensitive data leakage in session logs (M-07)
- memory_updater.py: Add audit_file_modification() that logs all file
  changes to logs/memory-audit.jsonl with timestamp, file path,
  modification type, and diff summary (M-10)
- gsd-check-update.js: Replace execSync with execFileSync (no shell),
  add error handling for cache writes, document as only hook with
  network access (L-11)

Findings addressed: M-03, M-07, M-10, L-07 (already covered), L-11

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@riaworks riaworks requested a review from thiagofinch as a code owner March 1, 2026 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant