Skip to main content

Crate rtl_flip_detect

Crate rtl_flip_detect 

Source
Expand description

§rtl-flip-detect

Detect bidi-control characters that flip rendered direction.

The classic attack: a filename evil\u{202E}cod.exe renders as evilexe.doc because U+202E (RIGHT-TO-LEFT OVERRIDE) flips everything after it. Same trick works inside any text the model displays back, or a tool argument.

This crate finds and strips those.

Controls flagged:

  • U+202A LRE, U+202B RLE, U+202D LRO, U+202E RLO
  • U+202C PDF (pop directional formatting — could close an attacker’s open)
  • U+2066 LRI, U+2067 RLI, U+2068 FSI, U+2069 PDI

§Example

use rtl_flip_detect::{has_rtl_flip, strip_rtl_flips};
let evil = "evil\u{202E}cod.exe";
assert!(has_rtl_flip(evil));
assert_eq!(strip_rtl_flips(evil), "evilcod.exe");

Functions§

find_rtl_flips
Return the byte positions of every bidi-control char in s.
has_rtl_flip
True when the input contains any bidi-control char that could flip direction.
strip_rtl_flips
Strip every bidi-control char from s.