Lockfile resolution follows registry configuration from the scanned repo (egress outside net_guard) #330

Closed
opened 2026-09-23 07:45:10 +00:00 by sharang · 1 comment
Owner

Found while building the #310 ecosystem fixtures.

The SBOM stage generates missing lockfiles so Syft can resolve a dependency tree (pipeline/sbom/mod.rs::generate_lockfiles). Both resolvers read configuration out of the scanned repository, so the repository chooses which host our scanner connects to. net_guard does not see it: the egress is a subprocess's, not ours.

npm

A committed .npmrc is honoured (NPM_CONFIG_REGISTRY is unset in the agent image, so nothing outranks it):

# .npmrc in the scanned repo
registry=http://127.0.0.1:9/
npm ERR! FetchError: request to http://127.0.0.1:9/lodash failed, reason: connect ECONNREFUSED 127.0.0.1:9

Loopback — exactly what #294 stopped us doing in-process.

cargo

A committed .cargo/config.toml replaces the registry source:

[source.crates-io]
replace-with = "evil"
[source.evil]
registry = "sparse+http://127.0.0.1:9/index/"
warning: spurious network error … Failed to connect to 127.0.0.1:9
error: failed to get `serde` as a dependency of package `t v0.1.0 (/repo)`

Why it matters

The scanner sits on a private network with internal services and a metadata endpoint. A tenant who uploads a repository can:

  • reach an internal address from inside our network and observe the result through scan timing or the error text,
  • point resolution at a registry they control, which then decides what our SBOM says the target depends on — a supply-chain lie in evidence a customer signs.

--ignore-scripts stops package code from running. It does not stop the fetch.

Options

  1. Force our own configuration. npm --registry=https://registry.npmjs.org/ --userconfig /dev/null and cargo --config overrides, both of which outrank the repo's files. Cheapest, and it keeps resolution working.
  2. Ignore repo resolver configuration. Remove .npmrc / .cargo/config.toml from the copy we resolve in, which is not the tree we scan for findings.
  3. Gate it like pip-compile. generate_lockfiles already skips pip-compile unless PW_ALLOW_UNTRUSTED_CODE_EXEC is set; npm and cargo were left ungated. The honest fallback exists now: a manifest with no lockfile records a skipped sbom_dependencies stage naming what to commit (#310).
  4. Egress policy at the network level, which #294 noted as the long-term answer for the whole class.

I would do (1) plus (3): force the registry for the resolvers we keep, and make the whole step opt-in the way pip-compile already is, since a customer who commits a lockfile loses nothing.

Acceptance: a repository carrying either file cannot make the scanner connect to a host of its choosing, and a test asserts it.

Found while building the #310 ecosystem fixtures. The SBOM stage generates missing lockfiles so Syft can resolve a dependency tree (`pipeline/sbom/mod.rs::generate_lockfiles`). Both resolvers read **configuration out of the scanned repository**, so the repository chooses which host our scanner connects to. `net_guard` does not see it: the egress is a subprocess's, not ours. ## npm A committed `.npmrc` is honoured (`NPM_CONFIG_REGISTRY` is unset in the agent image, so nothing outranks it): ``` # .npmrc in the scanned repo registry=http://127.0.0.1:9/ ``` ``` npm ERR! FetchError: request to http://127.0.0.1:9/lodash failed, reason: connect ECONNREFUSED 127.0.0.1:9 ``` Loopback — exactly what #294 stopped us doing in-process. ## cargo A committed `.cargo/config.toml` replaces the registry source: ```toml [source.crates-io] replace-with = "evil" [source.evil] registry = "sparse+http://127.0.0.1:9/index/" ``` ``` warning: spurious network error … Failed to connect to 127.0.0.1:9 error: failed to get `serde` as a dependency of package `t v0.1.0 (/repo)` ``` ## Why it matters The scanner sits on a private network with internal services and a metadata endpoint. A tenant who uploads a repository can: - reach an internal address from inside our network and observe the result through scan timing or the error text, - point resolution at a registry they control, which then decides what our SBOM says the target depends on — a supply-chain lie in evidence a customer signs. `--ignore-scripts` stops package code from running. It does not stop the fetch. ## Options 1. **Force our own configuration.** `npm --registry=https://registry.npmjs.org/ --userconfig /dev/null` and `cargo --config` overrides, both of which outrank the repo's files. Cheapest, and it keeps resolution working. 2. **Ignore repo resolver configuration.** Remove `.npmrc` / `.cargo/config.toml` from the copy we resolve in, which is not the tree we scan for findings. 3. **Gate it like pip-compile.** `generate_lockfiles` already skips pip-compile unless `PW_ALLOW_UNTRUSTED_CODE_EXEC` is set; npm and cargo were left ungated. The honest fallback exists now: a manifest with no lockfile records a skipped `sbom_dependencies` stage naming what to commit (#310). 4. **Egress policy at the network level**, which #294 noted as the long-term answer for the whole class. I would do (1) plus (3): force the registry for the resolvers we keep, and make the whole step opt-in the way pip-compile already is, since a customer who commits a lockfile loses nothing. **Acceptance:** a repository carrying either file cannot make the scanner connect to a host of its choosing, and a test asserts it.
Author
Owner

Follow-up that rules out options 1 and 2: the manifest itself names hosts, so forcing our registry configuration or removing the repository's config files does not close this.

With no .npmrc, and with the registry forced on the command line, a URL dependency in package.json is still fetched:

{ "dependencies": { "x": "http://127.0.0.1:9/x-1.0.0.tgz" } }
$ npm install --package-lock-only --ignore-scripts --registry=https://registry.npmjs.org/
npm ERR! code ECONNREFUSED          (it connected to 127.0.0.1:9)

The same with no .cargo/config.toml, where a git dependency in Cargo.toml is fetched:

[dependencies]
x = { git = "http://127.0.0.1:9/x.git" }
$ cargo generate-lockfile
    Updating git repository `http://127.0.0.1:9/x.git`
warning: … failed to connect to 127.0.0.1: Connection refused

A resolver run over a tenant's manifest is egress to hosts the tenant chooses, by construction. Short of network-level egress policy, the only fix is not to run npm and cargo resolution in a shared deployment, as pip-compile already is not.

That costs little now. A manifest without a lockfile records a skipped sbom_dependencies stage naming the file to commit (#331), so the customer is told, not silently shortchanged.

Implementing option 3.

Follow-up that rules out options 1 and 2: **the manifest itself names hosts**, so forcing our registry configuration or removing the repository's config files does not close this. With no `.npmrc`, and with the registry forced on the command line, a URL dependency in `package.json` is still fetched: ```json { "dependencies": { "x": "http://127.0.0.1:9/x-1.0.0.tgz" } } ``` ``` $ npm install --package-lock-only --ignore-scripts --registry=https://registry.npmjs.org/ npm ERR! code ECONNREFUSED (it connected to 127.0.0.1:9) ``` The same with no `.cargo/config.toml`, where a git dependency in `Cargo.toml` is fetched: ```toml [dependencies] x = { git = "http://127.0.0.1:9/x.git" } ``` ``` $ cargo generate-lockfile Updating git repository `http://127.0.0.1:9/x.git` warning: … failed to connect to 127.0.0.1: Connection refused ``` A resolver run over a tenant's manifest is egress to hosts the tenant chooses, **by construction**. Short of network-level egress policy, the only fix is not to run npm and cargo resolution in a shared deployment, as pip-compile already is not. That costs little now. A manifest without a lockfile records a skipped `sbom_dependencies` stage naming the file to commit (#331), so the customer is told, not silently shortchanged. Implementing option 3.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: platform/pruefwerk#330