fix: enforce per-user memory/session isolation for multi-user gateway#17989
Closed
Cyrene963 wants to merge 1 commit into
Closed
fix: enforce per-user memory/session isolation for multi-user gateway#17989Cyrene963 wants to merge 1 commit into
Cyrene963 wants to merge 1 commit into
Conversation
d6df96b to
58a4dd6
Compare
This was referenced May 3, 2026
Cyrene963
pushed a commit
to Cyrene963/hermes-agent
that referenced
this pull request
May 4, 2026
…ries - Add user_id parameter to session_search(), list_sessions_rich(), search_messages() - Add s.user_id = ? WHERE clause in both DB query methods - Pass user_id through tool handler kwargs - Fixes multi-user isolation regression where all users could see each other's sessions Closes NousResearch#17989 (isolation incomplete without query-level filtering)
0eaa539 to
d3e25da
Compare
- Add user_id parameter to MemoryStore and get_memory_dir() for per-user USER.md/MEMORY.md
- Pass user_id from AIAgent to MemoryStore during initialization
- Per-user memory directories: memories/{chat_id}/USER.md, memories/{chat_id}/MEMORY.md
- Adds session_search user_id filtering (from PR NousResearch#12571)
- Adds Hindsight per-platform retain gate (from PR NousResearch#12571)
Fixes cross-user data leakage where User A's profile and memory were
injected into User B's system prompt in multi-user gateway deployments.
d3e25da to
26a31ff
Compare
7 tasks
Author
|
Closing this PR — the functionality has already been implemented locally in our fork's patch stack (local patch applied). The local implementation covers the same scope and has been running in production. Thanks for the contribution! If upstream merges similar functionality, we'll rebase our patches accordingly. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In multi-user gateway deployments (e.g., multiple Telegram users sharing one Hermes instance), user data leaks across sessions:
1. System prompt injection — USER.md shared across all users
USER.mdis a single shared file (~/.hermes/memories/USER.md). When User A's profile (name, school, DOB, goals) is in USER.md, User B sees User A's identity in their system prompt.Fix: Per-user memory directories —
memories/{chat_id}/USER.mdandmemories/{chat_id}/MEMORY.md.2. session_search cross-user leakage
session_searchsearches the entire session database without user filtering, exposing User A's conversation history to User B or cron jobs.Fix: Added
user_idparameter tosearch_messages()andlist_sessions_rich()inhermes_state.py, threaded throughsession_search_tool.py.3. Hindsight memory cross-contamination on iLink WeChat (微信)
The iLink Bot API (
ilinkai.weixin.qq.com) reports the bot's own user_id asfrom_user_idfor ALL inbound messages, regardless of who actually sent them. This means:from_user_idFix: Per-platform retain gate in
hindsight/__init__.py— skipsauto_retainon platforms that can't distinguish users (detected by platform name or identical from_user_id).Changes (5 files, +63/-25)
tools/memory_tool.pyget_memory_dir(user_id=None)returns per-user subdir;MemoryStoreacceptsuser_idrun_agent.pyself._user_idtoMemoryStore()tools/session_search_tool.pyuser_idto DB queriesplugins/memory/hindsight/__init__.pyhermes_state.pyuser_idfilter insearch_messages()andlist_sessions_rich()How to set up per-user USER.md
Testing
session_search→ verify only User B's sessions appearRelated
Supersedes #12571 (original session_search + iLink fix, unmerged)