Skip to content

fix(security): escape recall boundaries + harden key expiry/session cleanup - #2006

Open
TINGyu123644 wants to merge 2 commits into
TencentCloud:feat/server_teamfrom
TINGyu123644:fix/security-and-robustness
Open

TINGyu123644 wants to merge 2 commits into
TencentCloud:feat/server_teamfrom
TINGyu123644:fix/security-and-robustness

Conversation

@TINGyu123644

Copy link
Copy Markdown

Summary

Small, focused hardening patch found during source review. Split into two commits:

1. fix(security) — escape injected-section boundaries in recall contexts (relates to #2005)

Recalled memory content and L3 persona are persisted values (LLM extraction, panel edits, imports) that are concatenated into XML-delimited prompt sections. Without escaping, a stored value containing a matching closing tag can break out of its section and be read as a system-level instruction on a future recall — a stored prompt-injection / memory-poisoning risk.

  • MemoryCore/openclaw-plugin/src/sanitize.ts: add escapeXmlTags() mirroring the existing core helper.
  • MemoryCore/openclaw-plugin/src/format.ts: escape L1 memory content and persona before injecting them into <relevant-memories> / <user-persona>.
  • MemoryCore/src/core/hooks/auto-recall.ts: escape persona, scene navigation and L1 memory lines at read/injection time, so edited/imported values are covered regardless of how they were produced.
  • Regression tests for both the client plugin and the core path.

2. fix — key expiry, session reclamation, debug cleanup

  • user-key.ts: an unparseable expires_at now fails closed (treated as expired) instead of yielding a never-expiring credential. Absent value still means "no expiry".
  • session-store.ts: reclaim all expired sessions on create() and enforce a capacity cap, so sessions that are never revisited cannot accumulate indefinitely. No background timer is used, so the Node process can still exit normally.
  • codex.ts: remove a leftover DEBUG block that dumped the request_user_input tool schema to stdout on every request.
  • Regression tests for key expiry and session-store reclamation.

Verification

Dependency install was not available in the author's environment, so the pure functions were exercised directly with Node 22's type stripping: 19 assertions on escapeXmlTags / isUserKeyExpired and 4 on the session-store algorithm, all passing. Vitest regression tests are included for CI to run in the project's normal setup.

Test plan

  • cd MemoryCore && npm test (vitest) — new sanitize.injection-boundary.test.ts, user-key.test.ts
  • cd MemoryCore/openclaw-plugin && npx vitest run tests/format.injection-boundary.test.ts
  • cd MemoryPanel && npm test (vitest) — new session-store-expiry.test.ts
  • Confirm ordinary content (markdown, unrelated tags) is unchanged in recall output

Notes

All commits are DCO signed-off. Base branch: feat/server_team.

@github-actions

Copy link
Copy Markdown

Thank you for your contribution! This is an automated acknowledgment. We'll review it internally soon and share all feedback in the discussion below.

Memory content and persona are persisted values (LLM extraction, panel edits, imports) that get concatenated into XML-delimited prompt sections such as <relevant-memories> and <user-persona>. A stored value containing a matching closing tag could break out of its section and be interpreted as a system-level instruction on a future recall (stored prompt injection / memory poisoning).

- Add escapeXmlTags to the openclaw client plugin's sanitize.ts (mirrors the core helper) and apply it to L1 memory content and persona in format.ts.
- Apply escapeXmlTags in core auto-recall hook at read time for persona, scene navigation and L1 memory lines, so protection also covers edited/imported values regardless of how they were produced.

Adds regression tests for both client and server paths.

Signed-off-by: TINGyu123644 <TINGyu123644@users.noreply.github.com>
- user-key: an unparseable expires_at now fails closed (treated as expired) instead of producing a never-expiring credential. Absent value still means no expiry.
- session-store: reclaim all expired sessions on create() and enforce a capacity cap, so entries never revisited cannot accumulate indefinitely. Avoids a background timer (which would keep the Node process alive).
- codex runner: remove a leftover DEBUG block that dumped the request_user_input tool schema to stdout on every request.

Adds regression tests for key expiry and session-store reclamation.

Signed-off-by: TINGyu123644 <TINGyu123644@users.noreply.github.com>

This branch has not been deployed

No deployments
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