ci: flag invisible Unicode in changed files (tag characters, bidi controls, zero-width)
tsk-cjzsbyb57vsf Review Maity Coder Claude 006
Oliver decided on 2026-12-05 (req-me2yfy2v2x5m): add a CI check of our own, Python stdlib only, no third-party action.
Why: many agents read our PR diffs and repo files directly through git and GitHub. Invisible characters there can carry text a human reviewer does not see but a model reads. Examples: Unicode tag characters U+E0000–E007F ("ASCII smuggling"), bidi controls U+202A–202E and U+2066–2069 (Trojan Source), zero-width characters U+200B–200D, U+2060 and U+FEFF (a BOM at the start of a file is allowed), and variation selectors used to hide bytes. The hub already refuses such characters in names and short texts (docs/api.md §1.7.1, hub/src/maity_hub/plain_text.py), and the CLI shows them escaped in messages; files and diffs are the gap.
What:
- A script under tools/ that scans the files a PR changes (and can scan the whole tree) and fails with file:line:column and the code point.
- Allow valid emoji tag sequences (the flag sequences 🏴 + tags + U+E007F) and ZWJ/VS16 inside emoji sequences, as plain_text.py does.
- An allowlist for files that hold such characters on purpose (tests of plain_text and onboarding, docs/api.md examples). Keep it explicit and small.
- Wire it into ci.yml as its own job. Add tests.
- A sentence in the contributor docs on what it checks.
Done when: CI fails on a planted tag character in a changed file, passes on main, and the tests cover the flag-emoji exception.
Notes
Maity Coder Claude 006 · Dec 5, 2026, 17:39 UTC
Boundary: (for the first review, from the go request seq 282530, branch coder-006/invisible-unicode-check)
Guarantees:
- On a pull request, ci.yml's
invisible-unicodejob (in ci-ok) runstools/invisible_unicode.py --diff HEAD^1on the merge commit. It reads every changed file that is UTF-8 text with no NUL byte in its first 8 KiB, and it checks the name of every changed file. Deleted files are not read. On a push to main it runs--allover every tracked file. - It flags these characters:
- tag characters U+E0000-E007F;
- bidi controls U+202A-202E, U+2066-2069, U+200E, U+200F and U+061C;
- zero-width characters U+200B-200D, U+2060, U+180E and U+FEFF;
- all variation selectors: U+FE00-FE0F, U+E0100-E01EF, U+180B-180D and U+180F;
- control characters except tab, LF and CR;
- U+2028 and U+2029;
- the invisible fillers U+115F, U+1160, U+3164, U+FFA0, U+2800, U+034F, U+17B4 and U+17B5;
- every other format (Cf) character.
- It allows these, and nothing else:
- U+FEFF as the first character of a file;
- an emoji flag tag sequence: U+1F3F4, then tags that spell a subdivision id (two tag letters or three tag digits, then one to four tag letters or digits), then U+E007F. At most 7 hidden lower-case characters fit, and the sequence is drawn as a flag;
- U+200D and U+FE0F inside an emoji, by plain_text.py's rule for names. The tool loads that rule from the hub's file, so the two cannot drift;
- for each of the 24 files in the explicit allowlist
ALLOWED, exactly the code points listed for it. A test fails when an entry names a code point its file no longer holds, and another fails when any entry names a tag character.
Does not:
- read files it skips as binary or non-UTF-8. They are named on stderr and still pass; UTF-16 files have NUL bytes and are skipped this way;
- count occurrences in an allowlisted file, so more of an already-allowed code point passes;
- scan commit messages, pull request titles or bodies, or card texts;
- check that a subdivision id is a real CLDR region;
- use Unicode's Extended_Pictographic data. The emoji test is plain_text.py's approximation by Unicode block.
P3 (proposed): wording, the allowlist comments, and adding or dropping a fringe class such as the fillers or U+2028/2029.
- On a pull request, ci.yml's
Maity Test Team · Dec 6, 2026, 04:10 UTC
Tester result (maity-test-team), tsk-cjzsbyb57vsf, branch coder-006/invisible-unicode-check at d5ca3c6fea0880611d472b98f92b0bc99c617650. It is not on main yet, so I tested it locally with Python 3.13.5: PASS.
python3 -m unittest tools/test_invisible_unicode.py: 35 tests OK (15 s).tools/invisible_unicode.py --allon the branch tree: rc=0, 1816 files checked, none found. Two PNG fixtures were skipped as binary and named on stderr.--diff origin/main(the PR's own changes): rc=0, 126 files checked, none found.- Planted commit, then
--diff HEAD^1: rc=1 with file:line:col and the code point for each of these: - README.md: U+E0041 and U+E0042 (tag characters)
- a new file: U+202E (bidi control) and U+200B (zero-width inside a word)
- The same new file also held a valid subdivision flag tag sequence (U+1F3F4 g b s c t U+E007F) and a ZWJ emoji (man ZWJ woman). Neither was flagged, which matches the card's flag-emoji exception.
- Not run: the ci.yml job itself on GitHub Actions. That needs a CI run on the PR.