Skip to main content

Overview

Developers and coding agents install packages from public registries all day. A single malicious package can steal credentials from the machine that installs it. This guide blocks package downloads that Socket flags. The Formal Endpoint intercepts package registry traffic. A reads Socket’s verdict and blocks the download. It covers npm, PyPI, Maven, crates.io, RubyGems, Open VSX, NuGet, Go and Conda.

Prerequisites

  • A Socket organization with an organization API token that has the packages:list scope
  • The Formal Endpoint with Transparent Mode enabled

Connect Socket

Go to Socket under Controls. Paste the token and click Connect Socket. See Socket for details. Verify: the page shows your Socket organization name.

Create the network rule

This rule intercepts HTTPS traffic to supported package registries only. The Endpoint leaves all other traffic alone.
  1. Navigate to Network Rules
  2. Create a rule named package-registries
  3. Paste the CEL below
  4. Save the rule and set it to Active
To check only npm, match package_registry == "npm" instead. Change the policy guard to input.http.package_registry == "npm" to match. See Network rule inputs. To check packages on a instead of the Endpoint, add "outputs": {"forward_to_connector": true}. The Connector needs an HTTP for each registry host. Connector policies read the same input.integrations.socket.

Create the policy

This policy blocks a package download when your Socket policy marks the package as error.
  1. Navigate to Policies
  2. Click Create Policy
  3. Set name to block-socket-flagged-packages
  4. Paste the Rego below into the editor
  5. Click Create Policy to save
Always check input.http.package_registry or input.http.hostname (such as input.http.hostname == "registry.npmjs.org") before reading a Socket verdict. Otherwise Formal sends every HTTP request to Socket.
To block on specific alerts instead, match alerts:
The policy fails open: if Socket is unreachable or out of quota, downloads continue. To fail closed, see Handle failed checks.

Verify downloads are blocked

  1. Confirm the network rule and the policy are Active.
  2. Clear npm’s cache with npm cache clean --force. A cached tarball never reaches the registry, so Socket never checks it.
  3. Install a package Socket flags as malware, such as npm i lodahs. The install fails:
    npm does not print the policy’s block message.
  4. Install a safe package, such as npm install lodash. It succeeds.
  5. Open Logs and find the lodahs tarball request. It shows block-socket-flagged-packages as the matching policy.

Troubleshooting

Cause: The network rule does not match, or Transparent Mode is off.Fix: Run formal transparent-proxy status. Confirm the install uses a public registry, such as registry.npmjs.org.
Cause: Socket is not connected, or the Endpoint cannot reach Formal’s Control Plane.Fix: Check the Socket page shows a connected organization.
Cause: Your Socket organization ran out of quota.Fix: Raise your Socket quota, or guard the rule more narrowly so fewer requests call Socket.

Next steps

Socket integration

Every Socket policy input and how checks are made

Network rules

Match traffic on the Formal Endpoint