Skip to content

fix: move security hook debug log from /tmp to ~/.claude/ and gate behind env var#186

Open
xiaolai wants to merge 1 commit intoComposioHQ:masterfrom
xiaolai:fix/nlpm-security-debug-log-path
Open

fix: move security hook debug log from /tmp to ~/.claude/ and gate behind env var#186
xiaolai wants to merge 1 commit intoComposioHQ:masterfrom
xiaolai:fix/nlpm-security-debug-log-path

Conversation

@xiaolai
Copy link
Copy Markdown

@xiaolai xiaolai commented Apr 21, 2026

Automated audit: This PR was generated by NLPM, a natural language programming linter, running via claude-code-action. Please evaluate the diff on its merits.

Security Fix (Medium severity)

security-guidance/hooks/security_reminder_hook.py writes a debug log unconditionally to /tmp/security-warnings-log.txt:

DEBUG_LOG_FILE = "/tmp/security-warnings-log.txt"

/tmp is world-writable on Linux/macOS. Any local user on the same machine can read this file. Since the log records which files are being edited and which security patterns triggered, it leaks session-scoped information — including file paths of files being written by Claude — to other local users.

The hook already uses ~/.claude/ for its session state files (e.g. security_warnings_state_{session_id}.json), making that the natural and already-trusted location.

Fix

Two changes:

  1. Relocate the log file from /tmp/security-warnings-log.txt to ~/.claude/security-warnings-log.txt, which is user-private and already used for hook state.

  2. Gate writes behind SECURITY_REMINDER_DEBUG=1 so no log file is created by default. The log existed only for debugging; there's no reason to write it on every hook invocation in production.

# Before
DEBUG_LOG_FILE = "/tmp/security-warnings-log.txt"

# After
_debug_log_enabled = os.environ.get("SECURITY_REMINDER_DEBUG", "0") == "1"
DEBUG_LOG_FILE = os.path.expanduser("~/.claude/security-warnings-log.txt")

Users who want debug logging can opt in with SECURITY_REMINDER_DEBUG=1 in their environment.

Impact

This is a minimal, backwards-compatible change. The hook's security warning behavior is unchanged. Debug logging is disabled by default (which was effectively true for any deployment that didn't know the undocumented /tmp path existed).

…ehind env var

The debug log was written unconditionally to /tmp/security-warnings-log.txt,
a world-writable path that any local user can read. Since the log records
which files are being edited and which security patterns fired, it leaks
session-scoped information to other local users.

Changes:
- Relocate DEBUG_LOG_FILE to ~/.claude/security-warnings-log.txt, matching
  where the hook already writes its session state files
- Gate all log writes behind SECURITY_REMINDER_DEBUG=1 env var so the log
  is disabled by default and no file is created unless explicitly opted in
- Add makedirs guard so the ~/.claude/ directory is created if needed

Co-Authored-By: Claude Code <noreply@anthropic.com>
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