-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(unsafe-import): warning on unsafe-import using eval/require (#190)
* add unsafe-import probe for eval/require * remove unecessary declaration & add eval/require both warning to unsafeimport probe * update test & rename/simmplify new probe * refacto test & rename/validate probe * refacto update isrequire/isunsafecallee, remove new probe * validateNode as array in isRequire probe & update test utils * rebase refacto probe test * update spec, update addDep, clean isRequire & isUnsafeCallee probes * fix init dependencyAutoWarning=false & update docs
- Loading branch information
Showing
7 changed files
with
89 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,3 +106,4 @@ dist | |
temp.js | ||
temp/ | ||
.vscode/ | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Import Node.js Dependencies | ||
import { test } from "node:test"; | ||
import assert from "node:assert"; | ||
|
||
// Import Internal Dependencies | ||
import { runASTAnalysis } from "../../index.js"; | ||
|
||
/** | ||
* @see https://github.com/NodeSecure/js-x-ray/issues/179 | ||
*/ | ||
// CONSTANTS | ||
const kIncriminedCodeSample = `const stream = eval('require')('stream');`; | ||
const kWarningUnsafeImport = "unsafe-import"; | ||
const kWarningUnsafeStatement = "unsafe-stmt"; | ||
|
||
test("should detect unsafe-import and unsafe-statement", () => { | ||
const sastAnalysis = runASTAnalysis(kIncriminedCodeSample); | ||
|
||
assert.equal(sastAnalysis.warnings.at(0).value, "stream"); | ||
assert.equal(sastAnalysis.warnings.at(0).kind, kWarningUnsafeImport); | ||
assert.equal(sastAnalysis.warnings.at(1).value, "eval"); | ||
assert.equal(sastAnalysis.warnings.at(1).kind, kWarningUnsafeStatement); | ||
assert.equal(sastAnalysis.warnings.length, 2); | ||
assert.equal(sastAnalysis.dependencies.has("stream"), true); | ||
assert.equal(sastAnalysis.dependencies.get("stream").unsafe, true); | ||
assert.equal(sastAnalysis.dependencies.size, 1); | ||
}); |