Skip to content

fix(shadow): scan only the dlx package with IPC token - #1617

Merged
Martin Torp (mtorp) merged 2 commits into
v1.xfrom
martin/shadow-dlx-scan-public-token
Oct 13, 2026
Merged

Martin Torp (mtorp) merged 2 commits into
v1.xfrom
martin/shadow-dlx-scan-public-token

Conversation

@mtorp

@mtorp Martin Torp (mtorp) commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

What

The pnpm and yarn shadow bins now honor the IPC overrides that internal callers pass, and dlx only scans the package being launched.

Why

When socket scan create --reach runs in a pnpm or yarn project, the CLI launches Coana with pnpm dlx or yarn dlx through the shadow bin. Before running, the shadow bin checks the package with POST /v0/purl. Two things went wrong there.

  1. Wrong token. spawnCoanaDlx (and runCdxgen) pass SOCKET_CLI_SHADOW_API_TOKEN: SOCKET_PUBLIC_API_TOKEN and SOCKET_CLI_SHADOW_ACCEPT_RISKS: true over IPC. The npm/npx path forwards these to the injected arborist. The pnpm and yarn bins ignored them and called the purl endpoint with the user's own token. The purl endpoint rejects repository-scoped tokens, so every reachability run with one printed Received a 403 response from Socket API which we consider a permanent failure: ... This endpoint does not support repository-scoped tokens. The run kept going, but it reads as an auth failure in CI logs.
  2. Wrong packages. The dlx scan treated every positional argument as a package. For Coana that meant run, the analysis timeout, the memory limit and the manifests tar hash were all looked up as npm packages, e.g. pkg:npm/run. Because accept-risks was also ignored, an alert on any of those names would have made the shadow bin exit 1 and kill the scan.

How

  • scanPackagesAndLogAlerts takes an optional apiToken and passes it to getAlertsMapFromPurls. When it's unset, the token falls back to the default, same as before.
  • shadowPnpmBin and shadowYarnBin read the API token and accept-risks from ipc, the same way the npm arborist does. Calls without IPC overrides, like a user running socket pnpm dlx foo, behave as before.
  • dlx scans the package option values, or the first positional if there are none. Later positionals belong to the launched binary. Each shadow bin passes a DlxFlags list naming its package options and the other options that take a value, so values like --allow-build esbuild are skipped before the package is chosen. pnpm uses --package (its -p is --parseable). yarn uses --package and -p.

Testing

  • New unit tests in src/shadow/pnpm/bin.test.mts and src/shadow/yarn/bin.test.mts cover dlx with tool arguments, dlx with --package, option values before the package, repeated --package split by another option, pnpm -p as a boolean, and IPC token plus accept-risks. They fail without the fix and pass with it.
  • pnpm run check:tsc and pnpm run lint pass.

Workaround for affected users until this ships: SOCKET_CLI_COANA_LAUNCHER=npm-install skips dlx and the shadow scan.

Expected reviewer effort: Full code review


Note

Medium Risk
Changes API token selection and which packages block dlx in the shadow security gate used before reachability runs; behavior for direct user dlx without IPC is intended to stay the same.

Overview
Fixes pnpm and yarn shadow-bin preflight scans when internal callers launch tools via dlx (e.g. Coana during socket scan create --reach).

The shadow bins now read SOCKET_CLI_SHADOW_API_TOKEN and SOCKET_CLI_SHADOW_ACCEPT_RISKS from IPC (matching npm/npx) and pass the token into getAlertsMapFromPurls, so the pre-download PURL check no longer hits the API with a repository-scoped user token and spurious 403 errors in CI.

dlx parsing is split from add: only --package / -p values (yarn) or --package plus pnpm value-taking flags are considered packages; otherwise the first positional is scanned and later args (e.g. run, timeouts) are ignored. Lockfile scans on pnpm also forward the IPC token.

Unit tests cover Coana-style dlx invocations, --package handling, and IPC overrides.

Reviewed by Cursor Bugbot for commit 77c1c66. Configure here.

The pnpm and yarn shadow bins ran their pre-launch package scan with
the user's default API token and ignored the IPC overrides that
internal callers pass. When the CLI launched Coana with pnpm dlx or
yarn dlx, a repository-scoped token got a 403 from the purl endpoint
on every reachability run. The npm path already used the public token.

The dlx scan also treated every positional argument as a package, so
the launched tool's own arguments were looked up as npm packages, and
an alert on one of them could abort the run.

Both bins now take the API token and accept-risks flag from IPC, and
dlx scans only the --package values or the first positional.
Comment thread src/shadow/common.mts Outdated
Comment thread src/shadow/common.mts Outdated
Comment thread src/shadow/common.mts Outdated
pnpm options like --allow-build and --reporter take the next argument
as their value. The dlx scan treated that value as the package and
stopped, so the package pnpm actually launched went unchecked. Each
shadow bin now passes the options that take a value, so the scan
skips their values before choosing the package. In pnpm, -p means
--parseable, so only yarn treats it as --package.
@mtorp
Martin Torp (mtorp) merged commit 7188bd9 into v1.x Oct 13, 2026
16 checks passed
@mtorp
Martin Torp (mtorp) deleted the martin/shadow-dlx-scan-public-token branch October 13, 2026 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants