[bug] The invisible-code-point scrub misses Default_Ignorable carriers (Mongolian FVS, Shorthand, Khmer inherent vowels)

Author: wgm66Created Sep 22, 2026Updated Sep 29, 2026
Labelsbughelp wanted

Problem

book_to_skill/sanitize.py::is_invisible_codepoint() (sanitize.py:121) is an enumerated blocklist organised by attack shape into eight commented groups. Group 1 already strips U+180E MONGOLIAN VOWEL SEPARATOR (sanitize.py:17) — but the free variation selectors in the same Mongolian block, and two further Default_Ignorable channels, are not in the list. They pass through extraction untouched, and because tools/scan_generated_skill.py imports the same predicate (scan_generated_skill.py:25, consumed by _is_invisible at 113 and the unicode.invisible finding at 241-251), the scanner does not flag them either.

That is the exact failure the module documents and exists to prevent (sanitize.py:124-126):

Exposed so the generated-skill scanner can flag exactly what extraction strips. When the two sets drift, the extractor lets a character through that the scanner then warns about — or worse, neither layer covers it.

The gap, measured

is_invisible_codepoint() returns False for nine assigned code points that are Default_Ignorable_Code_Point=Yes — the criterion PR #178 states this list is built on (sanitize.py:60-61, 106):

code point category Default_Ignorable currently stripped
U+180B MONGOLIAN FREE VARIATION SELECTOR ONE Mn Yes no
U+180C MONGOLIAN FREE VARIATION SELECTOR TWO Mn Yes no
U+180D MONGOLIAN FREE VARIATION SELECTOR THREE Mn Yes no
U+1BCA0 SHORTHAND FORMAT LETTER OVERLAP Cf Yes no
U+1BCA1 SHORTHAND FORMAT CONTINUING OVERLAP Cf Yes no
U+1BCA2 SHORTHAND FORMAT DOWN STEP Cf Yes no
U+1BCA3 SHORTHAND FORMAT UP STEP Cf Yes no
U+17B4 KHMER VOWEL INHERENT AQ Mn Yes no
U+17B5 KHMER VOWEL INHERENT AA Mn Yes no

(The neighbouring U+180E is stripped, which is what makes U+180B–U+180D a direct omission rather than a policy choice. Verified on Python 3.9.5 / Unicode 13.0.0; all nine are assigned there, so nothing here depends on a newer UCD.)

Why it matters

U+180B–U+180D are the same smuggling channel as the variation selectors this file already strips for exactly that reason (sanitize.py:88-101):

each selector carries one of 256 values, so a run of them after any base character encodes an arbitrary payload while rendering as nothing at all. They are combining marks rather than format controls, so a category-based filter that catches Cf misses them entirely.

The Mongolian free variation selectors are Mn, Default_Ignorable, and — like the selectors above — are applied in sequences after a base character to select a glyph variant, so a run of them is a channel for hidden data while rendering as nothing. They are a bypass of both layers today, not just one.

This list is complete, not just plausible

An exhaustive sweep of the whole assigned code space against the authoritative DerivedCoreProperties.txt / UnicodeData.txt for 13.0.0 (the UCD the Environment section names) — {assigned AND Default_Ignorable AND not stripped} — returns exactly these nine, with nothing else:

DI ranges parsed: 26 ; assigned codepoints: 283440
{assigned ∧ DI ∧ ¬stripped} = 9
  U+17B4 U+17B5 U+180B U+180C U+180D U+1BCA0 U+1BCA1 U+1BCA2 U+1BCA3
== the proposed nine : True      extra : []

So this is not "here are some code points you missed" — it is the complete set under the Default_Ignorable criterion, which is the criterion the file states it is built on. Adding all nine closes the Default_Ignorable half of the predicate.

The same sweep confirms the two neighbouring claims:

  • the seven code points in the scope note below are all Cf and not Default_Ignorable (verified against the same data), and
  • the four anti-over-stripping guards (U+180A, U+17B6, U+1BC9F, U+2800) are all not-DI and not-stripped today.

Proof it is a clean miss, not a partial catch

A generated skill whose only unusual feature is the carrier, after benign prose:

SKILL.md body: "# Notes\n\nStudy summary of the chapter.\nThe key idea is<U+13430>that practice beats theory.\n"
$ python3 tools/scan_generated_skill.py <skill-dir>
Generated-skill scan passed: no known injection or authority patterns found.
rc=0

sanitize_extracted_text() removed 0 code points, the carrier survived into the written SKILL.md, and the scanner reported passed — the unicode.invisible rule never fired. (I am deliberately not claiming the scanner is fully blind: it does have broad prose rules that catch a plain-English payload such as "ignore all previous instructions". The claim here is narrower and unambiguous — the invisible-carrier rule does not fire on these code points, in either layer.)

Proposed change

Add the nine code points above to sanitize.py, in the existing commented-group style. Because the predicate is shared, this hardens extraction and the scanner in one change — the same shape as #108, #178 and #182.

Preferred option (matches the scope below exactly): add the nine entries to the existing commented groups, in the file's current style —

  • the three Cf ones (U+1BCA0–U+1BCA3) into the format-control group, and
  • the five Mn + Default_Ignorable ones (U+180B–U+180D, U+17B4–U+17B5) as a new commented group, since stdlib exposes no Default_Ignorable property and they are combining marks rather than format controls.

Nine explicit values, no new dependency, and the predicate's behaviour changes for exactly the nine code points this issue is about.

Wider alternative, if you want it — the Cf half needs no table at all. Python's stdlib exposes the category:

