Sandworm
HomepageGitHub
  • Sandworm Audit
    • Getting Started
    • How It Works
    • Configuration
    • Issue Types
    • Resolved Issues
    • License Policies
    • Fail Policies
    • Custom Registries
    • Chart Info
  • Sandworm Guard
    • Overview
    • Getting Started
    • Supported Methods
    • Enforcing Permissions
    • Describing Permissions
    • Caller Module Paths
    • Configuration
    • Bundlers & Sourcemaps
  • Snapshot Testing
  • Contributing
    • Code of Conduct
    • Security Policy
Powered by GitBook
On this page
  • Configuring sourcemaps
  • Multiple source files

Was this helpful?

Edit on GitHub
  1. Sandworm Guard

Bundlers & Sourcemaps

PreviousConfigurationNextSnapshot Testing

Last updated 2 years ago

Was this helpful?

Sandworm relies on source file paths to determine caller modules for each method invocation. Unfortunately, when bundling your code with Webpack, Parcel, Rollup, or other similar tools, that information is lost, as everything gets bundled together in a single file. To re-enable Sandworm in this scenario, you'll also need to provide a .

Note When loading sourcemaps, Sandworm.init becomes an async method you need to await. It is best to wait for it to finish before importing other modules or further initializing your app. Until then, Sandworm will not be able to correctly infer module names, potentially leading to legitimate calls being blocked.

The simplest way to instruct Sandworm to load sourcemaps is to pass loadSourceMaps=true to Sandworm.init. Setting this option to true will load the sourcemap defined within the currently executing js file (containing the init-invoking code).

Note loadSourceMaps is true by default when running Sandworm in a browser.

await Sandworm.init({ loadSourceMaps: true });

Configuring sourcemaps

Ideally, your generated sourcemap:

  • should be inlined with the source file itself to save an extra network request;

  • should exclude the sources, as you probably don't what those to be publicly available, and they will unnecessarily inflate the file size;

  • should only include line numbers to reduce the file size, as we're only ever interested in original file names.

Multiple source files

If you're generating multiple source files in your bundling process, you'll need to let Sandworm know. Otherwise, js files distinct from the main file (the one that has initially called init) will be treated as entirely individual modules. To signal you need multiple code files, pass an object to the loadSourceMaps option with source paths (or URLs) as keys and sourcemap paths (or URLs) as values:

await Sandworm.init({
  loadSourceMaps: {
    'http://localhost:3001/static/js/main.chunk.js':
      'http://localhost:3001/static/js/main.chunk.js.map',
    'http://localhost:3001/static/js/vendors~main.chunk.js':
      'http://localhost:3001/static/js/vendors~main.chunk.js.map',
  },
});
sourcemap