GHSL-2020-306: Regular Expression Denial of Service in highlight.js
Originally disclosed on GitHub Security Lab
The project contains one or more regular expressions that are vulnerable to ReDoS (Regular Expression Denial of Service)
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
highlight.js is a syntax highlighting library. It takes a block of source code and a language name, and returns HTML in which the tokens of that language (keywords, strings, comments, numbers) are wrapped in markup so that a page can colour them. The library ships grammars for many languages, and each grammar is a set of rules describing how the pieces of that language look.
The report concerns one part of a grammar: the begin regular expression. In highlight.js a grammar rule is built around a regular expression that marks where a construct begins, and the engine uses that expression to walk through the input and decide what each stretch of text is. The begin expression is therefore applied to the code being highlighted, character by character, as the highlighter scans the input.
That matters because the input is often not trusted. highlight.js can be used both client-side and server-side. In the browser it may highlight code that a user pasted or that arrived from another source; on a server it may be called to render code snippets in a page, a documentation site, a paste service or an editor backend. In both cases the text handed to the highlighter can be controlled by someone other than the operator, and the highlighter will run its grammar regular expressions over that text.
The vulnerability in this report is not in the highlighting logic as such but in the construction of one of those grammar regular expressions. A regular expression that is ambiguous, where two parts of the pattern can match the same characters in more than one way, can be driven into exponential backtracking by a carefully built input string. The result is that a single call to highlight a short piece of code can take an extremely long time, which is the denial of service condition the report describes. The specific grammar involved is the one for the r programming language.
Setup
The version tested was the latest commit at the time of reporting, November 30, 2020. No specific release tag is named; the finding applies to the code as it stood on that commit.
The issue was found with a CodeQL query, specifically the one that identifies begin regular expressions vulnerable to ReDoS. The report links to the query description at https://codeql.github.com/codeql-query-help/javascript/js-redos/. The query flagged the begin regular expression of the r grammar as vulnerable, which is where the investigation started.
Reproducing the proof of concept needs Node.js and a local install of the library. The report gives the install command as:
npm install highlight.js
The PoC then loads the library from its package paths rather than the bundled build: highlight.js/lib/core for the engine and highlight.js/lib/languages/r for the r grammar, which is registered explicitly before highlighting. Nothing else is required: no account, no server, no configuration. The precondition for the attack is simply that untrusted text reaches hljs.highlight with the r language selected.
Finding it
The entry point was the CodeQL query for ReDoS in JavaScript, js-redos. Running it over the highlight.js codebase flagged the begin regular expression of the r grammar as vulnerable. From that flag, the rest of the report is an explanation of the class of bug and a proof that the flagged expression can actually be driven into pathological behaviour.
What ReDoS is
ReDoS, or Regular Expression Denial of Service, is a vulnerability affecting poorly constructed and potentially inefficient regular expressions which can make them perform extremely badly given a creatively constructed input string.
For the specific regular expression reported, it is possible to force it to work with an O(2^n) runtime performance when there is exponential backtracking. The cause is ambiguity or overlap between some regex clauses. Such badly performing regular expressions become a security issue when a user can control the input: if the project is an input validation library, for example, a server could use it to validate untrusted user input, and the attacker then chooses the string that triggers the worst case.
There is no one size fits all when it comes to fixing ReDoS. In general it is about removing ambiguity or overlap inside the regular expression. Before showing the vulnerable expression, the report walks through three examples of the pattern and its repair.
Teaching example: HTML comment regex
var reg = /<!--(.|\s)*?-->/g;
The expression matches the start of an HTML comment, followed by any characters, followed by the end of an HTML comment. The dot (.) matches any character except newlines, and \s matches any whitespace. Both . and \s match whitespace such as the space character, so there are many possible ways for the expression to match a sequence of spaces. This becomes a problem if the input is a string that starts with <!-- followed by a long sequence of spaces, because the regex evaluator will try every possible way of matching the spaces. The report points to a regex101 debugging session showing the blow-up: https://regex101.com/r/XvYgkN/1/debugger.
The fix removes the ambiguity by making the two alternatives disjoint, so that no character can be consumed by both:
var reg = /<!--(.|\r|\n)*?-->/g;
Teaching example: snake_case regex
var reg = /(\w+_?)+_(\d+)/;
This one matches a snake_case identifier that ends with some digits. For a string starting with lots of letters there are many ways for the expression to match those letters, because the regex has a repetition matching letters (\w+) inside another repetition that can match letters ((\w+_?)+). The evaluator will try every possible grouping of letters into smaller groups of letters; the report again links a debugging session, https://regex101.com/r/fmci1j/1/debugger.
The fix removes the ambiguity by changing the inner repetition so that each of its iterations must end with an underscore, which forces a unique way to split the input:
var reg = /(\w+_)+(\d+)/;
Teaching example: VS Code link pattern
Real expressions are often not as simple as the two above. The report takes an expression that used to be part of VS Code, with the vulnerable version on top and the fixed version below:
var linkPattern = /(\[((!\[[^\]]*?\]\(\s*)([^\s\(\)]+?)\s*\)\]|(?:\\\]|[^\]])*\])\(\s*)(([^\s\(\)]|\(\S*?\))+)\s*(".*?")?\)/g;
var linkPattern = /(\[((!\[[^\]]*?\]\(\s*)([^\s\(\)]+?)\s*\)\]|(?:\\\]|[^\]])*\])\(\s*)(([^\s\(\)]|\([^\s\(\)]*?\))+)\s*(".*?")?\)/g;
Despite its size, the example is very similar to the first one. A section of the expression that was too general (\S) was changed to something a bit more specific ([^\s\(\)]) to remove overlap with another part of the expression. The lesson carries over directly: the dangerous part is a subexpression that can match characters another subexpression also matches, inside a repetition.
The flagged highlight.js regex
The CodeQL query identified the begin regular expression of the r grammar as vulnerable. The report does not print that expression; it moves straight from the query result to a proof of concept that exercises it through the public API. The next section reproduces that proof.
Exploitation
The proof of concept drives the vulnerable begin expression through the public API of the library. It does not call the regular expression directly; it registers the r grammar and asks the highlighter to highlight a short, crafted string written in the r programming language. The report describes the input as a creatively constructed program in r that takes an extremely long time to parse.
Step 1: install highlight.js
npm install highlight.js
This installs the library into a local Node.js project. The PoC loads the engine and the grammar from the package's lib paths, so the installed package is all that is needed.
Step 2: register the r language and highlight the crafted input
The report instructs you to put the following in a .js file and run it with node:
var hljs = require('highlight.js/lib/core');
var r = require('highlight.js/lib/languages/r');
hljs.registerLanguage('r', r);
const highlightedCode = hljs.highlight('r', "#' @param \`x\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\ \code{numeric} foobar").value
The script has three parts:
require('highlight.js/lib/core')loads the core engine without the bundled language set, andrequire('highlight.js/lib/languages/r')loads thergrammar module.hljs.registerLanguage('r', r)makes the grammar available under the namer, so thathljs.highlight('r', ...)will use it.hljs.highlight('r', ...)runs the highlighter over the crafted string and returns an object whosevalueproperty holds the resulting HTML.
The parameter name is x followed by a long run of underscores. In the JavaScript source each underscore is written as \\_, which is a backslash followed by an underscore in the string that actually reaches the highlighter. The run of escaped underscores is followed by a space and then \code{numeric} foobar, where \code is again a backslash followed by code in the real input.
That shape is what matters. The comment body contains a long sequence of characters that the r grammar's begin expression can divide among its subexpressions in many different ways, which is the ambiguity described in the previous section. When the highlighter scans the input with that expression, the regex engine explores the possible divisions, and the number of possibilities grows exponentially with the length of the run. The report states that this input takes an extremely long time to parse; it does not give a measured duration or a count of steps.
The report does not break the string down further than this; the PoC is presented as a whole, and the observable result is the delay in the hljs.highlight call.
Because the call is synchronous, the delay blocks whatever thread runs it. In a Node.js server that is the event loop, so a single request that triggers the highlight can stall the process for other requests as well. The report itself only states that the crafted program takes an extremely long time to parse and leaves the deployment consequences to the impact section.
Root cause
The mistake is in the construction of the begin regular expression of the r grammar. The report does not print that expression, so the exact subexpressions involved are not shown; what it does say is that the expression is ambiguous, and that the ambiguity is what the CodeQL js-redos query flagged. The crafted input in the PoC is built to sit inside that ambiguity: a roxygen comment whose body carries a long run of backslash-escaped underscores, followed by \code{numeric} foobar. That run is the part the expression can divide among its clauses in many different ways.
The engine offers no defence because of how backtracking matchers work. When a repetition can match a stretch of input in more than one way, the engine does not know which division will lead to an overall match, so on failure it returns to the last choice point and tries the next alternative. With one ambiguous repetition the number of ways to split a run of length n grows exponentially, and the engine enumerates them. The report describes exactly this for the reported expression: it is possible to force it to work with an O(2^n) runtime performance when there is exponential backtracking. The cost is driven by the input, not by the pattern's length, so a short string is enough.
The three teaching examples show the same shape in miniature. In /<!--(.|\s)*?-->/g the dot and \s both match whitespace, so a run of spaces after <!-- can be consumed by either alternative, and the evaluator tries every possible way of matching the spaces. In /(\w+_?)+_(\d+)/ a repetition matching letters (\w+) sits inside another repetition that can match letters ((\w+_?)+), so a run of letters can be grouped into smaller groups in many ways, and the evaluator tries every possible grouping. In the VS Code linkPattern, a section that was too general (\S) overlapped with another part of the expression until it was narrowed to [^\s\(\)]. Each case is ambiguity or overlap between regex clauses, and each fix removes it: (.|\r|\n) makes the alternatives disjoint, (\w+_)+ forces every iteration to end with an underscore, and the narrower character class stops one clause matching what another already matches.
Nothing in the matching engine bounds this. A backtracking matcher has no step budget and no timeout by default; it keeps exploring until it finds a match or exhausts the possibilities, and the possibilities are what the attacker inflates. The highlighter applies the begin expression to the input as it scans, so the pathological work happens inside the ordinary hljs.highlight call, with no separate validation step that could reject the string first. The report's general point applies directly: these badly performing expressions become a security issue when a user can control the input, and here the input is the code being highlighted.
Impact
The report's own wording is deliberately narrow: this issue may lead to a denial of service. It does not claim code execution, data disclosure or any other consequence, and it gives no measured timings, no request rates and no estimates of how long the crafted input takes or how much memory it consumes. What it establishes is that a short, attacker-chosen string can make a single hljs.highlight call take an extremely long time.
The condition for that is the one stated throughout the report: the attacker must control the input that reaches the highlighter, and the r grammar must be the one selected for it. Where both hold, the attacker chooses the string, and the string determines the cost. The PoC is a single roxygen comment of a few dozen characters, so the attacker does not need a large payload or many requests; one crafted snippet is the whole attack.
The two deployment contexts the report names behave differently:
- Server-side. highlight.js is used to render code in pages, documentation sites, paste services or editor backends. There the highlighter runs in the server process, and the
hljs.highlightcall in the PoC is synchronous. A request that carries the craftedrsnippet therefore occupies the thread that runs it for as long as the regex engine keeps backtracking. In a Node.js service that thread is the event loop, so other requests waiting on the same process are held up too. The report does not spell out this consequence; it follows from the synchronous API and the server-side usage it describes. - Client-side. In the browser the same call runs on the page's main thread. A page that highlights user-supplied code with the
rgrammar can be made unresponsive by a snippet like the one in the PoC, which freezes the tab for the duration. Again the report states the usage context and the slow parse, not the browser-level effect.
In both cases the resource being exhausted is CPU time inside the regex engine, and the amount is set by the input rather than by anything the operator controls at runtime. There is no separate validation step in front of the begin expression that could reject the string first, so the highlighter cannot distinguish the crafted comment from ordinary code before it starts the expensive work.
The severity of the issue in any given deployment depends on exposure: whether untrusted text reaches hljs.highlight with the r language, how often that path can be triggered, and whether the process serving it is shared with other work. The report leaves those questions open and does not assign a score.
Fix
The report was sent to [redacted] on 11/29/2020, and a fix was published on 12/03/2020. The report does not reproduce the patch, so the exact change to the r grammar's begin expression is not shown here; what it does give is the principle the fix follows.
That principle is stated once in the report and applied in all three teaching examples: fixing ReDoS is about removing ambiguity or overlap inside the regular expression. There is no one size fits all. The repair is not a timeout, a length limit on the input or a wrapper around the call, but a rewrite of the pattern so that the same stretch of characters can no longer be consumed in more than one way.
The three examples show what that looks like in practice:
| Vulnerable | Fixed | What changed |
|---|---|---|
| `/<!--(. | \s)*?-->/g` | `/<!--(. |
/(\w+_?)+_(\d+)/ |
/(\w+_)+(\d+)/ |
The inner repetition must now end each iteration with an underscore, so a run of letters has a single possible grouping instead of many. |
VS Code linkPattern with \(\S*?\) |
linkPattern with \([^\s\(\)]*?\) |
A clause that was too general (\S) was narrowed to [^\s\(\)], removing its overlap with another part of the expression. |
The common thread is that each rewrite makes the subexpressions disjoint, or forces a unique split of the input, so the backtracking engine has no choice points to enumerate. Applied to the r grammar, the same reasoning would target whichever clause of the begin expression can divide the run of backslash-escaped underscores in the PoC in more than one way. The report does not print the expression, so the clause is not identified.
For anyone maintaining a grammar or a regex-based parser, the practical guidance that follows from the report is to treat a CodeQL js-redos finding on a begin expression as a real defect rather than a style warning, and to fix it at the pattern level. A step limit or a timeout in the calling code would bound the damage but would not remove the exponential behaviour; the report's framing is that the ambiguity itself is the bug.
Variants to test
The pattern in this report generalises well beyond the r grammar. Any place where a backtracking regex engine applies a pattern to attacker-influenced text is a candidate, and the three teaching examples in the report are effectively a checklist of shapes to look for. The concrete things to try:
- Other highlight.js grammars. The report only names the
rgrammar, but the same library ships grammars for many languages, each with its ownbeginexpressions. Run the CodeQLjs-redosquery over the whole codebase, or load each grammar withhljs.registerLanguageand feed it a comment or string body built from a long run of one repeated character followed by a terminator. A positive result is ahljs.highlightcall that hangs or takes visibly longer as the run grows: double the run length and the time should roughly double for a linear pattern, but square or worse for an ambiguous one. - Nested repetitions over the same character class. Look for patterns of the form
(\w+_?)+,(a+b?)+,(.*)*or(\s*\w*)*, where an inner quantifier and an outer quantifier can both consume the same characters. Feed a long run of the shared character with no terminator, or with a terminator that never matches. A positive result is a parse that stalls on a string of a few dozen characters and gets dramatically worse with each added character. - Overlapping alternatives inside a repetition. Look for
(.|\s)*,(\S|\s)*,([^x]|x)*and similar, where two branches of an alternation match the same character. The HTML comment example is the template: a long run of whitespace after the opening delimiter. A positive result is the same exponential growth, visible as a regex101 debugger step count that explodes as the input grows. - Comment and string delimiters in any highlighter. Highlighters commonly match "from the opening delimiter to the closing one" with a lazy repetition. Try an unterminated comment or string containing a long run of characters that the body subexpression can match in more than one way. A positive result is a hang on an unterminated construct, which is exactly the input a paste service or editor backend will receive from a user who is still typing.
- Regex-based validators and parsers in front of user input. The report's own framing is that a validation library used by a server to check untrusted input is the classic case. Try email, URL, markdown-link, filename and identifier validators with long runs of the characters their patterns repeat. A positive result is a validation call that takes seconds on a short string, which on a server means a request that ties up a worker.
- Markdown and link parsers. The VS Code
linkPatternexample is a markdown link parser, and the same shape recurs in markdown renderers. Try nested brackets, long runs of backslashes before a bracket, and unterminated link syntax. A positive result is a render that stalls on a small document. - Client-side paths. Where a highlighter or validator runs in the browser on pasted or fetched content, the same payloads apply. A positive result is a tab that freezes on a short snippet, which is the client-side equivalent of the server-side hang.
For each candidate, the measurement that matters is the growth rate rather than the absolute time: run the same input at several lengths of the repeated run and check whether the time stays roughly linear or climbs steeply. A pattern that is merely slow but linear is a performance bug; one whose cost doubles with each added character is the ReDoS condition the report describes.
Hunting notes
ReDoS hides wherever a backtracking regex engine meets input the attacker chooses. In practice that means three places worth checking during recon:
- Syntax highlighters and formatters. Any feature that renders user-supplied code, diffs, logs or configuration files is a candidate, especially when the language is selectable by the user, because the attacker then picks the grammar as well as the input. The signal is a
beginor equivalent expression in a grammar file, or a library like highlight.js loaded on the server side. - Validators and parsers exposed to untrusted input. Email, URL, slug, filename and identifier validation, markdown rendering, and link extraction all tend to use hand-written regexes with nested quantifiers. The signal is a regex with a quantifier inside a quantifier, or an alternation whose branches overlap.
- Server-side rendering paths. The impact is highest where the regex runs synchronously in a shared process, because one crafted request then affects other users. The signal is a Node.js or single-threaded backend that calls a highlighter or validator inline in the request handler.
The strongest recon signal is a CodeQL or similar static-analysis finding on a regex, which is exactly how this issue was found: the js-redos query flagged the begin expression before anyone had built a payload. If you have access to the source, running that query is cheaper than guessing. If you do not, grep for the shapes in the teaching examples: (.|\s)*, (\w+_?)+, (\S*?) inside a repetition, and any lazy *? between two delimiters.
On impact, the report shows enough by demonstrating the hang through the public API rather than by calling the regex directly. The PoC is a normal npm install, a normal require, and a normal hljs.highlight call with a short string, which establishes that an ordinary consumer of the library is affected without any special configuration. That is the bar to aim for: a reproduction that goes through the same entry point a real application would use, with a payload short enough to be plausible as user input, and a clear statement of which input the attacker controls. The report does not measure the delay or estimate request rates, and it still carries the finding, because the exponential growth is the point and the deployment context supplies the rest.
Hunting notes
What happened, in plain words
Imagine a website that shows code snippets, the way a blog post about programming shows a block of code with keywords in one colour, text in another and comments in grey. The tool that does the colouring is a piece of software called highlight.js. It is a library: a bundle of ready-made code that other programs can load and use, rather than a program you run on its own. You give it a piece of code and the name of the language it is written in, and it hands back the same code wrapped in markers that tell a web page how to colour each part.
To know what is a keyword and what is a comment, highlight.js keeps a set of rules for each language it supports. Each set of rules is called a grammar. One of those grammars is for the R programming language, a language used a lot for statistics and data analysis. Inside the R grammar there is a rule built around a regular expression, which is a short pattern written in a special mini-language for describing text. That pattern is used to recognise where a particular kind of R comment begins.
The report describes a flaw in that pattern. A regular expression can be written in a way that makes the computer try an enormous number of possible ways to match it against certain text. Most text is matched quickly, but a deliberately odd piece of text can make the matching take an extremely long time. The report calls this ReDoS, short for Regular Expression Denial of Service. "Denial of service" means making a service unusable for the people who need it, not by breaking in or stealing anything, but by keeping it so busy that it cannot answer anyone.
The crafted text in this case is a single short string written in the R programming language. It is only a few dozen characters long. When highlight.js is asked to highlight it using the R grammar, the matching work grows out of all proportion to the length of the text, and the call takes an extremely long time to finish. Because the call is synchronous, meaning the program waits for it to finish before doing anything else, everything else in that program waits too. On a web server that can mean other visitors' requests are held up. In a browser it can mean the page freezes.
The person who found it was Erik Krogh Kristensen, a member of the GitHub team, and the report carries the reference GHSL-2020-306. It was not found by staring at the code by hand. It was found with CodeQL, a tool that analyses source code automatically, using a ready-made question (a query) that looks specifically for regular expressions vulnerable to this kind of slowdown. The query pointed at the begin regular expression of the R grammar, and the report then shows a small program that proves the problem is real.
The timeline was short. The report was sent to the project's security contact address, [redacted], on 11/29/2020. A fix was published on 12/03/2020, four days later. The version tested was the latest commit at the time of reporting, on November 30, 2020; the report does not name a release number.
The rest of this article takes the same journey more slowly. It explains what highlight.js does and why the text it receives is often not trustworthy, how the automated tool found the problem, what a regular expression is and why one can go slow, how to reproduce the slowdown on your own computer with two short pieces of code, why the pattern behaves this way, what an attacker could do with it, how the project fixed it, and how someone curious could go looking for similar bugs elsewhere. Every command and every piece of code below is copied exactly as it appears in the report, and each one is explained line by line in ordinary words.
Background: what highlight.js does and why its input matters
To understand the bug, you first need a clear picture of the tool it lives in. This section explains what highlight.js is, how it decides what to colour, and why the text it is given is often text that nobody in charge of the website wrote.
What highlight.js is
When you read a programming tutorial online, code usually appears with colours: keywords like if and return in one shade, text inside quotes in another, comments in grey. A browser on its own does not know what a keyword is. It only understands HTML, the language web pages are written in, where text is wrapped in tags such as <span> to give it a style. Something has to take the raw code and wrap each meaningful piece in the right tags.
highlight.js is that something. It is a library, which means it is not a program you double-click. It is a collection of code that another program loads and calls when it needs a job done. You hand it two things: a block of source code, and the name of the language that code is written in. It hands back the same code, now wrapped in HTML tags that a page can colour. The report describes it in one sentence: "highlight.js is a code highlighting tool which can be used both client-side and server-side."
"Client-side" means it runs inside the visitor's browser, on the visitor's own computer. "Server-side" means it runs on the computer that hosts the website, the one that sends pages to visitors. The same library works in both places, which matters a great deal later.
How grammars work
highlight.js supports many programming languages, and it cannot possibly know all of them by itself. So it ships with a separate set of rules for each language, and each set is called a grammar. The grammar for R describes what an R comment looks like, what an R string looks like, what an R number looks like, and so on. The grammar for JavaScript describes the same kinds of things for JavaScript.
Think of a grammar as a sheet of instructions for a proofreader: "a comment starts with these characters and runs to the end of the line; a string starts with a quote and ends at the next matching quote; a number is a run of digits." The highlighter follows those instructions to walk through the code from start to finish and label each stretch of text.
What a begin regular expression is
Many of those instructions are written as regular expressions. A regular expression (often shortened to regex) is a pattern written in a small special language for describing text. Instead of listing every possible comment, you write one pattern that matches any comment. The pattern is not a piece of code you run; it is a description that a built-in part of the language, the regex engine, compares against text.
In highlight.js, a grammar rule is built around a regular expression that marks where a construct begins. That expression is called the begin expression. When the highlighter scans the code, it keeps asking the regex engine: "does the begin expression match the text starting here?" If it does, the highlighter knows a comment (or string, or whatever the rule describes) starts at that point, and it can colour it accordingly. If it does not, the highlighter moves on.
So the begin expression is applied to the code being highlighted, over and over, as the highlighter walks through it. Whatever text arrives at the highlighter is text that this expression will be run against.
Why the input is often untrusted
Here is the part that turns a performance quirk into a security problem. The text handed to highlight.js frequently comes from someone other than the person running the website.
- In the browser. A site might highlight code that a visitor pasted into a box, or code that arrived from another service. The visitor, or whoever sent that code, chooses the text.
- On a server. A documentation site, a paste service, a code-sharing site or the backend of an online editor may call highlight.js to render snippets into a page. The snippet may have been submitted by any user of that service.
In both cases the operator of the site controls the software, but not the string. The string is chosen by someone else. The report puts the general principle this way: these badly performing regular expressions "can become a security issue if a user can control the input." A slow pattern that only ever sees text you wrote yourself is a nuisance. A slow pattern that sees text an outsider wrote is something an outsider can aim at you.
That is the setting for everything that follows: a library that runs patterns over text, where the text can be chosen by an attacker, and where one of those patterns can be made to run for an extremely long time.
How the problem was found
Nobody sat down and read every regular expression in highlight.js looking for a slow one. The library supports many languages, each grammar has several rules, and each rule has patterns inside it. Reading all of that by eye and judging which patterns might go slow is slow, error-prone work, and the patterns that cause trouble often look perfectly reasonable at a glance. The report's own teaching examples show why: a pattern like /<!--(.|\s)*?-->/g looks like a sensible way to describe an HTML comment, and you would have to know the subtle rules of how a regex engine matches text to see the danger.
So the search was done by a machine instead.
What CodeQL is
CodeQL is a tool made by GitHub that reads source code the way a compiler does, rather than the way a person does. Instead of treating a program as a wall of text, it builds a structured model of it: this is a function, this is a variable, this is a regular expression, this function calls that one. Once the code is in that form, you can ask questions about it in a query language, and the tool answers by searching the whole codebase.
The everyday comparison is a search engine for code. A normal text search finds the word "password" wherever it appears. A CodeQL query can ask something much more precise, such as "find every regular expression that is used as a begin expression in a grammar and that has a quantifier nested inside another quantifier." That is a question about the shape of the code, not about the letters in it, and it is exactly the kind of question a human reviewer finds hard to answer reliably across a large project.
The report describes the tool simply: "This vulnerability was found using a CodeQL query which identified the begin regular expression as vulnerable." A query here means a saved question written for CodeQL. GitHub publishes a library of such questions, each aimed at one kind of bug, so that anyone analysing a project can run them without writing the question from scratch.
The js-redos query
The particular question used here is the one for ReDoS in JavaScript code. Its name is js-redos, and the report links to its description at:
https://codeql.github.com/codeql-query-help/javascript/js-redos/
That page explains what the query looks for and why. In plain terms, the query hunts for regular expressions whose structure allows the same characters to be matched in more than one way, because those are the patterns that can be driven into the runaway behaviour described in the next section. It does not run the patterns against any input. It only looks at how they are written and flags the ones whose shape is dangerous.
This is worth pausing on, because it explains why the finding arrived before anyone had built a payload. The query does not need to know what a malicious string looks like. It reasons from the pattern alone: if this pattern has an ambiguous repetition, then some string exists that will make it slow. The person running the query then has to confirm that the flagged pattern really can be made slow, which is what the proof of concept later in the report does.
What it flagged
Running the query over the highlight.js codebase produced a hit: the begin regular expression of the grammar for the R programming language. That is the pattern the highlighter uses to decide where an R comment starts. The report states it directly: the query "identified the begin regular expression as vulnerable."
The report does not print that expression. It tells you which rule is at fault and then moves on to a proof that the fault is real, so the exact pattern is not shown anywhere in the text. What you get instead is the name of the rule, the language it belongs to, and a small program that makes the highlighter hang on a short string.
The version tested
The report names the version it was tested against as "Latest commit at the time of reporting (November 30, 2020)." A commit is a saved snapshot of a project's code, the kind of checkpoint a version control system records every time someone changes something. Projects like highlight.js are developed in the open, and the "latest commit" means the most recent snapshot on the main line of development at that moment, rather than a numbered release.
So the finding applies to the code as it stood on that day. The report does not name a release number, and it does not say which earlier versions might also be affected. If you wanted to check a particular installed copy, you would have to compare it against that snapshot yourself; the report gives you no version list to work from.
Why this route matters
Finding the bug this way has a practical consequence for anyone defending a project. The query is reusable. Once you know that a begin expression can be vulnerable, you can run the same js-redos query over any JavaScript project, including your own, and get a list of patterns worth a closer look. The report's later sections lean on this: the same tool that found this bug is the cheapest way to look for its relatives.
It also sets the shape of the rest of the report. Because the query flagged a pattern rather than an observed crash, the report has to do two things to be convincing. First, it has to explain in general why an ambiguous pattern goes slow, which it does with three small examples. Second, it has to show the flagged pattern actually misbehaving on real input, which it does with the proof of concept. The next section covers the first of those, and the reproduction section covers the second.
Understanding ReDoS: when a regex goes slow
This section is the heart of the report. Everything before it explains where the bug lives and how it was spotted; everything after it depends on understanding what is explained here. So it starts from zero: what a regular expression is, how the engine that runs it works, and why a pattern that looks perfectly sensible can be made to take an absurd amount of time.
What a regular expression is
A regular expression (usually shortened to regex) is a way of describing a piece of text by its shape rather than by listing every possible example. You have almost certainly used something like it without knowing the name. When you type a search into a file manager and it finds every file ending in .jpg, or when a website tells you your password must contain at least one digit, some pattern is being compared against text.
A regex is written in a small special language. A few symbols do most of the work:
- Ordinary characters stand for themselves. The pattern
catmatches the three letters c, a, t in a row. - A dot,
., stands for "any single character except a newline." \sstands for "any whitespace character," such as a space, a tab or a newline.\wstands for "any word character," meaning a letter, a digit or an underscore.- A star,
*, means "the thing before it, repeated zero or more times." - A plus,
+, means "the thing before it, repeated one or more times." - A question mark,
?, means "the thing before it, zero or one time." - Square brackets,
[...], mean "any one character from this set." So[abc]matches a single a, b or c, and[^abc](with a caret) matches any single character that is not a, b or c. - Parentheses,
(...), group things together so that a repetition can apply to the whole group. - A vertical bar,
|, means "or." Socat|dogmatches either word.
The regex engine is the built-in part of the programming language that takes a pattern and a piece of text and decides whether, and where, the pattern matches. You do not write the engine; it is already there in JavaScript, in Python, in most languages. You only write the pattern.
The everyday comparison is a stencil. A stencil is a sheet with a shape cut out of it. You lay it over a page and it tells you where the shape occurs. A regex is a stencil for text: you lay it over a string and it tells you where the shape occurs. And just as a badly cut stencil can make you turn the page over and over looking for a fit that is not there, a badly written regex can make the engine work far harder than you would expect.
What backtracking is
Here is the part that surprises most beginners. A regex engine does not usually march straight through the text making one decision per character. It tries one way of matching, and if that way fails, it goes back and tries another. That going back is called backtracking.
A simple comparison: you are looking for a route through a maze, and at every junction you pick a direction. If you hit a dead end, you do not give up on the maze; you walk back to the last junction and take the other path. You keep doing that until you find the exit or until you have tried every combination of choices. Backtracking is exactly that walk, and the "junctions" are the places in the pattern where more than one choice was possible.
Take a tiny example. The pattern a*b means "any number of a's, followed by a b." Against the text aaab, the engine's a* can consume zero, one, two or three a's. It tries the greedy option first: take all three a's, then look for a b. There is one, so it succeeds immediately. No backtracking needed.
Now try the same pattern against aaac. The engine takes all three a's, looks for a b, finds a c, and fails. So it backtracks: give one a back, so a* consumed two a's, and look for a b at the third a. Fails again. Backtrack again: a* consumed one a, look for a b at the second a. Fails. Backtrack again: a* consumed nothing, look for a b at the first a. Fails. Only now does the engine conclude there is no match. For a run of three a's it made four attempts. For a run of a hundred a's it would make a hundred and one. That is slow but manageable: the work grows in step with the length of the text, which people describe as linear.
The trouble starts when the pattern has more than one place where a choice can be made, and those choices interact.
What exponential backtracking is
Suppose a pattern has two independent choice points, each with two options. The engine may have to try every combination: two times two, four attempts. Three choice points give eight. Four give sixteen. Each extra choice point doubles the number of combinations. That doubling is what people call exponential growth, and it is written as O(2^n), read "order two to the n." The n is the number of choice points, and the 2 is because each one doubles the work.
The everyday comparison is a combination lock with several dials, each with two settings. With one dial there are two combinations. With two dials, four. With three, eight. With twenty dials there are over a million, and with forty there are more than a trillion. The lock has not become harder to turn; there are simply vastly more combinations to try. A regex engine facing an ambiguous pattern is in the same position: it is systematically trying combinations, and the number of combinations explodes as the input grows.
This is the condition the report describes. For the specific regular expression it reports, "it is possible to force it to work with an O(2^n) runtime performance when there is exponential backtracking." In plain words: there exists an input that makes the engine try an exponentially growing number of combinations, so a string of a few dozen characters can take longer than a string of a few thousand characters normally would.
The key point for a beginner is that the cost is driven by the input, not by the length of the pattern. A short pattern can be catastrophic on the right short string. That is why the proof of concept later in the report is only a few dozen characters long and still matters.
Why ambiguity causes it
The report names the cause precisely: "ReDoS can be caused by ambiguity or overlapping between some regex clauses." Two words, and both mean roughly the same thing in practice: two parts of the pattern can match the same characters, so the engine has more than one way to divide the text between them.
Think of a sentence that two people could each claim to have written. If you are asked "who wrote this?", and both could have, you have to consider both possibilities. If the sentence is long and every word could belong to either, the number of possible attributions explodes. A regex engine in the same position has to consider every possible division of the text among the competing parts of the pattern, and if the text is a long run of characters that both parts can match, the number of divisions is enormous.
The report's own summary of the fix follows from this: "There is no one size fits all when it comes to fixing ReDoS. But in general it is about removing ambiguity/overlap inside the regular expression." In other words, you do not fix it by making the engine faster or by putting a time limit on the call. You fix it by rewriting the pattern so that there is only one way to divide the text, and the engine has nothing to enumerate.
The report then walks through three examples to make this concrete. Each one is a small pattern, each one has the same flaw, and each one is repaired the same way. They are worth reading slowly, because the pattern in highlight.js has the same shape even though the report does not print it.
Example 1: the HTML comment regex
The first example is a pattern for finding HTML comments. In HTML, a comment starts with <!-- and ends with -->, and anything in between is ignored by the browser. A regex to find such comments might look like this:
var reg = /<!--(.|\s)*?-->/g;
Line by line, in plain words:
var reg =declares a variable namedregand gives it a value. A variable is just a named box that holds something; here it holds the pattern.- The slashes
/ ... /are how JavaScript marks the start and end of a regex. Everything between them is the pattern. <!--matches the four literal characters that open an HTML comment.(opens a group, so that the repetition that follows applies to everything inside the parentheses..matches any single character except a newline.|means "or."\smatches any single whitespace character.)closes the group. So(.|\s)means "either any character, or any whitespace character."*?means "repeat the group zero or more times, but as few times as possible." The?after the star makes the repetition lazy: the engine prefers to stop early and only takes more characters if it has to.-->matches the three literal characters that close an HTML comment.- The
gafter the closing slash is a flag. It stands for "global," meaning "find every match in the text, not just the first."
On the face of it this reads sensibly: "an opening marker, then some stuff, then a closing marker." The problem is hidden in (.|\s). The dot already matches whitespace, because a space is "any character except a newline." And \s also matches whitespace. So for a space character, both branches of the "or" can match it. The report says it directly: "Both . and \s matches whitespace such as the space character. There are therefore many possible ways for this regular expression to match a sequence of spaces."
Now imagine the input is <!-- followed by a long run of spaces and then, eventually, -->. For each space, the engine has two choices: match it with the dot, or match it with \s. For a run of thirty spaces that is two to the power of thirty possible divisions, and the engine will try them one after another until it finds the one that lets the rest of the pattern match. The report describes exactly this: "the regular expression evaluator will try every possible way of matching the spaces." It links to a debugging session that shows the blow-up step by step:
https://regex101.com/r/XvYgkN/1/debugger
That page is a tool called regex101, which lets you paste a pattern and a piece of text and watch the engine work. The debugger view shows each step the engine takes, and on an ambiguous pattern with a long run of spaces the step count climbs steeply as the run grows.
The fix is to make the two branches stop overlapping:
var reg = /<!--(.|\r|\n)*?-->/g;
The only change is inside the group: (.|\s) became (.|\r|\n). The dot still matches any character except a newline. \r matches a carriage return and \n matches a newline, so those two cover the characters the dot leaves out. Now no character can be matched by both branches: a space is matched only by the dot, and a newline is matched only by \n. The engine has one way to divide the text, so there is nothing to enumerate. The report puts it as "there is no overlap between the different elements of the regular expression."
Example 2: the snake_case regex
The second example is a pattern for a naming style used in programming. snake_case is a way of writing names where words are separated by underscores, like user_name or total_count. The pattern is meant to match a snake_case name that ends in some digits, such as user_name_42:
var reg = /(\w+_?)+_(\d+)/;
Line by line:
(opens an outer group.\w+matches one or more word characters: letters, digits or underscores._?matches an optional underscore, zero or one of them.)closes the outer group.+after the outer group means "repeat the whole group one or more times."_matches a literal underscore.(opens a second group.\d+matches one or more digits.\dmeans "any digit.")closes the second group.
Read aloud, it says: "one or more chunks, where each chunk is some word characters optionally followed by an underscore, then an underscore, then some digits." That sounds like a reasonable description of user_name_42. The engine could divide user_name into chunks as user_ then name, or as user then _name, or in several other ways, and all of them are valid.
The report explains why that is a problem: "for a string starting with lots of letters, there many ways for the regular expression to match those letters, due to the regex having a repetition matching letters (w+) inside another repetition that can match letters ((\w+_?)+)." The inner \w+ can match letters, and the outer + repeats a group that also contains \w+. So a run of letters can be split into chunks in a great many ways, and the engine will try them all: "The regular expression evaluator will try every possible grouping of letters into smaller groups of letters." The report links another debugging session showing it:
https://regex101.com/r/fmci1j/1/debugger
The fix again removes the ambiguity, by forcing each chunk to end with an underscore:
var reg = /(\w+_)+(\d+)/;
Two small changes: _? became _, so the underscore is no longer optional, and the trailing _ outside the group was removed because it is now part of the group. The effect is that every repetition of the outer group must end with an underscore. That gives the engine exactly one way to split a run of letters: each chunk runs up to and including the next underscore. There is no choice left to make, so there is nothing to backtrack over. The report says the fix works "by changing the inner repetition to match groups of letters that must end with an underscore."
Example 3: the VS Code link pattern
The third example is a real one, taken from VS Code, the code editor made by Microsoft. The report says this pattern "used to be part of VS Code," and it is a pattern for finding links in markdown, the lightweight formatting language used in readme files and documentation. Markdown links look like [text](address), and the pattern has to cope with images, escaped brackets and other variations, which is why it is long. The report shows the vulnerable version on top and the fixed version below:
var linkPattern = /(\[((!\[[^\]]*?\]\(\s*)([^\s\(\)]+?)\s*\)\]|(?:\\\]|[^\]])*\])\(\s*)(([^\s\(\)]|\(\S*?\))+)\s*(".*?")?\)/g;
var linkPattern = /(\[((!\[[^\]]*?\]\(\s*)([^\s\(\)]+?)\s*\)\]|(?:\\\]|[^\]])*\])\(\s*)(([^\s\(\)]|\([^\s\(\)]*?\))+)\s*(".*?")?\)/g;
You do not need to follow every symbol to get the point. The two lines are almost identical; the difference is in one small part. In the first line, near the middle, there is \(\S*?\). In the second line the same spot reads \([^\s\(\)]*?\). Everything else is the same.
What does that change mean? \S means "any character that is not whitespace," which is a very broad category: it includes letters, digits, punctuation, brackets, everything except spaces and newlines. [^\s\(\)] means "any character that is not whitespace and not a parenthesis," which is narrower: it excludes the round brackets as well.
Why does that matter? Because the pattern as a whole is trying to match a link address, and a link address can contain parentheses, as in [text](some(address)). The pattern has to decide where the address ends. If one part of the pattern can match a parenthesis and another part is also trying to match parentheses, the engine has more than one way to divide the text, and the ambiguity is back. The report explains the fix in exactly these terms: "A section of the regular expression that was too general (\S) was changed to something a bit more specific ([^\s\(\)]) to remove overlap with another part of the regular expression."
The report also points out that this large example is "actually very similar to the first example." Despite its length, the flaw is the same: one part of the pattern was too permissive and overlapped with another part. The repair is the same: narrow the permissive part so the two no longer compete for the same characters.
The lesson from all three
The three examples are deliberately different in size and setting, but they share one shape. In each case, two parts of the pattern could match the same characters, so the engine had many ways to divide the input, and on the wrong input it would try them all. In each case the fix was to rewrite the pattern so that only one division is possible. The report's summary of the general principle is worth keeping in mind for the rest of the article: fixing ReDoS "is about removing ambiguity/overlap inside the regular expression."
There is one more thing to notice, and it explains why this class of bug is so easy to miss. None of the three patterns looks wrong. Each one reads like a reasonable description of the thing it is meant to match. The flaw is not a typo or a missing bracket; it is a subtle overlap between two clauses that both look sensible on their own. That is why a tool like CodeQL is useful: it can check the shape of every pattern in a project, which is exactly the kind of check a human reviewer finds hard to do reliably.
With that groundwork in place, the next section turns to the pattern that the query actually flagged in highlight.js, and to the small program that proves it can be made to run for an extremely long time.
The vulnerable highlight.js grammar
The three examples in the previous section were teaching material: small patterns chosen to show the shape of the problem. This section is about the real one, the pattern the CodeQL query actually flagged inside highlight.js.
What was flagged
Running the js-redos query over the highlight.js codebase produced one hit that the report names: the begin regular expression of the grammar for the R programming language. The report states it plainly: the query "identified the begin regular expression as vulnerable."
To see why that rule matters, recall how the highlighter works. It walks through the code it has been given, and at each point it asks the regex engine whether the begin expression matches the text starting there. If it does, the highlighter knows a comment begins at that spot and colours it accordingly. So the begin expression is run against the code being highlighted, over and over, as the scan proceeds. If that expression can be made to run for an extremely long time on some input, then highlighting that input takes an extremely long time, and the highlighter is stuck inside the call.
The begin expression of the R grammar is what recognises such a comment. The crafted input in the proof of concept is written in R, which is why the R grammar has to be selected for the attack to work.
What the report does not show
The report does not print the flagged expression. It tells you which rule is at fault, in which grammar, and then moves on. So the exact pattern, the exact subexpressions inside it, and the exact clause that overlaps with another are not shown anywhere in the text.
That is worth being clear about, because it changes what you can take away. You cannot read this report and point at the faulty clause. What you can take away is the shape of the bug, which the three teaching examples describe, and a demonstration that the flagged rule really does misbehave on a short, crafted string. The report's argument is: the query says this pattern is ambiguous, here is the general reason ambiguity is dangerous, and here is a program that makes the flagged rule hang. The middle step, showing the pattern itself, is left out.
If you wanted to see the pattern, you would have to look at the R grammar in the highlight.js source yourself, at the version named in the report. The report gives you no excerpt to compare against.
How the proof of concept reaches the pattern
Because the pattern is not printed, the report cannot show you a direct test of it. Instead, the proof of concept goes through the library's public API. An API, short for Application Programming Interface, is the set of functions a library offers for other programs to call. It is the front door: the documented way to ask the library to do something, as opposed to reaching inside and using its internal parts.
The everyday comparison is a restaurant. The menu is the API: it lists what you can order and how to ask for it. The kitchen is the internal code: the recipes, the equipment, the order in which things are cooked. A customer orders from the menu and never walks into the kitchen. In the same way, a program that uses highlight.js calls the functions the library publishes, and does not reach into the grammar files and run their patterns by hand.
The proof of concept follows that rule. It does not call the flagged regular expression directly. It loads the library, registers the R grammar, and asks the highlighter to highlight a short string written in R. The highlighter then does what it always does: it walks the string and applies the grammar's begin expression to it. The slow matching happens inside that ordinary call, driven by the ordinary machinery of the library.
This matters for two reasons. First, it makes the demonstration realistic. The PoC uses the same entry point a real website or application would use, so it shows that an ordinary consumer of the library is affected, not just someone poking at internals. Second, it means the attack needs no special configuration. There is no debug flag to set, no internal function to call, no unusual setup. If untrusted text reaches hljs.highlight with the R language selected, the vulnerable pattern is applied to it.
The next section walks through that proof of concept step by step: installing the library, then running the small JavaScript program that registers the R grammar and highlights the crafted comment.
Reproducing the problem step by step
This section is the practical part. It shows how to make the problem happen on your own computer, using two short pieces of code copied exactly from the report. You do not need an account, a server or any special setup. You need a computer with Node.js installed, which is the program that runs JavaScript outside a browser.
The proof of concept has two steps. First you install highlight.js, the library under test. Then you run a small JavaScript program that loads the library, registers the R grammar, and asks the highlighter to highlight one crafted string. The report describes the input as "creatively constructed program written in the r programming language" that "can take an extremely long time to parse."
Before the steps, one word needs explaining, because it appears in the first command: npm. npm is the package manager that comes with Node.js. A package is a bundle of code that someone else wrote and published so that others can reuse it instead of writing it from scratch. npm is the tool that fetches packages from a public registry and puts them into your project. The everyday comparison is an app store for code libraries: you ask for a package by name, npm downloads it and its dependencies (the other packages it needs), and records what it installed.
Step 1: install highlight.js
The report gives the install command as:
npm install highlight.js
Line by line, in plain words:
npmis the package manager program. You type it in a terminal, which is a text window where you type commands instead of clicking buttons.installis the instruction: fetch a package and put it into the current project.highlight.jsis the name of the package to fetch, exactly as it is published in the npm registry.
Why this step is needed: the proof of concept loads highlight.js from its installed package, so the package has to be present on disk first. The command downloads it into a folder called node_modules inside whatever folder you ran the command from, and records it in a file called package.json. From then on, any JavaScript file in that folder can load the library by name.
It simply gives the command. The version tested for the report was the latest commit at the time of reporting, November 30, 2020, but the install command as written fetches whatever the registry currently offers.
Step 2: register the R language and highlight the crafted input
The report instructs you to put the following in a .js file and run it with node:
var hljs = require('highlight.js/lib/core');
var r = require('highlight.js/lib/languages/r');
hljs.registerLanguage('r', r);
const highlightedCode = hljs.highlight('r', "#' @param \`x\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\ \code{numeric} foobar").value
This is the whole proof of concept. It is short, and every line has a job. Here is what each one does.
Line 1: var hljs = require('highlight.js/lib/core');
requireis a Node.js function that loads another file or package and hands back whatever that file exports. It is how one JavaScript file uses code from another.'highlight.js/lib/core'is the path to load.highlight.jsis the package you installed.libis a folder inside it, andcoreis a file inside that folder. Thecorebuild is the engine on its own, without the bundled set of languages. Loading the core keeps the test small: you get the highlighter, and nothing else.var hljs =stores the result in a variable namedhljs, which is the conventional short name for highlight.js. From here on,hljsrefers to the library.
Why this line: the program needs the highlighter itself before it can ask it to highlight anything.
Line 2: var r = require('highlight.js/lib/languages/r');
- Same
requirefunction, different path:'highlight.js/lib/languages/r'is the file that contains the grammar for the R language. var r =stores that grammar in a variable namedr.
Why this line: the core build does not include any languages. The R grammar has to be loaded separately, and this is the line that fetches it. This is the grammar that contains the flagged begin expression, so loading it is the whole point.
Line 3: hljs.registerLanguage('r', r);
registerLanguageis a function on thehljsobject. It tells the highlighter: "here is a grammar, and here is the name to use for it."'r'is the name the grammar will be known by. This is the name you will pass tohighlightlater.ris the grammar object loaded on line 2.
Why this line: loading a grammar file does not automatically make the highlighter aware of it. You have to register it under a name. After this line, hljs.highlight('r', ...) will use the R grammar. Without it, the highlighter would not know what "r" means.
Line 4: const highlightedCode = hljs.highlight('r', "...").value
This line does the actual work, and it has several parts.
hljs.highlightis the function that highlights code. It takes two arguments: the language name and the code to highlight.'r'is the language name, matching the name registered on line 3. This is what selects the R grammar, and therefore the flaggedbeginexpression.- The long string in double quotes is the code to highlight. It is the crafted input, and it is worth looking at closely.
.valuereads a property calledvaluefrom whathighlightreturns. The function does not return a plain string; it returns an object with several properties, andvalueholds the resulting HTML.const highlightedCode =stores that HTML in a variable. The program never prints it, so the variable is not used afterwards. Its presence shows the call completed and returned a result.
Now the crafted string itself. Its parts are:
xfollowed by a long run of underscores. In the JavaScript source each underscore is written as\\_. In a JavaScript string,\\means one literal backslash, so\\_becomes a backslash followed by an underscore in the string that actually reaches the highlighter. The run of escaped underscores is the heart of the payload.
Why this input triggers the slow behaviour: the run of backslash-escaped underscores is a long stretch of characters that the R grammar's begin expression can divide among its subexpressions in many different ways. That is the ambiguity described earlier. When the highlighter applies the expression to this string, the regex engine explores the possible divisions, and the number of possibilities grows exponentially with the length of the run.
What it states is that this input takes an extremely long time to parse. When you run the program, the observable result is that the hljs.highlight call does not return promptly.
What you would see
What it establishes is that a short, attacker-chosen string can make a single hljs.highlight call take an extremely long time. The call is synchronous, meaning the program waits for it to finish before moving on to the next line. So while the regex engine is backtracking, nothing else in that program happens.
That is the bridge to the impact section. On a web server running Node.js, the code that handles requests runs on a single thread called the event loop. If one request triggers this highlight, the event loop is stuck inside the call, and every other request waiting on the same process waits too. In a browser, the same call runs on the page's main thread, so the tab freezes for the duration. The report itself only states that the crafted program takes an extremely long time to parse; the deployment consequences follow from the synchronous API and the server-side and client-side usage the report describes.
Why the proof of concept is built this way
Two choices in the PoC are deliberate and worth noticing.
First, it goes through the public API. It loads the library, registers the grammar, and calls hljs.highlight, which is the same function a real website or application would call. That makes the demonstration realistic: an ordinary consumer of the library is affected, with no special configuration.
Second, the payload is short. It is a single comment of a few dozen characters, the kind of thing a user could plausibly paste into a code box. The attacker does not need a large payload or many requests; one crafted snippet is the whole attack. That is what makes the finding worth reporting rather than dismissing as a performance quirk.
With the reproduction in hand, the next section explains why the pattern behaves this way, connecting the crafted string back to the three teaching examples.
Why the regex becomes slow: the root cause
The reproduction shows that the highlighter hangs. This section explains why, in plain terms, and ties it back to the three small examples from earlier.
The mistake is in the pattern, not the input
The root cause is the construction of the begin regular expression of the R grammar. The report does not print that expression, so the exact subexpressions involved are not shown. What it does say is that the expression is ambiguous, and that the ambiguity is what the CodeQL js-redos query flagged. The crafted input in the PoC is built to sit inside that ambiguity: a roxygen comment whose body carries a long run of backslash-escaped underscores, followed by \code{numeric} foobar. That run is the part the expression can divide among its clauses in many different ways.
The input is not doing anything clever on its own. It is just a long run of similar characters. The pattern is what turns that run into a problem, because the pattern offers more than one way to consume it.
Why the engine cannot just stop
The regex engine offers no defence because of how backtracking matchers work. When a repetition can match a stretch of input in more than one way, the engine does not know which division will lead to an overall match. So it picks one, continues, and if the rest of the pattern fails, it returns to the last choice point and tries the next alternative. That is the maze walk from earlier: at every junction, try a path, and if it dead-ends, come back and try another.
With one ambiguous repetition, the number of ways to split a run of length n grows exponentially, and the engine enumerates them. The report describes exactly this for the reported expression: it is possible to force it to work with an O(2^n) runtime performance when there is exponential backtracking. The cost is driven by the input, not by the pattern's length, so a short string is enough.
A backtracking matcher has no step budget and no timeout by default. It keeps exploring until it finds a match or exhausts the possibilities, and the possibilities are what the attacker inflates. The highlighter applies the begin expression to the input as it scans, so the pathological work happens inside the ordinary hljs.highlight call, with no separate validation step that could reject the string first.
The same shape in the three examples
The three teaching examples show the same shape in miniature, and each one maps onto the R grammar's problem.
In /<!--(.|\s)*?-->/g, the dot and \s both match whitespace, so a run of spaces after <!-- can be consumed by either alternative, and the evaluator tries every possible way of matching the spaces. In /(\w+_?)+_(\d+)/, a repetition matching letters (\w+) sits inside another repetition that can match letters ((\w+_?)+), so a run of letters can be grouped into smaller groups in many ways, and the evaluator tries every possible grouping. In the VS Code linkPattern, a section that was too general (\S) overlapped with another part of the expression until it was narrowed to [^\s\(\)].
Each case is ambiguity or overlap between regex clauses, and each fix removes it: (.|\r|\n) makes the alternatives disjoint, (\w+_)+ forces every iteration to end with an underscore, and the narrower character class stops one clause matching what another already matches. The R grammar's begin expression has the same kind of flaw, which is why the crafted comment, a long run of similar characters inside a construct the expression is trying to match, drives it into the same runaway behaviour.
The general principle
The report's general point applies directly: these badly performing expressions become a security issue when a user can control the input, and here the input is the code being highlighted. A slow pattern that only ever sees text you wrote yourself is a nuisance. That is the condition the report establishes, and the next section looks at what an attacker could do with it.
What an attacker could do with this (impact)
The report's own wording is deliberately narrow: "This issue may lead to a denial of service." It does not claim code execution, data disclosure or any other consequence, and it gives no measured timings, no request rates and no estimates of how long the crafted input takes or how much memory it consumes.
What denial of service means
Denial of service means making a service unusable for the people who need it, without breaking in or stealing anything. The everyday comparison is a shop with one till. If one customer stands at the till and refuses to move, the shop is not robbed and nothing is taken, but nobody else can buy anything until that customer leaves. A denial of service attack does the same to a computer service: it keeps the service so busy that it cannot answer anyone else.
In this case the resource being exhausted is CPU time inside the regex engine. The attacker does not need to send many requests or a large payload. One crafted snippet is enough, because the cost is set by the input rather than by anything the operator controls at runtime.
The condition for the attack
The condition is the one stated throughout the report: the attacker must control the input that reaches the highlighter, and the R grammar must be the one selected for it. Where both hold, the attacker chooses the string, and the string determines the cost. The PoC is a single roxygen comment of a few dozen characters, so the attacker does not need a large payload or many requests.
Server-side consequences
highlight.js is used to render code in pages, documentation sites, paste services or editor backends. There the highlighter runs in the server process, and the hljs.highlight call in the PoC is synchronous. A request that carries the crafted R snippet therefore occupies the thread that runs it for as long as the regex engine keeps backtracking. In a Node.js service that thread is the event loop, so other requests waiting on the same process are held up too. The report does not spell out this consequence; it follows from the synchronous API and the server-side usage it describes.
Client-side consequences
In the browser the same call runs on the page's main thread. A page that highlights user-supplied code with the R grammar can be made unresponsive by a snippet like the one in the PoC, which freezes the tab for the duration. Again the report states the usage context and the slow parse, not the browser-level effect.
What determines the severity
The severity of the issue in any given deployment depends on exposure: whether untrusted text reaches hljs.highlight with the R language, how often that path can be triggered, and whether the process serving it is shared with other work. The report leaves those questions open and does not assign a score. What it does establish is that the condition is realistic: highlight.js is used both client-side and server-side, and in both places the text it receives is often chosen by someone other than the operator.
The fix and what it teaches
The report was sent to [redacted] on 11/29/2020, and a fix was published on 12/03/2020. The report does not reproduce the patch, so the exact change to the R grammar's begin expression is not shown here. What it does give is the principle the fix follows.
The principle
That principle is stated once in the report and applied in all three teaching examples: fixing ReDoS is about removing ambiguity or overlap inside the regular expression. There is no one size fits all. The repair is not a timeout, a length limit on the input or a wrapper around the call, but a rewrite of the pattern so that the same stretch of characters can no longer be consumed in more than one way.
The three examples side by side
The three examples show what that looks like in practice:
| Vulnerable | Fixed | What changed |
|---|---|---|
| `/<!--(. | \s)*?-->/g` | `/<!--(. |
/(\w+_?)+_(\d+)/ |
/(\w+_)+(\d+)/ |
The inner repetition must now end each iteration with an underscore, so a run of letters has a single possible grouping instead of many. |
VS Code linkPattern with \(\S*?\) |
linkPattern with \([^\s\(\)]*?\) |
A clause that was too general (\S) was narrowed to [^\s\(\)], removing its overlap with another part of the expression. |
The common thread is that each rewrite makes the subexpressions disjoint, or forces a unique split of the input, so the backtracking engine has no choice points to enumerate. Applied to the R grammar, the same reasoning would target whichever clause of the begin expression can divide the run of backslash-escaped underscores in the PoC in more than one way. The report does not identify that clause by name.
What it teaches
For anyone maintaining a grammar or a regex-based parser, the practical guidance that follows from the report is to treat a CodeQL js-redos finding on a begin expression as a real defect rather than a style warning, and to fix it at the pattern level. A step limit or a timeout in the calling code would bound the damage but would not remove the exponential behaviour; the report's framing is that the ambiguity itself is the bug.
How to look for similar bugs
The pattern in this report generalises well beyond the R grammar. Any place where a backtracking regex engine applies a pattern to attacker-influenced text is a candidate, and the three teaching examples are effectively a checklist of shapes to look for. The concrete things to try:
- Other highlight.js grammars. The report only names the R grammar, but the same library ships grammars for many languages, each with its own
beginexpressions. Run the CodeQLjs-redosquery over the whole codebase, or load each grammar withhljs.registerLanguageand feed it a comment or string body built from a long run of one repeated character followed by a terminator. A positive result is ahljs.highlightcall that hangs or takes visibly longer as the run grows: double the run length and the time should roughly double for a linear pattern, but square or worse for an ambiguous one. - Nested repetitions over the same character class. Look for patterns of the form
(\w+_?)+,(a+b?)+,(.*)*or(\s*\w*)*, where an inner quantifier and an outer quantifier can both consume the same characters. Feed a long run of the shared character with no terminator, or with a terminator that never matches. A positive result is a parse that stalls on a string of a few dozen characters and gets dramatically worse with each added character. - Overlapping alternatives inside a repetition. Look for
(.|\s)*,(\S|\s)*,([^x]|x)*and similar, where two branches of an alternation match the same character. The HTML comment example is the template: a long run of whitespace after the opening delimiter. A positive result is the same exponential growth, visible as a regex101 debugger step count that explodes as the input grows. - Comment and string delimiters in any highlighter. Highlighters commonly match "from the opening delimiter to the closing one" with a lazy repetition. Try an unterminated comment or string containing a long run of characters that the body subexpression can match in more than one way. A positive result is a hang on an unterminated construct, which is exactly the input a paste service or editor backend will receive from a user who is still typing.
- Regex-based validators and parsers in front of user input. The report's own framing is that a validation library used by a server to check untrusted input is the classic case. Try email, URL, markdown-link, filename and identifier validators with long runs of the characters their patterns repeat. A positive result is a validation call that takes seconds on a short string, which on a server means a request that ties up a worker.
- Markdown and link parsers. The VS Code
linkPatternexample is a markdown link parser, and the same shape recurs in markdown renderers. Try nested brackets, long runs of backslashes before a bracket, and unterminated link syntax. A positive result is a render that stalls on a small document. - Client-side paths. Where a highlighter or validator runs in the browser on pasted or fetched content, the same payloads apply. A positive result is a tab that freezes on a short snippet, which is the client-side equivalent of the server-side hang.
For each candidate, the measurement that matters is the growth rate rather than the absolute time: run the same input at several lengths of the repeated run and check whether the time stays roughly linear or climbs steeply. A pattern that is merely slow but linear is a performance bug; one whose cost doubles with each added character is the ReDoS condition the report describes.
Where to look during recon
Recon means the early stage of a security review, where you look around a system to see what it is made of before testing anything. ReDoS hides wherever a backtracking regex engine meets input the attacker chooses. In practice that means three places worth checking:
- Syntax highlighters and formatters. Any feature that renders user-supplied code, diffs, logs or configuration files is a candidate, especially when the language is selectable by the user, because the attacker then picks the grammar as well as the input. The signal is a
beginor equivalent expression in a grammar file, or a library like highlight.js loaded on the server side. - Validators and parsers exposed to untrusted input. Email, URL, slug, filename and identifier validation, markdown rendering, and link extraction all tend to use hand-written regexes with nested quantifiers. The signal is a regex with a quantifier inside a quantifier, or an alternation whose branches overlap.
- Server-side rendering paths. The impact is highest where the regex runs synchronously in a shared process, because one crafted request then affects other users. The signal is a Node.js or single-threaded backend that calls a highlighter or validator inline in the request handler.
The strongest recon signal is a CodeQL or similar static-analysis finding on a regex, which is exactly how this issue was found: the js-redos query flagged the begin expression before anyone had built a payload. If you have access to the source, running that query is cheaper than guessing. If you do not, grep for the shapes in the teaching examples: (.|\s)*, (\w+_?)+, (\S*?) inside a repetition, and any lazy *? between two delimiters.
What a good reproduction looks like
On impact, the report shows enough by demonstrating the hang through the public API rather than by calling the regex directly. The PoC is a normal npm install, a normal require, and a normal hljs.highlight call with a short string, which establishes that an ordinary consumer of the library is affected without any special configuration. That is the bar to aim for: a reproduction that goes through the same entry point a real application would use, with a payload short enough to be plausible as user input, and a clear statement of which input the attacker controls. The report does not measure the delay or estimate request rates, and it still carries the finding, because the exponential growth is the point and the deployment context supplies the rest.
Glossary
- API (Application Programming Interface): the set of functions a library or service publishes for other programs to call; the documented front door, as opposed to its internal code.
- Backtracking: the way a regex engine tries one way of matching, and if the rest of the pattern fails, goes back to the last choice point and tries another.
beginexpression: in highlight.js, the regular expression in a grammar rule that marks where a construct (such as a comment) starts.- Client-side: running on the visitor's own computer, inside the browser.
- CodeQL: a tool that builds a structured model of source code and answers precise questions about its shape.
- Commit: a saved snapshot of a project's code in version control.
- Denial of service: making a service unusable for the people who need it, without breaking in or stealing anything.
- Event loop: the single thread in Node.js that runs request-handling code; if it is busy, other requests wait.
- Exponential growth: growth where each added unit doubles the work, written O(2^n).
- Flag (regex): a letter after the closing slash of a regex that changes how it behaves;
gmeans "find every match." - Grammar: in highlight.js, the set of rules describing how the pieces of one programming language look.
- highlight.js: a library that takes source code and a language name and returns HTML with the pieces wrapped in markup for colouring.
- HTML: the language web pages are written in, where text is wrapped in tags such as
<span>to give it a style. - Lazy repetition: a repetition marked with
?after the quantifier (*?,+?) that prefers to match as few characters as possible. - Library: a bundle of ready-made code that other programs load and use, rather than a program you run on its own.
- Linear: work that grows in step with the length of the input.
- Node.js: a program that runs JavaScript outside a browser.
- npm: the package manager that comes with Node.js; it fetches published packages and puts them into your project.
- O(2^n): "order two to the n"; a way of writing that the work doubles with each added choice point.
- Package: a bundle of code published for others to reuse.
- Public API: the functions a library offers for other programs to call, as opposed to its internal parts.
- Query (CodeQL): a saved question written for CodeQL, aimed at one kind of bug.
- Recon: the early stage of a security review, looking around a system to see what it is made of before testing.
- ReDoS (Regular Expression Denial of Service): a vulnerability where a poorly constructed regex can be made to perform extremely badly on a crafted input, causing a denial of service.
- Regex (regular expression): a pattern written in a small special language for describing text.
- Regex engine: the built-in part of a programming language that compares a pattern against text.
registerLanguage: the highlight.js function that makes a loaded grammar available under a name.- R programming language: a language used a lot for statistics and data analysis.
- Roxygen comment: an R documentation comment starting with
#', read by tools to build help pages. - Server-side: running on the computer that hosts the website, the one that sends pages to visitors.
- Snake_case: a naming style where words are separated by underscores, such as
user_name. - Synchronous: a call that the program waits for to finish before doing anything else.
- Variable: a named box in a program that holds a value.
- VS Code: the code editor made by Microsoft, from which one of the teaching examples is taken.
Why the regex becomes slow: the root cause
The mistake is in the pattern, not the input
Why the engine cannot just stop
The same shape in the three examples
The general principle
What an attacker could do with this (impact)
What denial of service means
The condition for the attack
Server-side consequences
Client-side consequences
What determines the severity
The fix and what it teaches
The report was sent to [redacted] on 11/29/2020, and a fix was published on 12/03/2020, four days later. That address is the project's security contact: a mailbox the maintainers publish so that people who find a problem can tell them privately, before the details are public and before anyone can use them against sites that have not updated yet.
You will not find a before-and-after of the faulty pattern in the text, and you will not find a diff of the file that changed. What the report does give is the principle the fix follows, and that principle is the useful part, because it applies to every pattern of this kind, not just this one.
The principle
The principle is stated once in the report and applied in all three teaching examples: fixing ReDoS is about removing ambiguity or overlap inside the regular expression. There is no one size fits all.
That sentence is worth unpacking, because it rules out the fixes a beginner might reach for first. The repair is not a timeout, a length limit on the input or a wrapper around the call. A timeout would stop the program waiting forever, but the engine would still be doing the exponential work until the clock ran out, and the call would still fail. A length limit would refuse long inputs, but the crafted string in this report is only a few dozen characters, so a limit generous enough to accept ordinary code would let it through. A wrapper would hide the problem without touching it.
The repair is a rewrite of the pattern so that the same stretch of characters can no longer be consumed in more than one way. Once there is only one way to divide the text, the engine has no choices to try, and the exponential growth disappears at the source. The everyday comparison is a form with two boxes that both accept the same answer. If a clerk has to decide which box your answer belongs in, they may have to try both. Print the form so that each answer fits exactly one box, and the question never arises.
The three examples side by side
The three teaching examples show what that rewrite looks like in practice. Each row is one pattern, the repaired version, and the change that removed the ambiguity:
| Vulnerable | Fixed | What changed |
|---|---|---|
| `/<!--(. | \s)*?-->/g` | `/<!--(. |
/(\w+_?)+_(\d+)/ |
/(\w+_)+(\d+)/ |
The inner repetition must now end each iteration with an underscore, so a run of letters has a single possible grouping instead of many. |
VS Code linkPattern with \(\S*?\) |
linkPattern with \([^\s\(\)]*?\) |
A clause that was too general (\S) was narrowed to [^\s\(\)], removing its overlap with another part of the expression. |
Read the first row again with the earlier explanation in mind. In the vulnerable version, a space could be matched by the dot or by \s, so a run of spaces had two to the power of its length possible divisions. In the fixed version, a space is matched only by the dot and a newline only by \n, so each character has exactly one owner and the engine has nothing to try twice.
The second row is the same idea in a different shape. In the vulnerable version, a run of letters could be chopped into chunks in many ways, because the optional underscore let a chunk end wherever it liked. In the fixed version, every chunk must end with an underscore, so the underscores themselves mark the only possible boundaries.
The third row is the same idea again, in a pattern too long to read at a glance. One clause could match a round bracket, and another clause was also trying to match round brackets, so the engine had a choice about where a link address ended. Narrowing the first clause to [^\s\(\)] takes brackets away from it, so only the second clause can match them.
The report does not print the expression, so the fix that shipped is not described in the text; only the principle it must have followed is.
What it teaches
There is a second lesson in the timeline. The report was sent on 11/29/2020 and the fix was published on 12/03/2020, four days later.
How to look for similar bugs
The bug in this report is one instance of a shape that appears in a great many programs. Once you know the shape, you can go looking for its relatives, whether in your own code, in a library you depend on, or in a site you are allowed to test. This section is a beginner's guide to that search: where to look, what to look for, and how to tell a real problem from a pattern that is merely a little slow.
The one question to ask
Everywhere in this section, the question is the same: can an outsider choose the text that this pattern is run against, and does the pattern have more than one way to match that text? If the answer to both is yes, you have a candidate. If the text is always written by the operator, a slow pattern is a nuisance, not a security bug. If the pattern has only one way to match, there is nothing to inflate.
The report's own framing puts it in one sentence: these badly performing expressions "can become a security issue if a user can control the input." So the first step in any hunt is not reading regexes. It is working out which text in the system comes from outside.
Where to look
1. Other highlight.js grammars
The report names only the R grammar, but highlight.js ships grammars for many languages, and each grammar has its own begin expressions. The R grammar was found by a query that can be run over the whole codebase, so the same query will check every grammar at once. If you have the source, that is the cheapest route: run the js-redos query and read the list.
If you do not have the source, or you want to test a running site, you can do it through the library's public API, the same way the proof of concept does. Load a grammar with hljs.registerLanguage, then feed the highlighter a comment or a string body built from a long run of one repeated character followed by a terminator. The everyday comparison is tapping a wall to find a hollow spot: you are not looking at the wall's structure, you are listening for the place where the sound changes.
What counts as a positive result: a hljs.highlight call that hangs, or that takes visibly longer as the run grows. That last part is the important one, and it is explained under "Measuring growth" below.
2. Nested repetitions over the same character class
This is the shape of the second teaching example, /(\w+_?)+_(\d+)/. Look for patterns where a repetition sits inside another repetition and both can consume the same characters. Common forms include:
(\w+_?)+(a+b?)+(.*)*(\s*\w*)*
The everyday comparison is a set of nested boxes where the inner box and the outer box can both hold the same item. If you are asked to pack the items, there are many ways to distribute them between the boxes, and you may have to try them all.
To test one, feed it a long run of the shared character with no terminator, or with a terminator that never matches. The absence of a terminator is what forces the engine to exhaust every division before it gives up. A positive result is a parse that stalls on a string of a few dozen characters and gets dramatically worse with each character you add.
3. Overlapping alternatives inside a repetition
This is the shape of the first teaching example, /<!--(.|\s)*?-->/g. Look for patterns where two branches of an "or" can match the same character, inside a repetition. Common forms include:
(.|\s)*(\S|\s)*([^x]|x)*
The HTML comment example is the template: a long run of whitespace after the opening delimiter, where each space can be taken by either branch. The everyday comparison is two doors into the same room. If a visitor can enter by either door, then for a crowd of visitors there are many possible assignments of people to doors, and a guard checking every assignment has a lot of work.
To test one, build an input with a long run of the character both branches can match, placed where the pattern will try to consume it. A positive result is the same exponential growth, and it is visible in the regex101 debugger as a step count that explodes as the input grows. The report links two such debugging sessions for its own examples, at https://regex101.com/r/XvYgkN/1/debugger and https://regex101.com/r/fmci1j/1/debugger, and watching one of those is the quickest way to see what "explodes" means.
4. Comment and string delimiters in any highlighter
Highlighters commonly match "from the opening delimiter to the closing one" with a lazy repetition, exactly as the HTML comment example does. That is a natural way to write the rule, and it is where the ambiguity tends to hide.
The unterminated case matters because it is the input a real service receives all the time: a paste service or an editor backend gets text from a user who is still typing, so a comment that has not been closed yet is completely ordinary. A positive result is a hang on an unterminated construct.
5. Regex-based validators and parsers in front of user input
The report's own framing is that a validation library used by a server to check untrusted input is the classic case. A validator is a piece of code that checks whether a value has the right shape: is this a valid email address, a valid web address, a valid file name, a valid identifier? These checks are very often written as hand-made regexes, and they very often contain nested quantifiers, because real-world formats are fiddly.
A positive result is a validation call that takes seconds on a short string. On a server, that means one request ties up a worker for seconds, and a handful of such requests can make the service unusable for everyone else.
6. Markdown and link parsers
The VS Code linkPattern example is a markdown link parser, and the same shape recurs in markdown renderers generally. Markdown is full of nested brackets, escaped characters and optional parts, which is exactly the kind of grammar that tempts a writer into overlapping clauses.
This is a particularly good place to look on any site that lets users write comments or posts in markdown, because the renderer runs on text the user chose.
7. Client-side paths
Where a highlighter or validator runs in the browser on pasted or fetched content, the same payloads apply. The difference is who feels the pain. On a server, one crafted request can slow down everyone using the service. In a browser, the crafted text freezes the tab of the person who loaded it, which is a smaller blast radius but still a real problem for a site that renders other people's content.
If you are testing your own site, this is easy to check: paste the crafted text into whatever box accepts code, and see whether the page stops responding.
Measuring growth, not absolute time
This is the most important practical point in the whole section, and it is easy to get wrong.
A pattern that takes half a second on a long input might be perfectly fine. A pattern that takes half a second on a short input might be a serious bug. Absolute time tells you almost nothing on its own, because it depends on the computer, the language, what else is running, and how long the input is. What matters is how the time changes as the input grows.
The method is simple:
- Pick the repeated run in your test input, the part the pattern might divide in more than one way.
- Run the same test at several lengths of that run: say 10 characters, 20, 30, 40.
- Record how long each run takes.
- Look at the pattern of the numbers, not at any single one.
What the numbers mean:
- Roughly linear. Doubling the run roughly doubles the time. This is a pattern doing a normal amount of work. It may still be slow, but it is a performance question, not a ReDoS.
- Quadratic or worse. Doubling the run multiplies the time by four or more. Worth a closer look, and possibly a real problem depending on how the input arrives.
- Exponential. Each added character roughly doubles the time. Ten characters might be instant, twenty might take a second, thirty might take minutes. This is the ReDoS condition the report describes, and it is the one to report.
The everyday comparison is a queue. If twice as many people means twice as long a wait, the queue is working normally. If twice as many people means four times as long, something in the way people are served is inefficient. If one extra person doubles the wait, the system has a structural problem, and it will fall over at a size that looks small.
The report itself does not give measured timings for the R grammar, and it does not estimate request rates. It does not need to: the exponential growth is the finding, and the deployment context supplies the rest. When you write up a similar bug, the growth curve is the evidence that matters, more than any single stopwatch reading.
Where to look during recon
What a good reproduction looks like
That is the bar to aim for if you ever report one of these yourself. A reproduction that goes through the same entry point a real application would use, with a payload short enough to be plausible as user input, and a clear statement of which input the attacker controls.
Glossary
Glossary
- Character class: a part of a regex in square brackets, such as
[^\s\(\)], that matches any one character from a set, or with a caret any one character not in the set. - Diff: a side-by-side or before-and-after listing of the lines that changed between two versions of a file.
- Disclosure: the process of telling the maintainers of a project about a security problem, and later making the details public once a fix exists.
- Main thread: the single thread in a browser tab that runs the page's scripts; if it is busy, the page stops responding.
- Patch: the change that fixes a bug, usually shown as the lines added and removed.
- Quadratic: work that grows with the square of the input length, so doubling the input multiplies the work by four.
- Static analysis: examining source code with a tool, without running it, to find patterns of interest.
- Terminal: a text window where you type commands instead of clicking buttons.
- Thread: a single line of execution inside a program; work on one thread happens one step at a time.
- Timeout: a limit on how long a call may run before it is abandoned.