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:listscope - 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.- Control Plane
- Terraform
- Navigate to Network Rules
- Create a rule named
package-registries - Paste the CEL below
- Save the rule and set it to Active
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 aserror.
- Control Plane
- Terraform
- Navigate to Policies
- Click Create Policy
- Set name to
block-socket-flagged-packages - Paste the Rego below into the editor
- Click Create Policy to save
alerts:
Verify downloads are blocked
- Confirm the network rule and the policy are Active.
-
Clear npm’s cache with
npm cache clean --force. A cached tarball never reaches the registry, so Socket never checks it. -
Install a package Socket flags as malware, such as
npm i lodahs. The install fails:npm does not print the policy’s block message. -
Install a safe package, such as
npm install lodash. It succeeds. -
Open Logs and find the
lodahstarball request. It showsblock-socket-flagged-packagesas the matching policy.
Troubleshooting
Downloads are not checked
Downloads are not checked
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.Policy input has error.type formal_error
Policy input has error.type formal_error
Cause: Socket is not connected, or the Endpoint cannot reach Formal’s Control Plane.Fix: Check the Socket page shows a connected organization.
Policy input has status_code 429
Policy input has status_code 429
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