[GH-ISSUE #2641] [Issue]: sanitizeTextAgentResponse misses the message_id-attributed <committed_tracker_state> tag #1300

Closed
opened 2026-10-21 05:31:08 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @Romuromylus on GitHub (Jun 19, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2641

Originally assigned to: @Romuromylus on GitHub.

Summary

Severity: Low — leak (self-injection of tracker JSON into the main prompt). sanitizeTextAgentResponse strips only the attribute-less <committed_tracker_state> tag, but buildCommittedTrackerStateContext now emits <committed_tracker_state message_id="..."> when includeMessageIds is true. An echoed attributed block therefore survives sanitization and is injected back into the prompt.

Expected behavior

The sanitizer should strip the committed-tracker-state block regardless of attributes on the opening tag, so an echoed tracker block never re-enters the main prompt.

Actual behavior

packages/server/src/services/agents/agent-executor.ts:1910:

.replace(/<committed_tracker_state>[\s\S]*?<\/committed_tracker_state>/gi, "")

This matches only the bare tag, while buildCommittedTrackerStateContext (1357–1359) emits <committed_tracker_state${messageIdAttr}> whenever options.includeMessageIds is true (set from edit_messages === true, line 1080). The text/sanitize path is taken only when the agent response is not JSON, which requires a custom agent with resultType=context_injection. So a custom agent with resultType=context_injection and edit_messages=true, whose model echoes the attributed tracker block as bare content, bypasses the sanitizer and re-injects that block.

Steps to reproduce

  1. Configure a custom agent with settings.resultType = 'context_injection' and capabilities.edit_messages = true.
  2. Use it in a game/roleplay chat that has tracker snapshots.
  3. Have the model echo the <committed_tracker_state message_id="...">...</committed_tracker_state> block in its response.
  4. Observe the attributed block is not stripped and is injected into the main prompt.

Environment

  • Marinara Engine version: staging @ 3dc062e2
  • Install type: source
  • OS + version: n/a (static source audit)
  • Browser or app shell: n/a

Logs, screenshots, or video

Static source audit, cited to file:line above.

Additional context

Fix sketch: tolerate attributes on the opening tag — /<committed_tracker_state\b[^>]*>[\s\S]*?<\/committed_tracker_state\s*>/gi — and apply the same to the adjacent <assistant_response> strip on the next line.

Regression notes: not a regression — main's sanitizer (agent-executor.ts:1382) is the identical bare-tag-only regex, and the attribute-bearing emission is new to staging, so main never had the attributed form to leak. Low impact: the leaked content is the model's own read-only tracker JSON re-entering its prompt (continuity noise / token waste), not cross-user or secret data. Found via static audit.

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @Romuromylus on GitHub (Jun 19, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2641 Originally assigned to: @Romuromylus on GitHub. ## Summary **Severity: Low — leak (self-injection of tracker JSON into the main prompt).** `sanitizeTextAgentResponse` strips only the attribute-less `<committed_tracker_state>` tag, but `buildCommittedTrackerStateContext` now emits `<committed_tracker_state message_id="...">` when `includeMessageIds` is true. An echoed attributed block therefore survives sanitization and is injected back into the prompt. ## Expected behavior The sanitizer should strip the committed-tracker-state block regardless of attributes on the opening tag, so an echoed tracker block never re-enters the main prompt. ## Actual behavior `packages/server/src/services/agents/agent-executor.ts:1910`: ```ts .replace(/<committed_tracker_state>[\s\S]*?<\/committed_tracker_state>/gi, "") ``` This matches only the bare tag, while `buildCommittedTrackerStateContext` (1357–1359) emits `<committed_tracker_state${messageIdAttr}>` whenever `options.includeMessageIds` is true (set from `edit_messages === true`, line 1080). The text/sanitize path is taken only when the agent response is not JSON, which requires a custom agent with `resultType=context_injection`. So a custom agent with `resultType=context_injection` **and** `edit_messages=true`, whose model echoes the attributed tracker block as bare content, bypasses the sanitizer and re-injects that block. ## Steps to reproduce 1. Configure a custom agent with `settings.resultType = 'context_injection'` and `capabilities.edit_messages = true`. 2. Use it in a game/roleplay chat that has tracker snapshots. 3. Have the model echo the `<committed_tracker_state message_id="...">...</committed_tracker_state>` block in its response. 4. Observe the attributed block is not stripped and is injected into the main prompt. ## Environment - Marinara Engine version: `staging @ 3dc062e2` - Install type: source - OS + version: n/a (static source audit) - Browser or app shell: n/a ## Logs, screenshots, or video Static source audit, cited to file:line above. ## Additional context Fix sketch: tolerate attributes on the opening tag — `/<committed_tracker_state\b[^>]*>[\s\S]*?<\/committed_tracker_state\s*>/gi` — and apply the same to the adjacent `<assistant_response>` strip on the next line. Regression notes: not a regression — `main`'s sanitizer (`agent-executor.ts:1382`) is the identical bare-tag-only regex, and the attribute-bearing emission is new to staging, so `main` never had the attributed form to leak. Low impact: the leaked content is the model's own read-only tracker JSON re-entering its prompt (continuity noise / token waste), not cross-user or secret data. Found via static audit. ## Template check - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:31:08 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#1300
No description provided.