
Detects Trojan Source bidi-override and zero-width control characters in source text, pinpointing offending codepoints while accepting legitimate non-ASCII, with a CI-proven two-way test.
Hidden bidi / invisible control characters detected — a Trojan Source attack proven caught both ways in CI.
"Trojan Source" (CVE-2021-42574)
hides logic in plain sight: Unicode bidirectional overrides (U+202A–U+202E,
U+2066–U+2069) reorder how a line is displayed without changing its logical
bytes, so a reviewer sees if access == "user" while the compiler runs something
else; zero-width characters smuggle differences into identifiers and URLs.
All these codepoints are ≥ U+0020, so a naive "no ASCII control characters" check
passes them. reveal shows that gap, then shows a dangerous-set scan catching the
attack — on every push.
is_clean_ascii_only_unsafe('access_level = "user" };) nimda( fi') ─► True → MISSED (the risk)
is_clean_safe( same line) ─► False → CAUGHT
find_dangerous( same line) ─► [(21, "U+202E", "RIGHT-TO-LEFT OVERRIDE")]
is_clean_safe("administrator") ─► False (zero-width space) → CAUGHT
is_clean_safe("café déjà vu — façade") ─► True (legit non-ASCII) → OK
is_clean_safe(text) — returns False if the text contains any character
in DANGEROUS (bidi embeddings/overrides/isolates and common zero-width
formatting characters).find_dangerous(text) — reports each hit as (index, "U+XXXX", name) so a
linter can point at the exact offending codepoint.is_clean_ascii_only_unsafe — the insufficient check (ASCII control chars
only), included only to demonstrate that it misses the attack.Requires Docker.
bash tests/run_bidi.sh
Expected tail:
reveal trojan source: 10 passed, 0 failed
reveal.py is_clean_safe (dangerous-set scan) + find_dangerous + is_clean_ascii_only_unsafe (the demo)
tests/test_reveal.py the two-way proof (bidi override + zero-width pass the naive check, then caught; benign accepted)
tests/run_bidi.sh runs it in a pinned Python image
.github/workflows/ CI: the Trojan-Source proof + shellcheck
café is fine and a hidden
U+202E is not.glyph Unicode-normalization repo);
together they cover visual spoofing and hidden reordering.is_clean_ascii_only_unsafe is a teaching device — it must not be your only
gate.MIT — see LICENSE.

Open-source XDR and SIEM platform for threat detection, log analysis, file integrity monitoring, vulnerability assessment, and compliance management across endpoints and cloud workloads.

Open-source network IDS/IPS/NSM engine for real-time traffic inspection, intrusion detection and prevention, protocol analysis, and rule-based threat hunting.

Zeek is a powerful network analysis framework that is much different from the typical IDS you may know.