browserify (latest)
Published 09 May, 2018
No known vulnerabilities in browserify
Security wise, browserify seems to be a safe package to use.
Over time, new vulnerabilities may be disclosed on browserify and other packages. To easily find, fix and prevent such vulnerabilties, protect your repos with Snyk!
Vulnerable versions of browserify
Fixed in 12.0.0
Command Injection
Detailed paths
- Introduced through: browserify@11.2.0 > shell-quote@0.0.1
Overview
shell-quote
is an npm package used to quote and parse shell commands.
The quote
function does not properly escape the following special characters <
, >
, ;
, {
, }
, and as a result can be used by an attacker to inject malicious shell commands or leak sensitive information.
Shell command injection proof of concept
Consider the following poc.js
application
var quote = require('shell-quote').quote;
var exec = require('child_process').exec;
var userInput = process.argv[2];
var safeCommand = quote(['echo', userInput]);
exec(safeCommand, function (err, stdout, stderr) {
console.log(stdout);
});
Running the following command will not only print the character a
as expected, but will also run the another command, i.e touch malicious.sh
$ node poc.js 'a;{touch,malicious.sh}'
Remediation
Upgrade shell-quote
to version 1.6.1 or greater.
References
Regular Expression Denial of Service (DoS)
Detailed paths
- Introduced through: browserify@11.2.0 > glob@4.5.3 > minimatch@2.0.10
Overview
minimatch
is a minimalistic matching library used for converting glob expressions into JavaScript RegExp objects.
Affected versions of this package are vulnerable to Regular Expression Denial of Service (ReDoS) attacks.
The Regular expression Denial of Service (ReDoS) is a type of Denial of Service attack. Many Regular Expression implementations may reach edge cases that causes them to work very slowly (exponentially related to input size), allowing an attacker to exploit this and can cause the program to enter these extreme situations by using a specially crafted input and cause the service to excessively consume CPU, resulting in a Denial of Service.
An attacker can provide a long value to the minimatch
function, which nearly matches the pattern being matched. This will cause the regular expression matching to take a long time, all the while occupying the event loop and preventing it from processing other requests and making the server unavailable (a Denial of Service attack).
You can read more about Regular Expression Denial of Service (ReDoS)
on our blog.
Remediation
Upgrade minimatch
to version 3.0.2
or greater.
References
Fixed in 9.0.0
Regular Expression Denial of Service (DoS)
Detailed paths
- Introduced through: browserify@8.1.3 > browser-pack@3.2.0 > umd@2.1.0 > uglify-js@2.4.24
- Introduced through: browserify@8.1.3 > umd@2.1.0 > uglify-js@2.4.24
- Introduced through: browserify@8.1.3 > browser-pack@3.2.0 > umd@2.1.0 > ruglify@1.0.0 > uglify-js@2.2.5
- Introduced through: browserify@8.1.3 > umd@2.1.0 > ruglify@1.0.0 > uglify-js@2.2.5
Overview
The parse()
function in the uglify-js
package prior to version 2.6.0 is vulnerable to regular expression denial of service (ReDoS) attacks when long inputs of certain patterns are processed.
Denial of Service (DoS) describes a family of attacks, all aimed at making a system inaccessible to its original and legitimate users. There are many types of DoS attacks, ranging from trying to clog the network pipes to the system by generating a large volume of traffic from many machines (a Distributed Denial of Service - DDoS - attack) to sending crafted requests that cause a system to crash or take a disproportional amount of time to process.
The Regular expression Denial of Service (ReDoS) is a type of Denial of Service attack. Regular expressions are incredibly powerful, but they aren't very intuitive and can ultimately end up making it easy for attackers to take your site down.
Let’s take the following regular expression as an example:
regex = /A(B|C+)+D/
This regular expression accomplishes the following:
A
The string must start with the letter 'A'(B|C+)+
The string must then follow the letter A with either the letter 'B' or some number of occurrences of the letter 'C' (the+
matches one or more times). The+
at the end of this section states that we can look for one or more matches of this section.D
Finally, we ensure this section of the string ends with a 'D'
The expression would match inputs such as ABBD
, ABCCCCD
, ABCBCCCD
and ACCCCCD
It most cases, it doesn't take very long for a regex engine to find a match:
$ time node -e '/A(B|C+)+D/.test("ACCCCCCCCCCCCCCCCCCCCCCCCCCCCD")'
0.04s user 0.01s system 95% cpu 0.052 total
$ time node -e '/A(B|C+)+D/.test("ACCCCCCCCCCCCCCCCCCCCCCCCCCCCX")'
1.79s user 0.02s system 99% cpu 1.812 total
The entire process of testing it against a 30 characters long string takes around ~52ms. But when given an invalid string, it takes nearly two seconds to complete the test, over ten times as long as it took to test a valid string. The dramatic difference is due to the way regular expressions get evaluated.
Most Regex engines will work very similarly (with minor differences). The engine will match the first possible way to accept the current character and proceed to the next one. If it then fails to match the next one, it will backtrack and see if there was another way to digest the previous character. If it goes too far down the rabbit hole only to find out the string doesn’t match in the end, and if many characters have multiple valid regex paths, the number of backtracking steps can become very large, resulting in what is known as catastrophic backtracking.
Let's look at how our expression runs into this problem, using a shorter string: "ACCCX". While it seems fairly straightforward, there are still four different ways that the engine could match those three C's:
- CCC
- CC+C
- C+CC
- C+C+C.
The engine has to try each of those combinations to see if any of them potentially match against the expression. When you combine that with the other steps the engine must take, we can use RegEx 101 debugger to see the engine has to take a total of 38 steps before it can determine the string doesn't match.
From there, the number of steps the engine must use to validate a string just continues to grow.
String | Number of C's | Number of steps |
---|---|---|
ACCCX | 3 | 38 |
ACCCCX | 4 | 71 |
ACCCCCX | 5 | 136 |
ACCCCCCCCCCCCCCX | 14 | 65,553 |
By the time the string includes 14 C's, the engine has to take over 65,000 steps just to see if the string is valid. These extreme situations can cause them to work very slowly (exponentially related to input size, as shown above), allowing an attacker to exploit this and can cause the service to excessively consume CPU, resulting in a Denial of Service.
Remediation
Upgrade to version 2.6.0
or greater.
If a direct dependency update is not possible, use snyk wizard
to patch this vulnerability.
References
Improper minification of non-boolean comparisons
Detailed paths
- Introduced through: browserify@8.1.3 > browser-pack@3.2.0 > umd@2.1.0 > ruglify@1.0.0 > uglify-js@2.2.5
- Introduced through: browserify@8.1.3 > umd@2.1.0 > ruglify@1.0.0 > uglify-js@2.2.5
Overview
uglify-js
is a JavaScript parser, minifier, compressor and beautifier toolkit.
Tom MacWright discovered that UglifyJS versions 2.4.23 and earlier are affected by a vulnerability which allows a specially crafted Javascript file to have altered functionality after minification. This bug was demonstrated by Yan to allow potentially malicious code to be hidden within secure code, activated by minification.
Details
In Boolean algebra, DeMorgan's laws describe the relationships between conjunctions (&&
), disjunctions (||
) and negations (!
).
In Javascript form, they state that:
!(a && b) === (!a) || (!b)
!(a || b) === (!a) && (!b)
The law does not hold true when one of the values is not a boolean however.
Vulnerable versions of UglifyJS do not account for this restriction, and erroneously apply the laws to a statement if it can be reduced in length by it.
Consider this authentication function:
function isTokenValid(user) {
var timeLeft =
!!config && // config object exists
!!user.token && // user object has a token
!user.token.invalidated && // token is not explicitly invalidated
!config.uninitialized && // config is initialized
!config.ignoreTimestamps && // don't ignore timestamps
getTimeLeft(user.token.expiry); // > 0 if expiration is in the future
// The token must not be expired
return timeLeft > 0;
}
function getTimeLeft(expiry) {
return expiry - getSystemTime();
}
When minified with a vulnerable version of UglifyJS, it will produce the following insecure output, where a token will never expire:
( Formatted for readability )
function isTokenValid(user) {
var timeLeft = !( // negation
!config // config object does not exist
|| !user.token // user object does not have a token
|| user.token.invalidated // token is explicitly invalidated
|| config.uninitialized // config isn't initialized
|| config.ignoreTimestamps // ignore timestamps
|| !getTimeLeft(user.token.expiry) // > 0 if expiration is in the future
);
return timeLeft > 0
}
function getTimeLeft(expiry) {
return expiry - getSystemTime()
}
Remediation
Upgrade UglifyJS to version 2.4.24
or higher.
References
Fixed in 5.2.0
Insecure Randomness
Detailed paths
- Introduced through: browserify@5.1.1 > crypto-browserify@2.1.10
Overview
crypto-browserify
is implementation of crypto for the browser.
Affected versions of the package are vulnerable to Insecure Randomness due to using the cryptographically insecure Math.random()
. This function can produce predictable values and should not be used in security-sensitive context.
Details
Computers are deterministic machines, and as such are unable to produce true randomness. Pseudo-Random Number Generators (PRNGs) approximate randomness algorithmically, starting with a seed from which subsequent values are calculated.
There are two types of PRNGs: statistical and cryptographic. Statistical PRNGs provide useful statistical properties, but their output is highly predictable and forms an easy to reproduce numeric stream that is unsuitable for use in cases where security depends on generated values being unpredictable. Cryptographic PRNGs address this problem by generating output that is more difficult to predict. For a value to be cryptographically secure, it must be impossible or highly improbable for an attacker to distinguish between it and a truly random value. In general, if a PRNG algorithm is not advertised as being cryptographically secure, then it is probably a statistical PRNG and should not be used in security-sensitive contexts.
You can read more about node's insecure Math.random()
in Mike Malone's post.
Remediation
Upgrade crypto-browserify
to version 2.1.11 or higher.
References
Fixed in 3.33.0
Potential Script Injection
Detailed paths
- Introduced through: browserify@3.32.1 > syntax-error@0.1.0
Overview
There was a security vulnerability where a malicious file could execute code when browserified. Make sure your installation of browserify is using syntax-error@1.1.1 or later.
Source: Node Security Project
Details
The vulnerability involves breaking out of Function(), which was used to check syntax for more informative errors. In node 0.10, Function() seems to be implemented in terms of eval(), so malicious code can execute even if the function returned by Function() was never called. node 0.11 does not appear to be vulnerable.
Thanks to [Cal Leeming] (cal@iops.io) for discovering and disclosing this bug!
Remediation
Update to version 1.1.1 or greater. If this is being used in conjunction with browserify, update browserify to 4.2.1 or greater.
References
Fixed in 3.17.0
Uninitialized Memory Exposure
Detailed paths
- Introduced through: browserify@3.16.1 > module-deps@1.1.0 > concat-stream@1.0.1
- Introduced through: browserify@3.16.1 > concat-stream@1.0.1
Overview
concat-stream
is writable stream that concatenates strings or binary data and calls a callback with the result.
Affected versions of the package are vulnerable to Uninitialized Memory Exposure.
A possible memory disclosure vulnerability exists when a value of type number
is provided to the stringConcat()
method and results in concatenation of uninitialized memory to the stream collection.
This is a result of unobstructed use of the Buffer
constructor, whose insecure default constructor increases the odds of memory leakage.
Details
Constructing a Buffer
class with integer N
creates a Buffer
of length N
with raw (not "zero-ed") memory.
In the following example, the first call would allocate 100 bytes of memory, while the second example will allocate the memory needed for the string "100":
// uninitialized Buffer of length 100
x = new Buffer(100);
// initialized Buffer with value of '100'
x = new Buffer('100');
concat-stream
's stringConcat
function uses the default Buffer
constructor as-is, making it easy to append uninitialized memory to an existing list. If the value of the buffer list is exposed to users, it may expose raw server side memory, potentially holding secrets, private data and code. This is a similar vulnerability to the infamous Heartbleed
flaw in OpenSSL.
You can read more about the insecure Buffer
behavior on our blog.
Similar vulnerabilities were discovered in request, mongoose, ws and sequelize.
Remediation
Upgrade concat-stream
to version 1.5.2 or higher.
Note This is vulnerable only for Node <=4
References
Fixed in 1.1.0
Regular Expression Denial of Service (ReDoS)
Detailed paths
- Introduced through: browserify@1.0.0 > semver@1.0.14
Overview
npm is a package manager for javascript.
Affected versions of this package are vulnerable to Regular Expression Denial of Service (ReDoS). The semver module uses regular expressions when parsing a version string. For a carefully crafted input, the time it takes to process these regular expressions is not linear to the length of the input. Since the semver module did not enforce a limit on the version string length, an attacker could provide a long string that would take up a large amount of resources, potentially taking a server down. This issue therefore enables a potential Denial of Service attack. This is a slightly differnt variant of a typical Regular Expression Denial of Service (ReDoS) vulnerability.
Details
Denial of Service (DoS) describes a family of attacks, all aimed at making a system inaccessible to its original and legitimate users. There are many types of DoS attacks, ranging from trying to clog the network pipes to the system by generating a large volume of traffic from many machines (a Distributed Denial of Service - DDoS - attack) to sending crafted requests that cause a system to crash or take a disproportional amount of time to process.
The Regular expression Denial of Service (ReDoS) is a type of Denial of Service attack. Regular expressions are incredibly powerful, but they aren't very intuitive and can ultimately end up making it easy for attackers to take your site down.
Let’s take the following regular expression as an example:
regex = /A(B|C+)+D/
This regular expression accomplishes the following:
A
The string must start with the letter 'A'(B|C+)+
The string must then follow the letter A with either the letter 'B' or some number of occurrences of the letter 'C' (the+
matches one or more times). The+
at the end of this section states that we can look for one or more matches of this section.D
Finally, we ensure this section of the string ends with a 'D'
The expression would match inputs such as ABBD
, ABCCCCD
, ABCBCCCD
and ACCCCCD
It most cases, it doesn't take very long for a regex engine to find a match:
$ time node -e '/A(B|C+)+D/.test("ACCCCCCCCCCCCCCCCCCCCCCCCCCCCD")'
0.04s user 0.01s system 95% cpu 0.052 total
$ time node -e '/A(B|C+)+D/.test("ACCCCCCCCCCCCCCCCCCCCCCCCCCCCX")'
1.79s user 0.02s system 99% cpu 1.812 total
The entire process of testing it against a 30 characters long string takes around ~52ms. But when given an invalid string, it takes nearly two seconds to complete the test, over ten times as long as it took to test a valid string. The dramatic difference is due to the way regular expressions get evaluated.
Most Regex engines will work very similarly (with minor differences). The engine will match the first possible way to accept the current character and proceed to the next one. If it then fails to match the next one, it will backtrack and see if there was another way to digest the previous character. If it goes too far down the rabbit hole only to find out the string doesn’t match in the end, and if many characters have multiple valid regex paths, the number of backtracking steps can become very large, resulting in what is known as catastrophic backtracking.
Let's look at how our expression runs into this problem, using a shorter string: "ACCCX". While it seems fairly straightforward, there are still four different ways that the engine could match those three C's:
- CCC
- CC+C
- C+CC
- C+C+C.
The engine has to try each of those combinations to see if any of them potentially match against the expression. When you combine that with the other steps the engine must take, we can use RegEx 101 debugger to see the engine has to take a total of 38 steps before it can determine the string doesn't match.
From there, the number of steps the engine must use to validate a string just continues to grow.
String | Number of C's | Number of steps |
---|---|---|
ACCCX | 3 | 38 |
ACCCCX | 4 | 71 |
ACCCCCX | 5 | 136 |
ACCCCCCCCCCCCCCX | 14 | 65,553 |
By the time the string includes 14 C's, the engine has to take over 65,000 steps just to see if the string is valid. These extreme situations can cause them to work very slowly (exponentially related to input size, as shown above), allowing an attacker to exploit this and can cause the service to excessively consume CPU, resulting in a Denial of Service.
Remediation
Update to a version 4.3.2 or greater. From the issue description [2]: "Package version can no longer be more than 256 characters long. This prevents a situation in which parsing the version number can use exponentially more time and memory to parse, leading to a potential denial of service."
References
Fixed in 0.1.0
Prototype Pollution
Detailed paths
- Introduced through: browserify@0.0.5 > npm@6.2.0 > libcipm@2.0.1 > npm-lifecycle@2.0.3 > node-gyp@3.7.0 > request@2.81.0 > hawk@3.1.3 > hoek@2.16.3
- Introduced through: browserify@0.0.5 > npm@6.2.0 > npm-lifecycle@2.0.3 > node-gyp@3.7.0 > request@2.81.0 > hawk@3.1.3 > hoek@2.16.3
- Introduced through: browserify@0.0.5 > npm@6.2.0 > node-gyp@3.7.0 > request@2.81.0 > hawk@3.1.3 > hoek@2.16.3
- Introduced through: browserify@0.0.5 > npm@6.2.0 > libcipm@2.0.1 > npm-lifecycle@2.0.3 > node-gyp@3.7.0 > request@2.81.0 > hawk@3.1.3 > boom@2.10.1 > hoek@2.16.3
- Introduced through: browserify@0.0.5 > npm@6.2.0 > npm-lifecycle@2.0.3 > node-gyp@3.7.0 > request@2.81.0 > hawk@3.1.3 > boom@2.10.1 > hoek@2.16.3
- Introduced through: browserify@0.0.5 > npm@6.2.0 > node-gyp@3.7.0 > request@2.81.0 > hawk@3.1.3 > boom@2.10.1 > hoek@2.16.3
- Introduced through: browserify@0.0.5 > npm@6.2.0 > libcipm@2.0.1 > npm-lifecycle@2.0.3 > node-gyp@3.7.0 > request@2.81.0 > hawk@3.1.3 > cryptiles@2.0.5 > boom@2.10.1 > hoek@2.16.3
- Introduced through: browserify@0.0.5 > npm@6.2.0 > npm-lifecycle@2.0.3 > node-gyp@3.7.0 > request@2.81.0 > hawk@3.1.3 > cryptiles@2.0.5 > boom@2.10.1 > hoek@2.16.3
- Introduced through: browserify@0.0.5 > npm@6.2.0 > node-gyp@3.7.0 > request@2.81.0 > hawk@3.1.3 > cryptiles@2.0.5 > boom@2.10.1 > hoek@2.16.3
- Introduced through: browserify@0.0.5 > npm@6.2.0 > libcipm@2.0.1 > npm-lifecycle@2.0.3 > node-gyp@3.7.0 > request@2.81.0 > hawk@3.1.3 > sntp@1.0.9 > hoek@2.16.3
- Introduced through: browserify@0.0.5 > npm@6.2.0 > npm-lifecycle@2.0.3 > node-gyp@3.7.0 > request@2.81.0 > hawk@3.1.3 > sntp@1.0.9 > hoek@2.16.3
- Introduced through: browserify@0.0.5 > npm@6.2.0 > node-gyp@3.7.0 > request@2.81.0 > hawk@3.1.3 > sntp@1.0.9 > hoek@2.16.3
Overview
hoek is a Utility methods for the hapi ecosystem.
Affected versions of this package are vulnerable to Prototype Pollution.
The utilities function allow modification of the Object
prototype. If an attacker can control part of the structure passed to this function, they could add or modify an existing property.
PoC by Olivier Arteau (HoLyVieR)
var Hoek = require('hoek');
var malicious_payload = '{"__proto__":{"oops":"It works !"}}';
var a = {};
console.log("Before : " + a.oops);
Hoek.merge({}, JSON.parse(malicious_payload));
console.log("After : " + a.oops);
Remediation
Upgrade hoek
to versions 4.2.1, 5.0.3 or higher.
References
Insecure Randomness
Detailed paths
- Introduced through: browserify@0.0.5 > npm@6.2.0 > libcipm@2.0.1 > npm-lifecycle@2.0.3 > node-gyp@3.7.0 > request@2.81.0 > hawk@3.1.3 > cryptiles@2.0.5
- Introduced through: browserify@0.0.5 > npm@6.2.0 > npm-lifecycle@2.0.3 > node-gyp@3.7.0 > request@2.81.0 > hawk@3.1.3 > cryptiles@2.0.5
- Introduced through: browserify@0.0.5 > npm@6.2.0 > node-gyp@3.7.0 > request@2.81.0 > hawk@3.1.3 > cryptiles@2.0.5
Overview
cryptiles is a package for general crypto utilities.
Affected versions of this package are vulnerable to Insecure Randomness. The randomDigits()
method is supposed to return a cryptographically strong pseudo-random data string, but it was biased to certain digits. An attacker could be able to guess the created digits.
Remediation
Upgrade to version 4.1.2 and higher.
References
Time of Check Time of Use (TOCTOU)
Detailed paths
- Introduced through: browserify@0.0.5 > npm@6.2.0 > chownr@1.0.1
- Introduced through: browserify@0.0.5 > npm@6.2.0 > cacache@11.0.2 > chownr@1.0.1
- Introduced through: browserify@0.0.5 > npm@6.2.0 > libcipm@2.0.1 > pacote@8.1.6 > cacache@11.0.2 > chownr@1.0.1
- Introduced through: browserify@0.0.5 > npm@6.2.0 > pacote@8.1.6 > cacache@11.0.2 > chownr@1.0.1
- Introduced through: browserify@0.0.5 > npm@6.2.0 > libcipm@2.0.1 > pacote@8.1.6 > make-fetch-happen@4.0.1 > cacache@11.0.2 > chownr@1.0.1
- Introduced through: browserify@0.0.5 > npm@6.2.0 > pacote@8.1.6 > make-fetch-happen@4.0.1 > cacache@11.0.2 > chownr@1.0.1
- Introduced through: browserify@0.0.5 > npm@6.2.0 > libnpmhook@4.0.1 > npm-registry-fetch@3.2.0 > make-fetch-happen@4.0.1 > cacache@11.0.2 > chownr@1.0.1
- Introduced through: browserify@0.0.5 > npm@6.2.0 > npm-profile@3.0.2 > make-fetch-happen@4.0.1 > cacache@11.0.2 > chownr@1.0.1
- Introduced through: browserify@0.0.5 > npm@6.2.0 > libcipm@2.0.1 > pacote@8.1.6 > tar@4.4.4 > chownr@1.0.1
- Introduced through: browserify@0.0.5 > npm@6.2.0 > pacote@8.1.6 > tar@4.4.4 > chownr@1.0.1
- Introduced through: browserify@0.0.5 > npm@6.2.0 > npm-registry-fetch@1.1.1 > make-fetch-happen@3.0.0 > cacache@10.0.4 > chownr@1.0.1
- Introduced through: browserify@0.0.5 > npm@6.2.0 > tar@4.4.4 > chownr@1.0.1
Overview
Affected versions of chownr are vulnerable to Time of Check Time of Use (TOCTOU). It does not dereference symbolic links and changes the owner of the link.
Remediation
There is no fix version for chownr
.