Skip to content

feat(agent-core): harden sendAgentMessage (sanitize sender label, dedup targets) - #455

Merged
WinterYukky merged 1 commit into
aws-samples:mainfrom
WinterYukky:feature/harden-agent-messaging-1787632796
Aug 25, 2026
Merged

feat(agent-core): harden sendAgentMessage (sanitize sender label, dedup targets)#455
WinterYukky merged 1 commit into
aws-samples:mainfrom
WinterYukky:feature/harden-agent-messaging-1787632796

Conversation

@WinterYukky

Copy link
Copy Markdown
Contributor

Summary

Hardens sendAgentMessage with two small, self-contained safety improvements.

Motivation

The inline [Message from <name> (<id>)]: prefix that wraps an agent-to-agent
message is fed into the recipient LLM's prompt. A stray newline or bracket in the
sender label could break out of that envelope (prompt injection). Separately, a
caller passing the same target session id more than once would deliver to — and
wake — that target multiple times.

Changes

  • Sanitize the sender name and worker id embedded in the inline prefix via
    sanitizeSenderLabel (already used elsewhere in prompt.ts), falling back to
    agent / unknown when sanitisation empties the value.
  • De-duplicate targetSessionIds ([...new Set(...)]) so each unique target is
    delivered to / woken exactly once.
  • Add focused unit tests for both behaviours (no prior test existed for this module).

Testing

  • npm run build -w packages/agent-core (tsc) — pass
  • vitest run new tests — 3 passed
  • full agent-core suite — 271 passed
  • prettier format:check (agent-core) — pass

Notes

  • sanitizeSenderLabel already exists upstream in prompt.ts (its JSDoc even
    references sendAgentMessage); this wires it into the previously-unsanitised
    call site.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

…up targets)

- Sanitize the sender name and worker id embedded in the inline
  '[Message from <name> (<id>)]:' prefix via sanitizeSenderLabel, as
  defense in depth against prompt injection through the agent message
  envelope (a stray newline or bracket could otherwise break out of the
  prefix). Falls back to 'agent' / 'unknown' when sanitisation empties
  the value.
- De-duplicate targetSessionIds so a caller passing the same session id
  more than once delivers to (and wakes) each target only once.
- Add focused unit tests for both behaviours (no prior test existed for
  this module).
@WinterYukky
WinterYukky merged commit 027294b into aws-samples:main Aug 25, 2026
8 checks passed
@remote-swe
remote-swe Bot deleted the feature/harden-agent-messaging-1787632796 branch August 25, 2026 06:54
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