Skip to content

fix: harden hooks, MCP server, and config (security audit)#893

Open
brodsky754 wants to merge 1 commit intoMemPalace:developfrom
brodsky754:security/audit-fixes-2026-04
Open

fix: harden hooks, MCP server, and config (security audit)#893
brodsky754 wants to merge 1 commit intoMemPalace:developfrom
brodsky754:security/audit-fixes-2026-04

Conversation

@brodsky754
Copy link
Copy Markdown

Summary

  • hooks_cli: Add _is_safe_transcript_path() to reject .. traversal in transcript reads; add _is_valid_mempal_dir() to validate MEMPAL_DIR contains project markers before subprocess spawn; canonicalize all paths via os.path.realpath()
  • mcp_server: Replace str(e) with "Internal error" in 12 except Exception handlers to prevent leaking file paths/internal state to MCP clients (keeps str(e) in ValueError handlers for user-facing validation)
  • config: Create config.json atomically with os.open(O_CREAT|O_EXCL, 0o600) to eliminate TOCTOU permission window; write people_map.json with 0o600 permissions (contains PII)

Context

Full security audit of the codebase found 0 Critical, 3 High, 6 Medium, 6 Low findings. This PR addresses all 3 High and 3 trivial Medium fixes. Remaining Medium/Low findings are documented in the audit report (informational only).

Test plan

  • All 864 baseline tests pass (0 regressions)
  • Updated 4 test fixtures to create .git marker dirs for new _is_valid_mempal_dir() validation
  • Verified via background agent that all fixes are correct and complete

🤖 Generated with Claude Code

… injection, and info leakage

Security audit identified 3 High and 3 Medium findings. This commit addresses
them with minimal, targeted fixes while preserving all 864 baseline tests.

High fixes:
- hooks_cli: validate transcript_path rejects ".." traversal before reading
- hooks_cli: validate MEMPAL_DIR contains project markers before subprocess spawn,
  canonicalize paths via os.path.realpath()
Medium fixes:
- mcp_server: replace str(e) with "Internal error" in Exception handlers (12 sites)
  to prevent leaking file paths and internal state to MCP clients
- config: create config.json atomically with os.open(O_CREAT|O_EXCL, 0o600)
  to eliminate TOCTOU permission window
- config: write people_map.json with 0o600 permissions (contains PII)

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@igorls igorls added security Security related bug Something isn't working labels Apr 14, 2026
@bensig
Copy link
Copy Markdown
Collaborator

bensig commented Apr 15, 2026

hey @brodsky754 — this conflicts with develop. also pls rebase onto #863 (precompact fix) first since both touch hooks_cli.py — merging in the wrong order would regress the compaction fix. thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working security Security related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants