Token-Level Fuzzing

Christopher Salls, Chani Jindal, Jake Corina, Christopher Kruegel, Giovanni VignaarXiv 2023 · DOI

Introduction

Effectively fuzzing an interpreter presents a unique challenge in software security. Traditional methods often fall into two extremes: the chaotic, syntax-blind mutations of byte-level fuzzers or the rigid, grammar-constrained generation of grammar-based tools. This paper introduces Token-Level Fuzzing, a compelling "middle-ground" approach. By mutating code at the level of individual tokens—such as keywords, operators, and variable names—this technique bypasses simple syntax errors while remaining flexible enough to generate the "weird," non-conformant inputs necessary to break complex parsers and JIT compilers.

The Challenge of Interpreter Fuzzing

Fuzzing interpreters for languages like JavaScript is notoriously difficult. Byte-level fuzzers (e.g., AFL) are "dumb" in that they flip bits randomly. When applied to structured code, they mostly produce gibberish (e.g., changing while to whkle), which is immediately rejected by the parser.

Conversely, grammar-based fuzzers (e.g., Fuzzilli) ensure every input is syntactically correct. While this allows for deep exploration of engine logic, it creates a significant blind spot: it cannot generate the "syntactically incorrect but interesting" inputs that trigger bugs in the parser itself or in the handling of unusual edge cases. Furthermore, these tools are difficult to maintain as they require a complete, up-to-date specification of the target language.

Token-Level AFL: The Methodology

The authors propose Token-Level AFL, which operates on sequences of tokens rather than raw bytes. This approach allows the fuzzer to explore the "parse rate" sweet spot—high enough to reach deep code paths, but low enough to stress-test the parser with invalid sequences.

High-level architecture of the Token-Level Fuzzing pipeline.

The pipeline consists of several key stages:

  1. Pre-parsing: Input "seeds" (existing JavaScript files) are broken down into tokens using a standard lexer.
  2. Normalization: To focus the search space on structural logic, variable names are mapped to a small set of predefined names (e.g., var1, var2), and literal numbers are rounded to the nearest power of two.
  3. Encoding: Each unique token is mapped to a 16-bit integer, allowing the fuzzer to treat the program as an array of "shorts."
  4. Token-Level Mutation: The AFL engine is modified to perform standard mutations (bit flips, deletions, insertions) on these 16-bit token IDs. This ensures that every mutation results in a valid token from the language's vocabulary, even if the resulting sequence is grammatically "illegal" (e.g., while (while . x)).
  5. Decoding: Before execution in the target engine, the 16-bit IDs are translated back into a JavaScript string.
Detailed view of the pre-parsing and fuzzing loop, illustrating token normalization and mutation.

Evaluation and Results

The tool was evaluated against four major JavaScript engines: V8 (Chrome), SpiderMonkey (Firefox), JavaScriptCore (Safari), and ChakraCore (Edge). Using a small set of 100 regression tests as seeds, Token-Level AFL was compared against state-of-the-art baselines including AFL, Fuzzilli, CodeAlchemist, and Superion.

Key Findings

  • Bug Discovery: Token-Level AFL uncovered 29 previously unknown bugs. Several were high-severity, including a memory corruption bug in V8 that allowed for Remote Code Execution (RCE). The findings resulted in over $10,000 in bug bounties.
  • Efficiency: In a 3-day head-to-head trial, Token-Level AFL found 19 unique bugs, significantly outperforming the next best tool, CodeAlchemist, which found 8.
  • Unique Coverage: 15 of the bugs found were unique to the token-level approach, demonstrating its ability to explore territory that grammar-based or byte-level fuzzers cannot reach.
  • Parse Rate: While byte-level AFL has a successful parse rate of ~10% and grammar-based fuzzers are near 100%, Token-Level AFL hits a "sweet spot" at ~30%.

Conclusion and Future Work

Token-Level Fuzzing proves that grammar-agnosticism can be a feature rather than a limitation. By operating at the token level, the fuzzer avoids the bias of a strict grammar, allowing it to find bugs in the parser's own implementation.

Future improvements could include reducing seed sensitivity, as the tool's performance currently depends on the tokens present in the initial input. The authors also suggest integrating path-sensitive techniques to improve coverage tracking and exploring "ensemble fuzzing," where token-level and grammar-based fuzzers run side-by-side to cover each other's blind spots.

Summary updated

BibTeX
@misc{salls2023token,
  author = {Christopher Salls and Chani Jindal and Jake Corina and Christopher Kruegel and Giovanni Vigna},
  title = {{Token-Level Fuzzing}},
  year = {2023},
  eprint = {2304.02103},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2304.02103},
}
Figure