Neutralize </ctx-pack> sentinels in pack entry content - #3
Open
mgajda wants to merge 1 commit into
Open
Conversation
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.
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
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 tagprematurely 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_packnow routes every entry preview through a new_neutralize_pack_sentinels(), which inserts a zero-width space inside anyliteral
ctx-packtag found in content. The tag no longer matches the literalsentinel consumers scan for, while the rendered text stays visually
identical.
Tests
tests/test_pack_sentinel_guard.py(stdlibunittest, same style astests/test_release_smoke.py— no new test dependency, same language as theimplementation):
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 behaviourchanged. The 9 pre-existing failures in the suite (install/uninstall/docs/setup
tests) are present on
mainbefore this change and are unrelated.