Gathering detailed insights and metrics for sandworm-jest
Gathering detailed insights and metrics for sandworm-jest
Security Snapshot Testing Inside Your Jest Test Suite 🪱
npm install sandworm-jest
Typescript
Module System
Node Version
NPM Version
44.1
Supply Chain
92.6
Quality
72
Maintenance
50
Vulnerability
98.2
License
sandworm-jest: v1.5.0
Published on 28 Nov 2022
sandworm-jest: v1.4.0
Published on 08 Oct 2022
sandworm-jest: v1.3.0
Published on 29 Sept 2022
sandworm-jest: v1.2.0
Published on 29 Sept 2022
sandworm-jest: v1.1.0
Published on 29 Sept 2022
JavaScript (96.23%)
Shell (3.77%)
Total Downloads
723
Last Day
1
Last Week
3
Last Month
32
Last Year
133
17 Stars
14 Commits
1 Forks
5 Watching
2 Branches
2 Contributors
Minified
Minified + Gzipped
Latest Version
1.5.0
Package Id
sandworm-jest@1.5.0
Unpacked Size
103.86 kB
Size
98.03 kB
File Count
7
NPM Version
8.19.2
Node Version
18.12.1
Cumulative downloads
Total Downloads
Last day
-87.5%
1
Compared to previous day
Last week
-82.4%
3
Compared to previous week
Last month
0%
32
Compared to previous month
Last year
-14.2%
133
Compared to previous year
Security Snapshot Testing Inside Your Jest Test Suite 🪱
package-permissions.json
file in your app's root directory, containing a list of all sensitive methods invoked, grouped by caller path.Install the plugin:
1npm install --save-dev sandworm-jest # or yarn add --dev sandworm-jest
Then update your Jest config file to include the plugin modules:
1module.exports = { 2 // ... your Jest configs 3 globalSetup: require.resolve('sandworm-jest/setup'), 4 globalTeardown: require.resolve('sandworm-jest/teardown'), 5 setupFilesAfterEnv: [require.resolve('sandworm-jest/setupFiles')], 6}
If you're already using globalSetup
or globalTeardown
, you can manually call the corresponding Sandworm method:
1// in your config file 2module.exports = { 3 globalSetup: require.resolve('./test/setup.js'), 4} 5 6// in ./test/setup.js 7const sandwormSetup = require('sandworm-jest/setup'); 8 9module.exports = async () => { 10 await sandwormSetup(); 11 // The rest of your setup logic 12};
Next, you'll probably want to exclude calls made by your test code from the output, since you only want to capture your core app's security profile. To do this, create a .sandworm.config.json
file in your app's root, containing one or more of the following attributes:
aliases
ignoredModules
Note Read more about aliases in Sandworm's docs.
Note Dev dependencies are always excluded from the output.
For example, to exclude test code and fixtures from Express, you could use the following configuration:
1{ 2 "aliases": [ 3 {"path": "express/test", "name": "test"}, 4 {"path": "express/examples", "name": "test"} 5 ], 6 "ignoredModules": ["test"] 7}
You're now ready for the initial run, that will output the package-permissions.json
security snapshot in your app's root. When running your test suite, you should now see Sandworm booting up in the console logs:
[🪱 Sandworm]: Setting up intercepts...
[🪱 Sandworm]: Intercepts ready
After the tests end, you should see Sandworm reporting on the number of events it has captured:
[🪱 Sandworm]: Intercepted 2672 events
You should now also see a new package-permissions.json
file in your app's root directory, containing an array of permission descriptor objects that each have the following attributes:
module
- the module or caller path name responsible for invoking sensitive methodspermissions
- an array of strings representing each invoked method, e.g., fs.readFile
.Here's an example of what the file might look like:
1[ 2 { 3 "module": "root", 4 "permissions": [ 5 "Function.Function", 6 "fs.readFile" 7 ] 8 }, 9 { 10 "module": "source-map-js", 11 "permissions": [ 12 "Function.Function" 13 ] 14 } 15]
Note that if you use some syntax not supported by Node out of the box, Jest will default to using babel-jest
to transform that code into plain JavaScript, similar to what you would do when building for browsers. This means the permissions Sandworm captures will represent the transformed code and not your source directly.
Hence, you might see Babel artifacts in your permissions file, such as the use of new Function('return this')
to access the global
object.
At this point, you should take your time to audit this file, and make sure each permission makes sense and represents an operation that's critical to your app's functionality. Once that's done, commit it to your repository. This will become the snapshot that future test suite runs match against.
Whenever adding or removing code or dependencies that use sensitive methods, you'll need to manually update this file to reflect the changes (or remove it and run the test suite again to have it automatically regenerated).
The Inspector is a browser app that gives an in-depth view into all of the calls intercepted by Sandworm. To launch it, run this before executing your test suite:
1npm run sandworm # or yarn sandworm
The Inspector UI should now be available at http://localhost:7071. In the left, you'll see a list of all caller paths that have been intercepted. The Permissions tab displays an aggregated list of all required permissions, while the Activity tab hosts a list of all intercepted calls. For each method call, you can see the associated arguments as well as a stack trace that can help you figure out exactly who called what.
Note You'll also see dev dependency activity in the Inspector.
No vulnerabilities found.
No security vulnerabilities found.