Detalhes do pacote

lavamoat

LavaMoat71.2kMIT9.0.11

lavamoat is a NodeJS runtime where modules are defined in [SES][SesGithub] Compartments. It aims to reduce the risk of malicious code in the app dependency graph, known as "software supply chain attacks".

readme (leia-me)

LavaMoat Node - a runtime for running LavaMoat-protected NodeJS applications

lavamoat is a NodeJS runtime where modules are defined in SES Compartments. It aims to reduce the risk of malicious code in the app dependency graph, known as "software supply chain attacks".

LavaMoat Runtime

LavaMoat differs from the standard node runtime in that it:

  1. 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.
  2. 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.
  3. 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/import.

The result is a runtime that should work just as before, but provides some protection against supply chain attacks.

For an overview of LavaMoat tools see the main README

Install

Before you use lavamoat runtime protections, make sure you've set up allow-scripts and install dependencies using that setup.

Use one of:

npm i lavamoat
yarn add lavamoat

Usage

Recommended usage

  1. Install
  2. Run your application once with lavamoat app.js --autopolicy
  3. Inspect the ./lavamoat/node/policy.json file it generated
  4. Run your application with lavamoat app.js
  5. 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.

Note You can regenerate the main policy file on updates (and review for unexpected new permissions) while the modifications you needed to make remain in a separate overrides file. It makes reviewing and maintaining both files easier.

See also: Policy file explained

All options

lavamoat <entryPath> [Options]

Positionals:
  entryPath  the path to the entry file for your application. same as node.js
                                                                        [string]

Options:
      --version                             Show version number        [boolean]
      --help                                Show help                  [boolean]
  -p, --policy, --policyPath                Pass in policy. Accepts a filepath
                                            string to the existing policy. When
                                            used in conjunction with
                                            --autopolicy, specifies where to
                                            write the policy. Default:
                                            ./lavamoat/node/policy.json
                                 [string] [default: "lavamoat/node/policy.json"]
  -o, --policyOverride, --override,         Pass in override policy. Accepts a
  --policyOverridePath                      filepath string to the existing
                                            override policy. Default:
                                            ./lavamoat/node/policy-override.json
                        [string] [default: "lavamoat/node/policy-override.json"]
      --policyDebug, --pd, --policydebug,   Pass in debug policy. Accepts a
      --policyDebugPath                     filepath string to the existing
                                            debug policy. Default:
                                            ./lavamoat/node/policy-debug.json
                           [string] [default: "lavamoat/node/policy-debug.json"]
  -a, --writeAutoPolicy, --autopolicy       Generate a "policy.json" and
                                            "policy-override.json" in the
                                            current working         directory.
                                            Overwrites any existing policy
                                            files. The override policy is for
                                            making manual policy changes and
                                            always takes precedence over the
                                            automatically generated policy.
                                                      [boolean] [default: false]
      --writeAutoPolicyAndRun, --ar,        parse + generate a LavaMoat policy
      --autorun                             file then execute with the new
                                            policy.   [boolean] [default: false]
      --writeAutoPolicyDebug, --dp,         when writeAutoPolicy is enabled,
      --debugpolicy                         write policy debug info to specified
                                            or default path
                                                      [boolean] [default: false]
      --projectRoot                         specify the director from where
                                            packages should be resolved
            [string] [default: "/home/naugtur/work/metamask/metamask-extension"]
  -d, --debugMode, --debug                  Disable some protections and extra
                                            logging for easier debugging.
                                                      [boolean] [default: false]
      --statsMode, --stats                  enable writing and logging of stats
                                                      [boolean] [default: false]

More Examples

Run with Policy in default location

This uses the existing policy and policy-override files to run your app.

lavamoat index.js

Automatically searches for policy files inside ./lavamoat/node/.

Policy Override with Relative Path

This uses the override policy specified at ./policies/policy-override.json.

$ lavamoat index.js --override './policies/policy-override.json'

Tips

  • Having trouble reading thrown Errors? try running with the --debugMode flag. Warning: not safe for production runs.

  • For more information on the lavamoat policy file, check Policy file explained in documentation.

  • Got a dependency that wont quite work under LavaMoat? try patch-package

Programmatic usage

Programmatic usage is almost identical to the commandline and its arguments.

const { runLava } = require('lavamoat')

runLava({
  entryPath: './app.js',
  // Optional:
  writeAutoPolicy: false,
  writeAutoPolicyDebug: false,
  writeAutoPolicyAndRun: false,
  policyPath: 'path to file',
  policyDebugPath: 'path to file',
  policyOverridePath: 'path to file',
  projectRoot: process.cwd(),
  debugMode: false,
  statsMode: false,
})

changelog (log de mudanças)

Changelog

Dependencies

  • The following workspace dependencies were updated
    • dependencies
      • lavamoat-core bumped from ^14.2.2 to ^14.2.3

Dependencies

  • The following workspace dependencies were updated
    • dependencies
      • lavamoat-core bumped from ^15.1.0 to ^15.1.1

Dependencies

  • The following workspace dependencies were updated
    • dependencies
      • lavamoat-core bumped from ^15.2.0 to ^15.2.1
      • lavamoat-tofu bumped from ^7.2.1 to ^7.2.2

