Linear Matching of JavaScript Regular Expressions
摘要
Modern regex languages have strayed far from well-understood traditional regular expressions: they include features that fundamentally transform the matching problem. In exchange for these features, modern regex engines at times suffer from exponential complexity blowups, a frequent source of denial-of-service vulnerabilities in JavaScript applications. Worse, regex semantics differ across languages, and the impact of these divergences on algorithmic design and worst-case matching complexity has seldom been investigated.
This paper provides a novel perspective on JavaScript's regex semantics by identifying a larger-thanpreviously-understood subset of the language that can be matched with linear time guarantees. In the process, we discover several cases where state-of-the-art algorithms were either wrong (semantically incorrect), inefficient (suffering from superlinear complexity) or excessively restrictive (assuming certain features could not be matched linearly). We introduce novel algorithms to restore correctness and linear complexity. We further advance the state-of-the-art in linear regex matching by presenting the first nonbacktracking algorithms for matching lookarounds in linear time: one supporting captureless lookbehinds in any regex language, and another leveraging a JavaScript property to support unrestricted lookaheads and lookbehinds. Finally, we describe new time and space complexity tradeoffs for regex engines. All of our algorithms are practical: we validated them in a prototype implementation, and some have also been merged in the V8 JavaScript implementation used in Chrome and Node.js.
问 Lune
几分钟读透这篇 Paper,不用再花一下午。
Lune 能读完全文,也能读引用它的顶会 Paper,讲清它的结论、证据和局限,每一点都注明出自哪篇 Paper。不用硬啃,也不靠猜。
已有 5 篇顶会 Paper 引用了它。别等审稿人问起,先弄清它们发现了什么。
脉络
- Towards Efficient Matching of Regexes with Backreferences using Register Set Automata 引用了 RE#: High Performance Derivative-Based Regex Matching with Intersection, Complement, and Restricted Lookarounds
- Towards Efficient Matching of Regexes with Backreferences using Register Set Automata 引用了 Regex matching with counting-set automata
- Towards Efficient Matching of Regexes with Backreferences using Register Set Automata 引用了 Revealer: Detecting and Exploiting Regular Expression Denial-of-Service Vulnerabilities
- Efficient Algorithms for the Uniform Tokenization Problem 引用了 Regular Expression Matching using Bit Vector Automata
- RE#: High Performance Derivative-Based Regex Matching with Intersection, Complement, and Restricted Lookarounds 引用了 Regex matching with counting-set automata
- RE#: High Performance Derivative-Based Regex Matching with Intersection, Complement, and Restricted Lookarounds 引用了 Regular Expression Matching using Bit Vector Automata
- Regex Decision Procedures in Extended RE# 引用了 RE#: High Performance Derivative-Based Regex Matching with Intersection, Complement, and Restricted Lookarounds
- Revealer: Detecting and Exploiting Regular Expression Denial-of-Service Vulnerabilities 引用了 Freezing the Web: A Study of ReDoS Vulnerabilities in JavaScript-based Web Servers
- Regular Expression Matching using Bit Vector Automata 引用了 Regex matching with counting-set automata
- Formal Verification for JavaScript Regular Expressions: A Proven Mechanized Semantics and Its Applications 引用了 RE#: High Performance Derivative-Based Regex Matching with Intersection, Complement, and Restricted Lookarounds
- Formal Verification for JavaScript Regular Expressions: A Proven Mechanized Semantics and Its Applications 引用了 Freezing the Web: A Study of ReDoS Vulnerabilities in JavaScript-based Web Servers
引用它的顶会 Paper5
- RE#: High Performance Derivative-Based Regex Matching with Intersection, Complement, and Restricted LookaroundsIan Erik Varatalu, Margus Veanes, Juhan P. ErnitsPOPL 2025 · 9 次引用
- Efficient Algorithms for the Uniform Tokenization ProblemAngela W. Li, Konstantinos MamourasOOPSLA 2025 · 3 次引用
- Regex Decision Procedures in Extended RE#Ian Erik Varatalu, Margus Veanes, Ekaterina Zhuchko, Juhan P. ErnitsCAV 2025 · 3 次引用
- Towards Efficient Matching of Regexes with Backreferences using Register Set AutomataVojtech Havlena, Lukás Holík, Ondrej Lengál, Jan Vasák 等PLDI 2026
- Formal Verification for JavaScript Regular Expressions: A Proven Mechanized Semantics and Its ApplicationsAurèle Barrière, Victor Deng, Clément Pit-ClaudelPOPL 2026
它引用的 Paper9
- Freezing the Web: A Study of ReDoS Vulnerabilities in JavaScript-based Web ServersCristian-Alexandru Staicu, Michael PradelUSENIX Security 2018 · 125 次引用
- Using Selective Memoization to Defeat Regular Expression Denial of Service (ReDoS)James C. Davis, Francisco Servant, Dongyoon LeeS&P 2021 · 43 次引用
- Revealer: Detecting and Exploiting Regular Expression Denial-of-Service VulnerabilitiesYinxi Liu, Mingxue Zhang, Wei MengS&P 2021 · 28 次引用
- Regex matching with counting-set automataLenka Turonová, Lukás Holík, Ondrej Lengál, Olli Saarikivi 等OOPSLA 2020 · 22 次引用
- Regular Expression Matching using Bit Vector AutomataAlexis Le Glaunec, Lingkun Kong, Konstantinos MamourasOOPSLA 2023 · 22 次引用
相关 Paper
- Efficient Matching of Regular Expressions with Lookaround AssertionsKonstantinos Mamouras, Agnishom ChattopadhyayPOPL 2024 · 19 次引用
- Repairing DoS Vulnerability of Real-World RegexesNariyoshi Chida, Tachio TerauchiS&P 2022 · 15 次引用
- Exploring Motif-based Heterogeneous Graph Learning for ReDoS DetectionHong Huang, Chengyu Yao, Rongchen Li, Weihao Su 等ICML 2026
- ReDoSHunter: A Combined Static and Dynamic Approach for Regular Expression DoS DetectionYeting Li, Zixuan Chen, Jialun Cao, Zhiwu Xu 等USENIX Security 2021 · 20 次引用
- Regulator: Dynamic Analysis to Detect ReDoSRobert McLaughlin, Fabio Pagani, Noah Spahn, Christopher Kruegel 等USENIX Security 2022