python
if unicodedata.category(chr(codepoint)) == "Cf":
    return True

added after the existing explicit checks. That closes U+1BCA0–U+1BCA3 and every future assigned Cf with zero new dependencies — but it also takes the seven semantic code points listed below in the same stroke, so it is a scope decision, not a free win. That is why I am proposing the explicit nine first and offering this second.

Scope note — what I am deliberately NOT proposing. Seven further Cf code points are also unstripped but should be a separate decision, and I have left them out on purpose:

  • U+0600 ARABIC NUMBER SIGN, U+06DD ARABIC END OF AYAH, U+08E2 ARABIC DISPUTED END OF AYAH, U+110BD KAITHI NUMBER SIGN, U+110CD KAITHI NUMBER SIGN ABOVE — all Cf but not Default_Ignorable, and all Prepended_Concatenation_Mark: they carry semantic meaning in the text. Stripping them would be the U+2800 BRAILLE PATTERN BLANK mistake #178 explicitly avoided.
  • U+13430/U+13431 EGYPTIAN HIEROGLYPH VERTICAL/HORIZONTAL JOINER — Cf but not Default_Ignorable; they affect hieroglyph layout rather than being pure spacers.

This is not my judgement call — DerivedCoreProperties.txt (13.0.0) subtracts both groups from Default_Ignorable_Code_Point explicitly, and says why:

#  Derived Property: Default_Ignorable_Code_Point
#  Generated from
#    Other_Default_Ignorable_Code_Point
#  + Cf (Format characters)
#  + Variation_Selector
#  - White_Space
#  - FFF9..FFFB (Interlinear annotation format characters)
#  - 13430..13438 (Egyptian hieroglyph format characters)
#  - Prepended_Concatenation_Mark (Exceptional format characters that should be visible)

"Exceptional format characters that should be visible" is the same reason #178 kept U+2800. So the split above follows the Unicode property itself, not a preference.

If you would rather take those too, the unicodedata.category(...) == "Cf" alternative above takes all seven at once; I have kept them out of the primary recommendation so the nine Default_Ignorable ones can land independently of that call.

How would we know it's better?

Binary before/after, no new dependency:

python
CARRIERS = (0x180B, 0x180C, 0x180D, 0x1BCA0, 0x1BCA1, 0x1BCA2, 0x1BCA3, 0x17B4, 0x17B5)

# Before (526f362)
for cp in CARRIERS:
    assert is_invisible_codepoint(cp) is False
    assert sanitize_extracted_text("a" + chr(cp) + "b") == ("a" + chr(cp) + "b", 0)

# After
for cp in CARRIERS:
    assert is_invisible_codepoint(cp) is True
    assert sanitize_extracted_text("a" + chr(cp) + "b") == ("ab", 1)

and the scanner agrees, on benign text:

scanner on "Study summary.<U+180B>Notes here."  ->  rc=1, rule "unicode.invisible"

Guards against over-stripping (these must stay False):

U+180A MONGOLIAN NIRUGU (visible punctuation)
U+17B6 KHMER VOWEL SIGN AA (visible vowel)
U+1BC9F DUPLOYAN PUNCTUATION CHINOOK FULL STOP (visible)
U+2800 BRAILLE PATTERN BLANK (semantic — #178 kept it deliberately)

Tests: tests/test_sanitize_bidi_controls.py already contains the agreement tests (test_scanner_flags_everything_extraction_strips, test_scanner_shares_the_extractor_predicate) and the "carriers a Cf filter does not reach" class — extend those tables, do not add a parallel test file. Four focused cases: the nine carriers stripped; the scanner flags them; the four visible neighbours kept; the Arabic/Kaithi number signs documented as deliberately preserved.

  • No regression expected: the change only adds code points to an existing blocklist predicate; pytest tests/ -q on Linux (py3.9.5) is 679 passed, 1 skipped at 526f362, and I will re-run it against the candidate patch.

Alternatives considered

  • Leave it — "an enumeration is never complete." True, and it is the honest weakness of this file. The response in this repo has been to keep closing the channels (#75 → #85 → #108 → #178 → #182), so this is a continuation of an accepted series, not a new policy. The durable part of the proposal is the Cf-by-property line, which stops the Cf half from ever being incomplete again.
  • Strip every Cf. Closes all 16 findings at once but also removes bidirectional controls and the Arabic/Kaithi number signs wholesale. The bidi controls are already handled explicitly (group 2, for a stated rendering reason), and the number signs are semantic — so a blanket Cf rule belongs only as an addition under the existing groups, which is why option 1 above adds it after the explicit checks rather than replacing them.
  • Default_Ignorable by embedded table. Stdlib has no such property; a table would be a new maintained artifact. The nine-value list is smaller than the table and matches the file's current style.
  • Fix only the scanner. The scanner imports the extractor predicate by design so the two cannot drift; fixing the scanner alone would break that invariant.

Environment

  • upstream/master 526f362552562d88c1a8bbf8012d2cee93f831d5 (v1.4.0). sanitize.py pinned via git cat-file blob (sha256 of the blob verified against a clean Linux checkout).
  • Ubuntu 20.04.6 LTS, Python 3.9.5, Unicode 13.0.0 data; pytest 8.4.2, ruff 0.16.8.
  • No optional extractors involved; the reproduction is the stdlib sanitizer and the stdlib-only scanner.
  • Prior art in this exact class: #75, #85, #108, #178, #182 — all merged, all touching this predicate.

Source: virgiliojr94/book-to-skill