Skip to content

fix: keep the API token and settings socket-cli passes Coana out of the build tools it runs - #1725

Merged
Jeppe Fredsgaard Blaabjerg (jfblaa) merged 1 commit into
v1.xfrom
jfblaa/facts-1-coana-env
Nov 18, 2026
Merged

Jeppe Fredsgaard Blaabjerg (jfblaa) merged 1 commit into
v1.xfrom
jfblaa/facts-1-coana-env

Conversation

@jfblaa

@jfblaa Jeppe Fredsgaard Blaabjerg (jfblaa) commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Heads up, reviewer

Coana passes its environment to the build tools and package managers it runs, so today the Socket API token we give Coana reaches every Gradle/Maven plugin and npm install script in the user's project.

This PR doesn't change how we pass settings to Coana: it's the same 7 variables as on v1.x. The fix is on Coana's side (coana-tech/coana-package-manager#2774): Coana deletes those variables at startup, before it starts anything. Socket CLI's part is small:

  • It sets only those 7 for Coana. It no longer spreads its own normalised settings, and no longer sets SOCKET_BRANCH_NAME, which Coana never read.
  • It leaves out the other names it reads the token from (SOCKET_SECURITY_API_TOKEN, SOCKET_SECURITY_API_KEY, SOCKET_CLI_API_KEY). Coana doesn't know those names, so it can't delete them.

LLM Description written by Claude Code:claude-opus-5-5

