Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
vuln-regex-detector
Advanced tools
Detect vulnerable regexes by querying a service hosted at Virginia Tech.
In JavaScript, regular expressions (regexes) can be "vulnerable": susceptible to catastrophic backtracking. If your application is used on the client side, this can be a performance issue. On the server side, this can expose you to Regular Expression Denial of Service (REDOS).
This module lets you check a regex for vulnerability.
const vulnRegexDetector = require('vuln-regex-detector');
const regex = /(a+)+$/; // RegExp
const pattern = regex.source; // String
const cacheConfig = {
type: vulnRegexDetector.cacheTypes.persistent
};
const config = {
cache: cacheConfig
};
/* This runs synchronously so it's expensive.
* It uses a persistent cache, so subsequent queries in this process or another one
* can be resolved locally. */
const result = vulnRegexDetector.testSync(regex, config);
console.log(`I got ${result}`);
vulnRegexDetector.test(pattern, config)
.then((result) => {
if (result === vulnRegexDetector.responses.vulnerable) {
console.log('Regex is vulnerable');
} else if (result === vulnRegexDetector.responses.safe) {
console.log('Regex is safe');
} else {
console.log('Not sure if regex is safe or not');
}
});
The module exports:
test
and testSync
for making queriescacheTypes
for use specifying config.cacheresponses
for interpreting results/**
* @param regex: RegExp or string (e.g. /re/ or 're')
* @param [config]: provide a config object like this:
* {
* server: {
* hostname: 'toybox.cs.vt.edu',
* port: 8000
* },
* cache: {
* type: cacheTypes.persistent,
* [persistentDir]: '/tmp/vuln-regex-detector-client-persistentCache'
* }
* }
*
* Config defaults if not provided:
* server: indicated in the example. This is a research server at Virginia Tech.
* cache: 'persistent' with persistentDir in a subdir of os.tmpdir().
*
* @returns Promise fulfilled with responses.X or rejected with responses.invalid.
*/
vulnRegexDetector.test (regex, config)
/**
* @param regex: see checkRegex API
* @param [config]: see checkRegex API
*
* @returns synchronous result: responses.X
*
* Since this makes a synchronous HTTP query it will be slow.
*/
vulnRegexDetector.testSync (regex, config)
NB: This API makes synchronous HTTP queries, which can be slow. You should not use it in server software. On an AWS micro instance this API can be called about 200 times per minute.
This API is intended for use in CI contexts where performance is less critical. For use in CI, see this module. If your application defines many regexes dynamically you might want to write your own CI stage.
If fulfilled, the returned Promise gets one of the following values:
responses.vulnerable
responses.safe
responses.unknown
If rejected, the returned Promise gets the value:
responses.invalid
This module queries a server hosted at Virginia Tech. When you use it, your regex will be shipped (via HTTPS) to the server and tested there.
If the regex has not been seen before, the server will respond "unknown" and test it in the background. The server cannot test synchronously because testing is expensive (potentially minutes) and there might be a long line.
If the server has not seen the regex before, it should have an answer if you query it again in a few minutes.
If you cannot connect to the server or your query is malformed, you'll get the answer "invalid".
This module maintains a persistent local cache stored in os.tmpdir()
to reduce the number of HTTP queries.
By using this module you are consenting to send us your regexes.
If your code is not open-source then feel free to host your own service.
See here for details, and specify your service's hostname and port in config
when you call the API.
We may:
The IP address of any client querying our server will be anonymized.
check-regex.pl
tool in this repo.safe-regex
uses a heuristic called star height which will miss a lot of regexes that are actually dangerous. safe-regex
misses about 90% of vulnerabilities by my estimate.Issues and PRs welcome.
MIT
FAQs
Detect vulnerable regexes by querying a service hosted at Virginia Tech.
The npm package vuln-regex-detector receives a total of 1,539 weekly downloads. As such, vuln-regex-detector popularity was classified as popular.
We found that vuln-regex-detector demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.