Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regular expression vulnerability with xmlbuilder dependency #632

Open
eistrati opened this issue Mar 9, 2018 · 0 comments
Open

Regular expression vulnerability with xmlbuilder dependency #632

eistrati opened this issue Mar 9, 2018 · 0 comments

Comments

@eistrati
Copy link
Contributor

eistrati commented Mar 9, 2018

This project seems to have bundled code from the xmlbuilder library, and it contains a Regular expression Denial of Service (ReDoS)* vulnerability.
This was fixed in the upstream xmlbuilder v9.0.7, you can see the upstream commit here:
oozcitak/xmlbuilder-js@bbf929a

The vulnerablity originates from the following Regular Expression (/^A-Za-z*$/), in this function:

XMLStringifier.prototype.xmlEncoding = function(val) {
      val = '' + val || '';
      if (!val.match(/^[A-Za-z](?:[A-Za-z0-9._-]|-)*$/)) {
        throw new Error("Invalid encoding: " + val);
      }    
      return val; 
    };   

Here is an attack string (JSON-formatted):

{"pumpPairs":[{"pump":"-A","prefix":"AA"}],"suffix":"\u0000"}

A string composed of the indicated prefix, the "pump" concatenated 30 times, and then the suffix, takes about 10 seconds to evaluate, and will double for each additional concatenation of the pump string.

The blow-up is exponential-time, so just truncating the input may not help.
The 10-second string is under 100 characters long.

  • ReDoS, also known as Catastrophic Backtracking, catastrophic backtracking is when the regex engine takes more than linear time to scan a string.
    There are lots of resources about it on the web. I have included some starting points below.

Catastrophic backtracking is particularly problematic if two conditions are met:

  1. The module is used by server processes, and
  2. The regex can be reached by user input.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants