Skip to content

Commit 511ecc4

Browse files
committed
fix(decimal128): add basic guard against REDOS attacks
This is a naive approach to reducing the efficacy of a REDOS attack against this module. A refactor of the regular expression or a custom parser substitute would be ideal, however this solution suffices as a stopgap until such work is completed. Many thanks to James Davis who graciously alterted us to the attack
1 parent 095fba9 commit 511ecc4

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

lib/bson/decimal128.js

+7
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,13 @@ Decimal128.fromString = function(string) {
206206
// Read index
207207
var index = 0;
208208

209+
// Naively prevent against REDOS attacks.
210+
// TODO: implementing a custom parsing for this, or refactoring the regex would yield
211+
// further gains.
212+
if (string.length >= 7000) {
213+
throw new Error('' + string + ' not a valid Decimal128 string');
214+
}
215+
209216
// Results
210217
var stringMatch = string.match(PARSE_STRING_REGEXP);
211218
var infMatch = string.match(PARSE_INF_REGEXP);

0 commit comments

Comments
 (0)