9.0.11 (2025-08-25)

Dependencies

  • The following workspace dependencies were updated
    • dependencies
      • @lavamoat/aa bumped from ^4.3.3 to ^4.3.4
      • lavamoat-core bumped from ^16.5.0 to ^16.5.1

9.0.10 (2025-06-24)

Bug Fixes

  • add Node.js v24.0.0 to supported engines (ad9cdcd)
  • deps: update babel monorepo (afc9fe5)
  • deps: update dependency corepack to v0.33.0 (#1682) (0de2351)
  • lavamoat-node: support packages with falsy main field (e8c489c), closes #1706

Dependencies

  • The following workspace dependencies were updated
    • dependencies
      • @lavamoat/aa bumped from ^4.3.2 to ^4.3.3
      • lavamoat-core bumped from ^16.4.0 to ^16.5.0
      • lavamoat-tofu bumped from ^8.0.7 to ^8.0.8

9.0.9 (2025-05-01)

Bug Fixes

  • core: block circular global object endowments (#1505) (6745a0e)
  • deps: update dependency corepack to v0.32.0 (#1611) (854bf40)

Dependencies

  • The following workspace dependencies were updated
    • dependencies
      • lavamoat-core bumped from ^16.3.2 to ^16.4.0
      • lavamoat-tofu bumped from ^8.0.6 to ^8.0.7

9.0.8 (2025-03-11)

Bug Fixes

  • deps: update dependency resolve to v1.22.10 (#1535) (17bee26)

Dependencies

  • The following workspace dependencies were updated
    • dependencies
      • @lavamoat/aa bumped from ^4.3.1 to ^4.3.2
      • lavamoat-core bumped from ^16.3.1 to ^16.3.2
      • lavamoat-tofu bumped from ^8.0.5 to ^8.0.6

9.0.7 (2025-01-28)

Dependencies

  • The following workspace dependencies were updated
    • dependencies
      • lavamoat-core bumped from ^16.3.0 to ^16.3.1
      • lavamoat-tofu bumped from ^8.0.4 to ^8.0.5

9.0.6 (2025-01-15)

Bug Fixes

  • deps: update dependency corepack to v0.30.0 (4f4fd6e)

Dependencies

  • The following workspace dependencies were updated
    • dependencies
      • lavamoat-core bumped from ^16.2.2 to ^16.3.0

9.0.5 (2024-12-09)

Bug Fixes

  • 2 bugs manifested in walking content from policy-overrides (#1471) (7599146)

Dependencies

  • The following workspace dependencies were updated
    • dependencies
      • lavamoat-core bumped from ^16.2.1 to ^16.2.2

9.0.4 (2024-12-05)

Bug Fixes

  • make policy ordering consistntly manifest itself in json files produced (a149a7d)

Dependencies

  • The following workspace dependencies were updated
    • dependencies
      • lavamoat-core bumped from ^16.2.0 to ^16.2.1
      • lavamoat-tofu bumped from ^8.0.3 to ^8.0.4

9.0.3 (2024-12-04)

Bug Fixes

  • deps: update babel monorepo (e6f4e70)
  • deps: update babel monorepo to v7.25.9 (6d9d5a3)
  • deps: update babel monorepo to v7.26.2 (9bac12a)
  • deps: update dependency node-gyp-build to v4.8.4 (1c21367)
  • lavamoat-node: fix the bug that prevented following dependency relationships listed in policy overrides (61df9ed)

Dependencies

  • The following workspace dependencies were updated
    • dependencies
      • @lavamoat/aa bumped from ^4.3.0 to ^4.3.1
      • lavamoat-core bumped from ^16.1.0 to ^16.2.0
      • lavamoat-tofu bumped from ^8.0.2 to ^8.0.3

9.0.2 (2024-10-11)

Dependencies

  • The following workspace dependencies were updated
    • dependencies
      • lavamoat-core bumped from ^16.0.1 to ^16.1.0
      • lavamoat-tofu bumped from ^8.0.1 to ^8.0.2

9.0.1 (2024-09-11)

Bug Fixes

  • browserify: support Node.js ^20.17.0 (a5a3949)
  • deps: update dependency corepack to v0.29.4 (a8d265b)
  • deps: update dependency node-gyp-build to v4.8.2 (59c26bd)
  • node: support Node.js ^20.17.0 (a5a3949)
  • perf: support Node.js ^20.17.0 (a5a3949)
  • support Node.js ^20.17.0 (a5a3949)

Dependencies

  • The following workspace dependencies were updated
    • dependencies
      • lavamoat-core bumped from ^16.0.0 to ^16.0.1
      • lavamoat-tofu bumped from ^8.0.0 to ^8.0.1

9.0.0 (2024-08-15)

⚠ BREAKING CHANGES

  • node: remove support for Node.js v16
  • browserify: remove support for Node.js v16
  • perf: remove support for Node.js v16
  • tofu: remove support for Node.js v16
  • webpack: remove support for Node.js v16
  • core: remove support for Node.js v16

Bug Fixes

  • deps: update babel monorepo (b6aa714)
  • node: support Node.js ^22.5.1 (f631ae2)
  • perf: support Node.js ^22.5.1 (f631ae2)

Miscellaneous Chores

  • browserify: remove support for Node.js v16 (6ca05ba)
  • core: remove support for Node.js v16 (6ca05ba)
  • node: remove support for Node.js v16 (6ca05ba)
  • perf: remove support for Node.js v16 (6ca05ba)
  • tofu: remove support for Node.js v16 (6ca05ba)
  • webpack: remove support for Node.js v16 (6ca05ba)

Dependencies

  • The following workspace dependencies were updated
    • dependencies
      • lavamoat-core bumped from ^15.4.0 to ^16.0.0
      • lavamoat-tofu bumped from ^7.3.0 to ^8.0.0

8.0.7 (2024-07-11)

Bug Fixes

  • deps: update babel monorepo (246ec25)
  • deps: update babel monorepo to v7.24.5 (7e466bd)
  • deps: update babel monorepo to v7.24.6 (f6d450f)
  • deps: update dependency node-gyp-build to v4.8.1 (aa04eda)

Dependencies

  • The following workspace dependencies were updated
    • dependencies
      • @lavamoat/aa bumped from ^4.2.0 to ^4.3.0
      • lavamoat-core bumped from ^15.3.0 to ^15.4.0
      • lavamoat-tofu bumped from ^7.2.3 to ^7.3.0

8.0.6 (2024-03-26)

Bug Fixes

  • node: remove unused props from LavaMoatOpts type (7c9ae4a)

Dependencies

  • The following workspace dependencies were updated
    • dependencies
      • @lavamoat/aa bumped from ^4.1.0 to ^4.2.0
      • lavamoat-core bumped from ^15.2.1 to ^15.3.0
      • lavamoat-tofu bumped from ^7.2.2 to ^7.2.3

8.0.4 (2024-02-29)

Bug Fixes

  • lavamoat: update for ESM support in policy gen (612b9f9)

Dependencies

  • The following workspace dependencies were updated
    • dependencies
      • @lavamoat/aa bumped from ^4.0.1 to ^4.1.0
      • lavamoat-core bumped from ^15.1.2 to ^15.2.0
      • lavamoat-tofu bumped from ^7.2.0 to ^7.2.1

8.0.3 (2024-02-07)

Bug Fixes

  • deps: update babel monorepo (e30facc)
  • deps: update dependency json-stable-stringify to v1.1.1 (7d28e79)
  • deps: update dependency node-gyp-build to v4.8.0 (f25d495)

Dependencies

  • The following workspace dependencies were updated
    • dependencies
      • lavamoat-core bumped from ^15.1.1 to ^15.1.2
      • lavamoat-tofu bumped from ^7.1.0 to ^7.2.0

8.0.1 (2024-01-18)

Bug Fixes

  • deps: pin dependencies (4006c1f)
  • deps: update dependency node-gyp-build to v4.6.1 (570e00f)
  • deps: update dependency yargs to v17.7.2 (a1b21d3)

Dependencies

  • The following workspace dependencies were updated
    • dependencies
      • @lavamoat/aa bumped from ^4.0.0 to ^4.0.1
      • lavamoat-core bumped from ^15.0.0 to ^15.1.0
      • lavamoat-tofu bumped from ^7.0.0 to ^7.1.0

8.0.0 (2023-10-18)

⚠ BREAKING CHANGES

  • The minimum supported Node.js version is now v16.20.0.

Features

  • core: add overrideTaming: 'severe' for improved developer experience under lavamoat (#730) (20e4f76)
  • node20 (ef3a0da)

Bug Fixes

  • browserify,node,tofu,viz: bump babel packages (4e12040)
  • drop Node.js v14 (#729) (10c667b)

Dependencies

  • The following workspace dependencies were updated
    • dependencies
      • @lavamoat/aa bumped from ^3.1.5 to ^4.0.0
      • lavamoat-core bumped from ^14.4.1 to ^15.0.0
      • lavamoat-tofu bumped from ^6.2.1 to ^7.0.0

7.3.1 (2023-09-14)

Bug Fixes

  • lavamoat: allow prefixed builtins (6ef1593), closes #652
  • lavamoat: fix main entry point (09dc176)
  • node/examples: Use workspace version of lavamoat (9f1d14d)
  • normalize all package versions (0800c11)

Dependencies

  • The following workspace dependencies were updated
    • dependencies
      • @lavamoat/aa bumped from ^3.1.0 to ^3.1.5
      • lavamoat-core bumped from ^14.2.3 to ^14.4.1
      • lavamoat-tofu bumped from ^6.0.3 to ^6.2.1

7.1.1 (2023-09-08)

Bug Fixes

  • lavamoat: allow prefixed builtins (6ef1593), closes #652
  • lavamoat: fix main entry point (09dc176)
  • node/examples: Use workspace version of lavamoat (9f1d14d)

Dependencies

  • The following workspace dependencies were updated
    • dependencies
      • lavamoat-core bumped from ^14.2.1 to ^14.2.2
      • lavamoat-tofu bumped from ^6.0.2 to ^6.0.3