Skip to content

Potential catastrophic backtracking regex vulnerability #563

@msporny

Description

@msporny

From @davisjam via email::

Forge has a regex vulnerable to catastrophic backtracking, which may lead to poor performance (if used client-side) or a REDOS vulnerability (if used server-side, esp. on attacker-controlled input).

I am not sure how likely this is in your case, but given the popularity of your module (6.8M downloads/month!) I thought I would let you know.

Regex:

lib/form.js

var _regex = /(.*?)\[(.*?)\]/g;

(introduced in 2011, 6d4e32e)

Here is a sample attack string:

{"pumpPairs":[{"pump":"[","prefix":"a"}],"suffix":"["}

i.e. "prefix" + "pump a bunch of times" + "suffix".

The catastrophic backtracking follows a power law: f(x) ~= a * x^2.58, where x is the number of pumps. On my machine, about 3K pumps (about 3K chars) blocks the node event loop for 10 seconds.

Fix advice
If you want to fix it, you can refactor the regex (the problem lies in the adjacent overlapping quantified classes .* ... .*) . You could also replace it with custom parsing. If legitimate input strings should be no longer than, say, a few hundred characters you could also simply trim the input.

Let me know if you have any questions.

If you are not familiar with REDOS, here are some good starting points for information:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions