Skip to content

fix: security hardening — shell injection, SSL bypass, error leaks, read-only MCP mode#34

Closed
kushjoy wants to merge 1 commit intoMemPalace:developfrom
kushjoy:fix/security-hardening
Closed

fix: security hardening — shell injection, SSL bypass, error leaks, read-only MCP mode#34
kushjoy wants to merge 1 commit intoMemPalace:developfrom
kushjoy:fix/security-hardening

Conversation

@kushjoy
Copy link
Copy Markdown

@kushjoy kushjoy commented Apr 7, 2026

Summary

Security hardening across 6 files, addressing findings from a full codebase audit.

  • Shell injection (hooks/mempal_save_hook.sh): $TRANSCRIPT_PATH was string-interpolated directly into an inline Python script — a path containing a single quote could
    inject arbitrary code. Fixed by passing it via env var. $SESSION_ID sanitized with tr before use as a filename component to prevent path traversal.
  • SSL bypass (benchmarks/convomem_bench.py): ssl._create_unverified_context was globally disabling certificate verification, enabling MITM on all HTTPS connections
    including API key transmission. Removed.
  • Personal credential names (benchmarks/longmemeval_bench.py): Hardcoded personal key names (lu_key, anthropic_milla, anthropic_claude_code_main) and a personal
    config path (~/.config/lu/keys.json) were published in the repo. Simplified _load_api_key() to use only the standard ANTHROPIC_API_KEY env var.
  • Internal path leakage (mempalace/mcp_server.py): str(e) was returned directly in MCP responses, exposing internal file paths. Replaced with generic messages; real
    errors still logged server-side.
  • Read-only MCP mode (mempalace/mcp_server.py): Added --read-only flag that blocks all write tools (mempalace_add_drawer, mempalace_kg_add, mempalace_diary_write)
    at the dispatch layer, mitigating memory poisoning from untrusted MCP clients.
  • MD5 collision risk (mempalace/mcp_server.py, mempalace/knowledge_graph.py): MD5 truncated to 16 hex chars was used for ID generation — collisions could cause silent
    data overwrites. Replaced with uuid4.
  • .gitignore gaps: Added entities.json, known_names.json, identity.txt, *.sqlite3, *.db to prevent personal data files from being accidentally committed.

Test plan

  • All 9 existing tests pass (pytest tests/ -v)
  • Python syntax verified on all changed files
  • No new dependencies (uuid, argparse are stdlib)

IgorTavcar added a commit to IgorTavcar/mempalace that referenced this pull request Apr 7, 2026
Cherry-picked from upstream PR MemPalace#34 (kushjoy).
- Fix shell injection in mempal_save_hook.sh (env var instead of interpolation)
- Remove SSL certificate verification bypass in benchmarks
- Remove hardcoded personal API key paths from benchmark code
- Replace str(e) in MCP error responses with generic messages (prevents path leakage)
- Replace truncated MD5 IDs with uuid4 (collision safety)
- Add --read-only MCP flag to block write tools from untrusted clients
- Add PII-sensitive files to .gitignore

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
adv3nt3 added a commit to adv3nt3/mempalace that referenced this pull request Apr 7, 2026
Add usedforsecurity=False to hashlib.md5() calls in miner.py and
convo_miner.py to document that MD5 is used for deterministic ID
generation, not cryptographic security. Preserves stable drawer IDs
for backward compatibility with existing palaces.

Swapping to SHA-256 would change the ID formula and make existing
drawers unreachable on re-ingestion. PR MemPalace#34 covers the MD5 sites
in knowledge_graph.py and mcp_server.py.

Verified: usedforsecurity kwarg is supported since Python 3.9
(project target per pyproject.toml line 10), confirmed via Context7
CPython docs.
@bensig
Copy link
Copy Markdown
Collaborator

bensig commented Apr 7, 2026

Thanks for the thorough security audit! A few of these have already been merged separately:

The remaining changes are valuable though — especially removing the ssl bypass in benchmarks, the hardcoded key file paths in longmemeval_bench.py, and the .gitignore additions. Could you split those into a smaller focused PR? The current diff overlaps too much with merged work and would be hard to land cleanly.

@kushjoy
Copy link
Copy Markdown
Author

kushjoy commented Apr 8, 2026

@bensig noted. Focused security fixes — no overlap with #114 or #62.

  • convomem_bench.py: remove ssl._create_unverified_context bypass; SSL validation should be handled at the environment/CA level
  • longmemeval_bench.py: remove ~/.config/lu/keys.json key fallback — API keys must come from --llm-key flag or ANTHROPIC_API_KEY env var only
  • .gitignore: exclude entities.json, known_names.json, identity.txt, *.sqlite3, *.db to prevent accidental data/credential commits

@bensig
Copy link
Copy Markdown
Collaborator

bensig commented Apr 9, 2026

@kushjoy 1 conflict to fix pls

@bensig
Copy link
Copy Markdown
Collaborator

bensig commented Apr 9, 2026

@kushjoy pls rebase

@kushjoy kushjoy force-pushed the fix/security-hardening branch from 87300ed to a0a7a06 Compare April 10, 2026 09:24
@kushjoy
Copy link
Copy Markdown
Author

kushjoy commented Apr 10, 2026

done

Copy link
Copy Markdown

@web3guru888 web3guru888 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔧 Review of #34fix: security hardening — shell injection, SSL bypass, error leaks, read-only MCP mode

Scope: +9/−33 · 3 file(s)

  • .gitignore (modified: +5/−0)
  • benchmarks/convomem_bench.py (modified: +0/−4)
  • benchmarks/longmemeval_bench.py (modified: +4/−29)

🟢 Approved — clean, well-structured PR. Good work @kushjoy!


🏛️ Reviewed by MemPalace-AGI · Autonomous research system with perfect memory · Showcase: Truth Palace of Atlantis

- convomem_bench.py: drop ssl._create_unverified_context bypass; SSL
  validation should be configured at the environment/CA level
- longmemeval_bench.py: remove ~/.config/lu/keys.json fallback; API keys
  must come from --llm-key arg or ANTHROPIC_API_KEY env var only
- .gitignore: exclude entities.json, known_names.json, identity.txt,
  *.sqlite3, *.db to prevent accidental credential/data commits

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@kushjoy kushjoy force-pushed the fix/security-hardening branch from a0a7a06 to b48e6cc Compare April 11, 2026 15:41
@kushjoy
Copy link
Copy Markdown
Author

kushjoy commented Apr 11, 2026

small update pushed for gitignore to rebase. @bensig lets merge :)

@bensig bensig changed the base branch from main to develop April 11, 2026 22:23
@bensig bensig requested a review from igorls as a code owner April 11, 2026 22:23
@bensig
Copy link
Copy Markdown
Collaborator

bensig commented Apr 12, 2026

Closing — this is superseded by recently merged PRs to develop. Thank you for the contribution!

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.

3 participants