LavaMoat Node.js runtime
lavamoat
is a Node.js runtime where modules are defined in SES Compartments. It virtualizes CommonJS module loading to apply runtime protections according to a Policy.
LavaMoat Runtime
LavaMoat differs from the standard node runtime in that it:
- Uses
lockdown()
from SES to prevent tampering with the execution environment. Thanks to lockdown, prototype-pollution attacks are neutralized. It’s also a prerequisite to code isolation. - Uses SES Compartments to isolate each package’s execution.
Packages don’t share references to anything unless explicitly passed in or allowed by policy. Custom
require
and linking implementation is provided for the purpose of loading allowed dependencies. - Enforces the app-specified LavaMoat policy. The policy specifies what execution environment each package should run with, which means: what global/built-in APIs should it be exposed to, and what other packages can it require.
The result is a runtime that should work just as before, but provides some protection against supply chain attacks.
Install
Use one of:
Usage
- Install
- Run your application once with
lavamoat app.js --autopolicy
- Inspect the
./lavamoat/node/policy.json
file it generated - Run your application with
lavamoat app.js
- If you find you need to change the policy in step 2 or 3 create a
./lavamoat/node/policy-override.json
file and introduce changes there. You can both expand and trim the permissions.
For multiple entry points or apps, use the options to set policy paths to maintain policies specific to each app.
For more information on the lavamoat policy file, check Policy file explained in documentation.
All options
Examples
Run with Policy in default location
This uses the existing policy and policy-override files to run your app.
Automatically searches for policy files inside ./lavamoat/node/
.
Policy Override with Relative Path
This uses the override policy specified at ./policies/policy-override.json
.
Troubleshooting
-
Having trouble reading thrown Errors? try running with the
--debugMode
flag. Warning: not safe for production runs. -
Got a dependency that wont quite work under LavaMoat? try patch-package
For more details go to the troubleshooting section
Programmatic usage
Programmatic usage is almost identical to the commandline and its arguments.