Bad Characters: Imperceptible NLP Attacks

Nicholas Boucher, Ilia Shumailov, Ross Anderson, Nicolas Papernot

This paper, presented at the 43rd IEEE Symposium on Security and Privacy, introduces a stealthy new class of adversarial attacks on Natural Language Processing (NLP) systems. While previous NLP attacks relied on visible changes like typos or synonym swaps, "Bad Characters" exploits the fundamental gap between how humans perceive text (as visual glyphs) and how computers process it (as encoded bytes).

TL;DR

Researchers have uncovered a way to "break" major NLP systems—including Google Translate and Microsoft Azure—using Unicode perturbations that are completely invisible to the human eye. By injecting invisible characters or swapping letters for identical-looking "homoglyphs," attackers can flip a model's output or bypass toxicity filters without changing the text's visual appearance.

What Problem Does This Paper Address?

In the world of computer vision, "adversarial examples" (like adding invisible noise to a photo of a stop sign to make a car see a speed limit sign) are well-documented. In NLP, however, creating "imperceptible" attacks is much harder because text is discrete. If you change a letter, a human usually notices the typo.

The authors address the "semantic gap" between the rendering engine (which draws text for humans) and the NLP pipeline (which tokenizes text for the machine). Because modern NLP models are often "agnostic" to characters outside their specific dictionary, an attacker can exploit Unicode features to feed the machine "garbage" that looks like perfectly clean text to a human reader.

Methods

The authors categorize their "Bad Characters" into four types of perturbations:

  1. Invisible Characters: Using non-rendering characters like the Zero-Width Space (U+200B) to break words apart in the eyes of the tokenizer.
  2. Homoglyphs: Swapping a character for one that looks identical but has a different encoding (e.g., the Latin 'a' vs. the Cyrillic 'а').
  3. Reorderings: Exploiting the "Bidi" (Bidirectional) algorithm. By using control characters, an attacker can store text in the byte stream in a scrambled order that the rendering engine then "unscrambles" for the display.
  4. Deletions: Injecting control characters like "backspace" (U+0008) that remove preceding characters during rendering but remain present in the raw data processed by the model.

To find the most effective "injection points," the authors use Differential Evolution, a gradient-free genetic algorithm. This allows them to mount "black-box" attacks, meaning they don't need to know the internal weights of the target model to succeed.

Datasets

The researchers evaluated their attacks against a wide array of tasks and models:

  • Machine Translation: Evaluated on the WMT14 English-French dataset using Facebook’s Fairseq, Google Translate, and Microsoft Azure.
  • Toxic Content Detection: Tested on the Wikipedia Detox Dataset using IBM’s Toxic Content Classifier and Google’s Perspective API.
  • Other Tasks: Evaluation also included the MNLI (Textual Entailment), CoNLL-2003 (Named Entity Recognition), and the Emotion dataset (Sentiment Analysis).

Key Insights and Ideas

  • The Tokenizer is the Weak Link: Most NLP models use sub-word tokenization (like BPE). Injecting an invisible character in the middle of a word forces the tokenizer to split a known word into multiple "unknown" or rare tokens, effectively blinding the model to the word's meaning.
  • Bidi is a "Super-Power" for Attackers: Reordering attacks are particularly devastating because they don't just confuse the model with unknown tokens; they provide a completely scrambled sequence that still looks perfect to a human.
  • Search Engine "Ghosting": The authors found that production search engines (like Google) often fail to index text containing these characters. An attacker could hide malicious content "in plain sight" from search crawlers while keeping it readable for users.
  • OCR as a Shield: The most interesting defense proposed is an Optical Character Recognition (OCR) pipeline. By rendering the input text to an image and then "reading" it back, the system can see exactly what the human sees, effectively stripping away all invisible encoding tricks.

Key Results

  • Translation Failure: On the Fairseq EN-FR model, the BLEU score (a measure of translation quality) plummeted from 35.0 to near 0 with just five injections.
  • Bypassing Toxicity Filters: Homoglyph and reordering attacks reduced the detection of toxic sentences by up to 75% in IBM and Google systems.
  • Commercial Vulnerability: Both Google Translate and Microsoft Azure were found to be highly susceptible, proving these aren't just theoretical academic weaknesses.
  • Defense Efficacy: The proposed OCR defense was 100% effective against invisible characters, reorderings, and deletions, though it did result in a minor (6.2%) drop in baseline performance due to OCR imperfections.

Limitations and Future Work

The authors acknowledge that the OCR defense, while robust, is computationally expensive and might not be suitable for high-latency applications. Furthermore, some "invisible" characters are font-dependent; on older systems, they might appear as "tofu" (empty boxes), potentially alerting a very observant user.

Future work involves developing more efficient "sanitization" layers that can strip these characters at the architectural level without the overhead of full image rendering. The paper serves as an urgent call for NLP architects to treat text input with the same level of suspicion as a SQL query or a shell command.

Summary updated

BibTeX
@inproceedings{boucher2022bad,
  author = {Nicholas Boucher and Ilia Shumailov and Ross Anderson and Nicolas Papernot},
  title = {{Bad Characters: Imperceptible NLP Attacks}},
  booktitle = {IEEE Symposium on Security and Privacy},
  year = {2022},
  url = {https://openreview.net/forum?id=vskJD-LhlN},
}
Figure