Coana passes its environment on to the build tools and package managers it runs, so the API token and the other settings socket-cli sets for Coana reached them too. Coana now removes the variables it reads at startup (coana-tech/coana-package-manager#2774). socket-cli sets only those for it, and leaves out the other variables it reads the token from, which Coana doesn't read.

Merge and release only with the whole stack, after COANA_CLI_VERSION is bumped to a Coana release with the Coana Socket facts stack (coana-tech/coana-package-manager#2791, #2774–#2779 and #2792, then #2780 and #2788 for socket fix and #2785, #2781, #2786 and #2793 for reachability) and SocketDev/depscan#30549 (serves Coana's facts component) is deployed. Until the bump, the token still reaches the tools: the pinned Coana 15.15.0 leaves the variables in place.

Details
  • Coana gets SOCKET_CLI_API_TOKEN, SOCKET_ORG_SLUG, SOCKET_CLI_API_BASE_URL, SOCKET_CLI_API_PROXY, SOCKET_CALLER_USER_AGENT, SOCKET_CLI_VERSION and SOCKET_REPO_NAME; unset ones leave the user's own.
  • The user's SOCKET_SECURITY_API_TOKEN, SOCKET_SECURITY_API_KEY, SOCKET_CLI_API_KEY and SOCKET_CLI_CONFIG (which can carry a token) are left out, as Coana gets the token in SOCKET_CLI_API_TOKEN. A build that reads one of these itself no longer sees it under Coana.
  • SOCKET_BRANCH_NAME is no longer set; Coana doesn't read it.
  • socket-cli's own normalised settings, such as NODE_COMPILE_CACHE, still reach Coana through bin/cli.js; keeping those out is a separate change.
  • This keeps the token out of what those tools log or record. It doesn't stop a hostile plugin: on Linux, a process running as the same user can read Coana's starting environment from /proc.
  • Tests run a stand-in Coana from the real cache script and check the environment it gets.
Stack
  1. fix: keep the API token and settings socket-cli passes Coana out of the build tools it runs #1725: Keep the Socket API token out of the tools Coana runs (this PR)
  2. feat(manifest): generate Socket facts with Coana #1726: Generate Socket facts with Coana
  3. refactor(manifest): delete socket-cli's build-tool scripts and facts assembly #1727: Delete socket-cli's build-tool scripts and facts assembly (internal)
  4. feat(manifest): add socket.json reachability settings for the build tools #1728: socket.json reachability settings for the build tools
  5. feat(manifest): ask for the reachability settings in the setup wizards #1729: Reachability settings in the setup wizards
  6. refactor: follow-ups to generating Socket facts with Coana #1733: Follow-ups (draft)

Changelog

In CHANGELOG.md under [Unreleased]:

Fixed

  • Your Socket API token, whether from socket login or the environment, and the other settings socket-cli passes to Coana no longer reach the build tools and package managers Coana runs.

🤖 Generated with Claude Code

@jfblaa Jeppe Fredsgaard Blaabjerg (jfblaa) changed the title Pass what socket-cli adds for Coana in one variable fix: keep socket-cli's API token and settings out of the build tools Coana runs Nov 17, 2026
@jfblaa Jeppe Fredsgaard Blaabjerg (jfblaa) changed the title fix: keep socket-cli's API token and settings out of the build tools Coana runs fix: keep the API token and settings socket-cli passes Coana out of the build tools it runs Nov 17, 2026
@jfblaa
Jeppe Fredsgaard Blaabjerg (jfblaa) marked this pull request as ready for review November 18, 2026 08:10
@cursor

cursor Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

PR Summary

High Risk
Changes how authentication and org settings reach Coana across reach/fix flows and requires a matching Coana release for the new context variable; mis-versioned Coana or env regressions could break scans or re-expose secrets.

Overview
Stops socket-cli credentials and Socket-specific settings from leaking into build tools Coana spawns (Maven, Gradle, npm, etc.) by no longer setting SOCKET_CLI_API_TOKEN, org slug, API base URL, and related vars on Coana's process environment.

spawnCoana now builds a SocketCliContext (API token, base URL, proxy, org, repo name, user agent, CLI version) and passes it to Coana either as JSON in SOCKET_CLI_COANA_CONTEXT (pinned/newer Coana) or as the legacy separate env vars (older --reach-version / --fix-version). Coana's child env is reduced to the user's environment (still stripping npm_package_*) plus that single context channel—not constants.processEnv or scattered SOCKET_* overrides.

Reachability drops branchName / SOCKET_BRANCH_NAME and passes repository name through spawnCoana's repoName option instead of env, skipping the default placeholder repo so unrelated projects don't share Coana cache buckets.

Tests cover context JSON for pinned Coana, legacy env for old versions, repo-name handling, and that socket-cli-only env keys stay out of Coana's environment.

Reviewed by Cursor Bugbot for commit 700fbd3. Configure here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplification review: reuse, simplification, efficiency and altitude. Nothing here is a blocker. The inline comments are ordered roughly by importance.

Outside this PR's scope, for the longer-term design the description mentions:

  • Only the socket login token is kept out of the build tools. A user's own SOCKET_CLI_API_TOKEN, SOCKET_SECURITY_API_TOKEN or GITHUB_TOKEN still reaches Coana through userEnv, and from there the build tools. That is the usual CI setup. The changelog wording is accurate, but the root fix is Coana starting build tools with a scrubbed environment.
  • Shadow npm has the same pattern. src/shadow/npm-base.mts:184 and src/shadow/npm/install.mts:92 still spread constants.processEnv into npm, whose lifecycle scripts run untrusted code. One shared helper that builds the environment for children running build or install code would give Coana and npm the same policy.

Checked and fine: every Coana spawn goes through spawnCoana (including the three socket fix calls), threading the version out of getCoanaCliDir is necessary because the cache directory is content-addressed, contextVariables needs its filter, and nothing the diff adds is slower in a way that matters.

Comment thread src/utils/coana-release.mts Resolved
Comment thread src/utils/coana-release.mts Resolved
Comment thread src/utils/coana-release.mts Resolved
Comment thread src/utils/coana-release.mts Resolved
Comment thread src/utils/coana-release.mts Resolved
Comment thread src/utils/coana-release.test.mts Resolved
Comment thread src/utils/coana-release.test.mts Resolved
Comment thread src/utils/coana-release.test.mts Resolved
@jfblaa
Jeppe Fredsgaard Blaabjerg (jfblaa) force-pushed the jfblaa/facts-1-coana-env branch 2 times, most recently from d0498e0 to 59c5124 Compare November 18, 2026 10:39
@jfblaa

Copy link
Copy Markdown
Contributor Author

[agent] Thanks for the review. On the two points outside the PR:

  • The user's own token: covered now. The design changed after the review: Coana deletes the seven variables it reads at startup, whoever set them (coana-tech/coana-package-manager#2774), and socket-cli leaves out the other names it reads the token from (SOCKET_SECURITY_API_TOKEN, SOCKET_SECURITY_API_KEY, SOCKET_CLI_API_KEY), which Coana doesn't know. So a token from CI's environment no longer reaches the build tools either. GITHUB_TOKEN and other secrets in the user's environment still do; scrubbing those is the broader policy you describe.
  • Shadow npm and the other spawn sites: agreed, same pattern. socket manifest gradle/sbt and Bazel pass the environment on too. A shared helper that builds the environment for children running build or install code is the right follow-up, kept out of this stack.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[agent] One cleanup outside this diff: spawnSocketCli in test/utils.mts:211-228 lists the four token variable names by hand, twice, to keep them out of the test environment. It could build those exclusions from SOCKET_CLI_API_TOKEN_VARIABLES (it also drops SOCKET_CLI_API_BASE_URL and SOCKET_CLI_ORG_SLUG, which would stay explicit), so a name added to or removed from the list doesn't leave the test helper out of date.

Comment thread src/constants.mts Resolved
Comment thread src/utils/coana-release.test.mts Resolved
Comment thread src/utils/coana-release.mts Resolved
@jfblaa

Copy link
Copy Markdown
Contributor Author

[agent] Fixed in 9ef8c0d - spawnSocketCli in test/utils.mts now builds its exclusions from SOCKET_CLI_API_TOKEN_VARIABLES, plus SOCKET_CLI_API_BASE_URL and SOCKET_CLI_ORG_SLUG, which stay explicit.

Comment thread src/utils/coana-release.mts Resolved
Comment thread src/utils/coana-release.test.mts Resolved

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

I don't know if the test failure needs looking into?

Coana passes its environment on to the build tools and package managers
it runs. It now removes the variables it reads (the API token,
organization, API base URL, proxy, User-Agent, CLI version and
repository name) at startup, so socket-cli sets only those for it.

socket-cli also leaves out the other variables it reads the token from
(SOCKET_SECURITY_API_TOKEN, SOCKET_SECURITY_API_KEY, SOCKET_CLI_API_KEY)
and SOCKET_CLI_CONFIG, which can carry one; Coana reads none of them. It
no longer adds its own normalised settings (constants.processEnv) to
Coana's environment, nor the branch name, which Coana does not read.
@jfblaa

Copy link
Copy Markdown
Contributor Author

[agent] Thanks. The failure was real, not flake: sets the variables Coana reads expected a token, and only got one where socket-cli has a saved login. CI has none, so it failed on every Node version. Fixed in 549e452 - the test now sets its own token through a config override and checks that Coana gets exactly the token socket-cli resolves.

@jfblaa
Jeppe Fredsgaard Blaabjerg (jfblaa) merged commit 5e7464d into v1.x Nov 18, 2026
23 checks passed
@jfblaa
Jeppe Fredsgaard Blaabjerg (jfblaa) deleted the jfblaa/facts-1-coana-env branch November 18, 2026 13:34
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