eslint-plugin-redos
Advanced tools
Comparing version 4.4.5 to 4.5.0-beta.1
147
lib/main.js
@@ -34,2 +34,5 @@ "use strict"; | ||
}; | ||
var __esm = (fn, res) => function __init() { | ||
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res; | ||
}; | ||
var __commonJS = (cb, mod) => function __require() { | ||
@@ -55,2 +58,116 @@ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; | ||
// src/utils/cache.ts | ||
var fs, os, path, import_find_cache_dir, findDefaultCacheFile, findCacheFileFromOptions, findCacheFile; | ||
var init_cache = __esm({ | ||
"src/utils/cache.ts"() { | ||
"use strict"; | ||
fs = __toESM(require("fs")); | ||
os = __toESM(require("os")); | ||
path = __toESM(require("path")); | ||
import_find_cache_dir = __toESM(require("find-cache-dir")); | ||
findDefaultCacheFile = () => { | ||
const cacheDir = (0, import_find_cache_dir.default)({ name: "eslint-plugin-redos", create: true }) || os.tmpdir(); | ||
const cacheFile = path.join(cacheDir, "recheck-cache.json"); | ||
return cacheFile; | ||
}; | ||
findCacheFileFromOptions = (location) => { | ||
const cacheFile = path.resolve(location); | ||
let stat; | ||
try { | ||
stat = fs.statSync(cacheFile); | ||
} catch (e) { | ||
} | ||
if (stat) { | ||
if (stat.isDirectory()) { | ||
throw new Error(`Resolved cache.location '${cacheFile}' is a directory`); | ||
} | ||
} | ||
return cacheFile; | ||
}; | ||
findCacheFile = (location) => { | ||
if (!location) { | ||
return findDefaultCacheFile(); | ||
} | ||
return findCacheFileFromOptions(location); | ||
}; | ||
} | ||
}); | ||
// src/utils/version.ts | ||
var recheckVersion; | ||
var init_version = __esm({ | ||
"src/utils/version.ts"() { | ||
"use strict"; | ||
recheckVersion = () => { | ||
const pkg = require.resolve("recheck/package.json"); | ||
return pkg.version; | ||
}; | ||
} | ||
}); | ||
// src/utils/checker.ts | ||
var fs2, util, ReDoS, createCachedCheck; | ||
var init_checker = __esm({ | ||
"src/utils/checker.ts"() { | ||
"use strict"; | ||
fs2 = __toESM(require("fs")); | ||
util = __toESM(require("util")); | ||
ReDoS = __toESM(require("recheck")); | ||
init_cache(); | ||
init_version(); | ||
createCachedCheck = (cache, timeout, params) => { | ||
const { | ||
location: cacheLocation = void 0, | ||
strategy: cacheStrategy = "aggressive" | ||
} = typeof cache === "boolean" ? {} : cache; | ||
const cacheFile = cache ? findCacheFile(cacheLocation) : null; | ||
const settings = { | ||
version: recheckVersion(), | ||
timeout, | ||
strategy: cacheStrategy, | ||
params | ||
}; | ||
let cacheData; | ||
try { | ||
if (cacheFile) { | ||
cacheData = fs2.existsSync(cacheFile) ? JSON.parse(fs2.readFileSync(cacheFile, "utf-8")) : {}; | ||
if (!util.isDeepStrictEqual(cacheData.settings, settings)) { | ||
cacheData = { | ||
settings, | ||
results: {} | ||
}; | ||
} | ||
} | ||
} catch (error) { | ||
throw new Error(`Invalid cache: ${error}`); | ||
} | ||
const cachedCheck = (source, flags) => { | ||
const key = `/${source}/${flags}`; | ||
if (cacheData && cacheData.results[key]) { | ||
return cacheData.results[key]; | ||
} | ||
const result = ReDoS.checkSync(source, flags, __spreadValues({ timeout }, params)); | ||
let shouldCache = false; | ||
switch (cacheStrategy) { | ||
case "aggressive": | ||
shouldCache = true; | ||
break; | ||
case "conservative": | ||
shouldCache = result.checker === "automaton"; | ||
break; | ||
} | ||
if (!shouldCache) { | ||
return result; | ||
} | ||
if (cacheFile) { | ||
cacheData.results[key] = result; | ||
fs2.writeFileSync(cacheFile, JSON.stringify(cacheData)); | ||
} | ||
return result; | ||
}; | ||
return cachedCheck; | ||
}; | ||
} | ||
}); | ||
// src/rules/no-vulnerable.ts | ||
@@ -60,3 +177,3 @@ var require_no_vulnerable = __commonJS({ | ||
"use strict"; | ||
var ReDoS = __toESM(require("recheck")); | ||
init_checker(); | ||
var rule = { | ||
@@ -82,2 +199,21 @@ meta: { | ||
}, | ||
cache: { | ||
oneOf: [ | ||
{ | ||
type: "boolean" | ||
}, | ||
{ | ||
properties: { | ||
location: { | ||
type: "string" | ||
}, | ||
strategy: { | ||
type: "string", | ||
enum: ["aggressive", "conservative"] | ||
} | ||
}, | ||
additionalProperties: false | ||
} | ||
] | ||
}, | ||
accelerationMode: { | ||
@@ -177,10 +313,13 @@ type: "string", | ||
permittableComplexities = [], | ||
timeout = 1e4 | ||
timeout = 1e4, | ||
cache = false | ||
} = _a, params = __objRest(_a, [ | ||
"ignoreErrors", | ||
"permittableComplexities", | ||
"timeout" | ||
"timeout", | ||
"cache" | ||
]); | ||
const cachedCheck = createCachedCheck(cache, timeout, params); | ||
const check = (node, source, flags) => { | ||
const result = ReDoS.checkSync(source, flags, __spreadValues({ timeout }, params)); | ||
const result = cachedCheck(source, flags); | ||
switch (result.status) { | ||
@@ -187,0 +326,0 @@ case "safe": |
{ | ||
"name": "eslint-plugin-redos", | ||
"version": "4.4.5", | ||
"version": "4.5.0-beta.1", | ||
"description": "ESLint plugin for catching ReDoS vulnerability", | ||
@@ -28,3 +28,4 @@ "license": "MIT", | ||
"dependencies": { | ||
"recheck": "4.4.5" | ||
"find-cache-dir": "4.0.0", | ||
"recheck": "4.5.0-beta.1" | ||
}, | ||
@@ -35,9 +36,11 @@ "peerDependencies": { | ||
"devDependencies": { | ||
"@types/eslint": "8.21.0", | ||
"@types/node": "18.13.0", | ||
"esbuild": "0.17.8", | ||
"@types/eslint": "8.21.1", | ||
"@types/find-cache-dir": "3.2.1", | ||
"@types/jest": "29.4.0", | ||
"@types/node": "18.14.0", | ||
"esbuild": "0.17.10", | ||
"esbuild-jest": "0.5.0", | ||
"esbuild-register": "3.4.2", | ||
"eslint": "8.34.0", | ||
"jest": "29.4.2", | ||
"jest": "29.4.3", | ||
"prettier": "2.8.4", | ||
@@ -58,3 +61,3 @@ "rimraf": "4.1.2", | ||
], | ||
"gitHead": "e721d682478543cecfc73585c610502dc897037a" | ||
"gitHead": "e53585b7b8ac3baf9953df62f7d1f89f8c5f105e" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15824
415
3
12
1
2
+ Addedfind-cache-dir@4.0.0
+ Addedcommon-path-prefix@3.0.0(transitive)
+ Addedfind-cache-dir@4.0.0(transitive)
+ Addedfind-up@6.3.0(transitive)
+ Addedlocate-path@7.2.0(transitive)
+ Addedp-limit@4.0.0(transitive)
+ Addedp-locate@6.0.0(transitive)
+ Addedpath-exists@5.0.0(transitive)
+ Addedpkg-dir@7.0.0(transitive)
+ Addedrecheck@4.5.0-beta.1(transitive)
+ Addedrecheck-jar@4.5.0-beta.1(transitive)
+ Addedrecheck-linux-x64@4.5.0-beta.1(transitive)
+ Addedrecheck-macos-x64@4.5.0-beta.1(transitive)
+ Addedrecheck-windows-x64@4.5.0-beta.1(transitive)
+ Addedyocto-queue@1.1.1(transitive)
- Removedrecheck@4.4.5(transitive)
- Removedrecheck-jar@4.4.5(transitive)
- Removedrecheck-linux-x64@4.4.5(transitive)
- Removedrecheck-macos-x64@4.4.5(transitive)
- Removedrecheck-windows-x64@4.4.5(transitive)
Updatedrecheck@4.5.0-beta.1