Skip to content

Neutralize </ctx-pack> sentinels in pack entry content - #3

Open
mgajda wants to merge 1 commit into
dchu917:mainfrom
mgajda:sentinel-guard
Open

Neutralize </ctx-pack> sentinels in pack entry content#3
mgajda wants to merge 1 commit into
dchu917:mainfrom
mgajda:sentinel-guard

Conversation

@mgajda

@mgajda mgajda commented Jun 22, 2026

Copy link
Copy Markdown

Problem

Entry content rendered into a context pack can contain a literal
</ctx-pack> (or <ctx-pack>). The resume skill wraps the whole pack in
<ctx-pack>…</ctx-pack>, so any entry whose content contains that literal tag
prematurely closes the wrapper — a consumer that splits on the literal
sentinel mis-parses everything after it. It's a delimiter-collision /
injection-style bug: untrusted data can break out of its enclosing tag.

Fix

cmd_pack now routes every entry preview through a new
_neutralize_pack_sentinels(), which inserts a zero-width space inside any
literal ctx-pack tag found in content. The tag no longer matches the literal
sentinel consumers scan for, while the rendered text stays visually
identical
.

Tests

tests/test_pack_sentinel_guard.py (stdlib unittest, same style as
tests/test_release_smoke.py — no new test dependency, same language as the
implementation):

  • closing/opening tags no longer match the literal sentinel
  • guarded text is visually identical once the ZWSP is stripped
  • benign text is untouched
  • multiple occurrences are all guarded

Verified the test fails when the guard is stubbed to a no-op (it genuinely
catches the regression) and passes with the fix.

Scope

One commit, two files (contextfun/cli.py + the new test). No other behaviour
changed. The 9 pre-existing failures in the suite (install/uninstall/docs/setup
tests) are present on main before this change and are unrelated.

Entry content rendered into a pack can contain a literal </ctx-pack> (or
<ctx-pack>). Because the resume skill wraps the pack in <ctx-pack>…</ctx-pack>,
such content prematurely closes the wrapper, so any consumer that splits on
the literal tag mis-parses everything after it.

cmd_pack now routes every entry preview through _neutralize_pack_sentinels(),
which inserts a zero-width space inside any literal ctx-pack tag found in
content. The tag no longer matches the literal sentinel consumers scan for,
while the text stays visually identical.

Adds tests/test_pack_sentinel_guard.py (stdlib unittest, same style as
test_release_smoke.py): closing/opening tags no longer match, guarded text is
visually identical once the ZWSP is stripped, benign text is untouched, and
multiple occurrences are all guarded.
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