no_bidi_controls
Flag Trojan-Source bidi override characters (U+202A to U+202E, U+2066 to U+2069). Defense against CVE-2021-42574.
A text file with stray invalid UTF-8 is still scanned, so a junk byte cannot hide a control. A binary-looking file (for example one with a NUL byte) is scanned when it is valid UTF-8, so a NUL byte cannot hide a control in a crafted source file either; a binary-looking file that is not valid UTF-8 (images, fonts, archives) is skipped, which keeps paths: "**/*" free of false positives from random binary bytes. A finding in a binary-looking file is reported but not auto-fixed (file_strip_bidi refuses to edit binary content).
Options
Section titled "Options"This rule takes no kind-specific options.
Plus the common paths, level, id, when, scope_filter, fix, and expect_matches fields. This table is generated from the JSON Schema; option types and defaults are authoritative.
Example
Section titled "Example"A source file with a Trojan Source bidi override
Section titled "A source file with a Trojan Source bidi override"The rule fires on this repository:
- src/
- src/clean.rs✓
- src/sneaky.rs
✗ error no-bidi
1:16 Unicode bidi control U+202E at line 1 col 16 (Trojan-Source defense)
pub fn ok() {}let comment = "<U+202E>gnitcepsnI ydobon emah sih";With this .alint.yml:
version: 1rules: - id: no-bidi kind: no_bidi_controls paths: "src/**/*.rs" level: erroralint check reports:
--- src/sneaky.rs -------------------------------------------------------------- x error no-bidi 1:16 Unicode bidi control U+202E at line 1 col 16 (Trojan-Source defense)
Summary (1 violation): x 1 error 0 passing * 1 failingSource files with ordinary emoji and no bidi controls
Section titled "Source files with ordinary emoji and no bidi controls"This repository is compliant:
- src/
- src/ascii.rs✓
- src/unicode.rs✓
pub fn ok() {}// A ☃ comment with emoji 🦀pub fn fine() {}With this .alint.yml:
version: 1rules: - id: no-bidi kind: no_bidi_controls paths: "src/**/*.rs" level: erroralint check reports:
v All 1 rule(s) passed.