Repository navigation
fix(lsp): bundle LSP servers inherit Gateway secrets - #179415
Conversation
Bundle LSP servers were spawned from the full Gateway process.env (minus the dangerous-key policy), so provider API keys, Gateway and hook tokens and secret-manager credentials reached every plugin-declared language server. Bundle MCP stdio servers, which use the same launch config, already start from the MCP SDK default environment. Start LSP servers from the same MCP defaults plus locale, temp, XDG and toolchain location variables, and keep applying the server's configured env through the existing exec override policy.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR restricts bundled LSP child environments and adds warnings, Doctor diagnostics, and recovery documentation. Example: A bundle starts an LSP server while OPENAI_API_KEY=provider-key-canary and LSP_LOG_LEVEL=verbose is configured.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR fixes credential inheritance that remains on main; the previous findings are resolved, and no blocking defect remains in the reviewed diff. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherEnabled bundle metadata supplies LSP launch configurations; the agent runtime starts owned stdio processes, initializes language servers, and exposes their capabilities as agent tools. flowchart TD
A[Enabled bundle configuration] --> B[LSP runtime]
B --> C[Shared LSP environment policy]
D[Gateway environment] --> C
C --> E[Owned stdio process]
E --> F[LSP agent tools]
C --> G[Warnings and Doctor diagnostics]
Technical reviewBest possible solution: Land the allowlisted environment with the shared diagnostics and documented recovery path. Do we have a high-confidence way to reproduce the issue? Current-main source establishes the inheritance path, and the supplied before/after process-environment and LSP-tool output demonstrate it with synthetic credentials; no target code was executed during this review. Is this the best way to solve the issue? The fix changes the spawning owner, preserves the shared host policy and configured env, and shares diagnostics between runtime and Doctor; the added modules serve the security change and its accepted compatibility recovery. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 1350f617d48d. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +316, Tests +264, Docs +52. Total +632 across 9 files. Added test files: 1. View PR surface stats
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (4 earlier review cycles)
Reviewed October 21, 2026, 9:59 PM ET / October 22, 2026, 01:59 UTC (Revision 5). |
Keep GOMODCACHE and GOBIN in the bundle LSP base env. GOPATH and CARGO_HOME stay dropped by the host exec env policy. Log one warning per server when commonly needed, non-secret Gateway variables (proxy, CA bundle, Python, Node, Go, Rust, JVM, .NET, Android) are set but not passed, split into names the server's env can supply and names the policy refuses there too. Add a matching openclaw doctor note for configured bundle LSP servers, reading the doctor and installed Gateway service environments. Both print names only and skip secret-looking names. Document the LSP server environment and how to pass variables.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Secret scanners flag scheme://user:pass@host literals. Split the synthetic proxy URL so the runtime value and assertions stay identical.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
The host exec env policy lets a child inherit GRADLE_USER_HOME, so bundle LSP servers got it before the allowlist; it is now withheld and the policy refuses it in a server's env. Name it in the docs and pin the behavior.
|
@clawsweeper review |
|
🦞👀 Re-review progress:
|
* fix(lsp): bundle LSP servers inherit Gateway secrets Bundle LSP servers were spawned from the full Gateway process.env (minus the dangerous-key policy), so provider API keys, Gateway and hook tokens and secret-manager credentials reached every plugin-declared language server. Bundle MCP stdio servers, which use the same launch config, already start from the MCP SDK default environment. Start LSP servers from the same MCP defaults plus locale, temp, XDG and toolchain location variables, and keep applying the server's configured env through the existing exec override policy. * fix(lsp): name Gateway env vars bundle LSP servers no longer get Keep GOMODCACHE and GOBIN in the bundle LSP base env. GOPATH and CARGO_HOME stay dropped by the host exec env policy. Log one warning per server when commonly needed, non-secret Gateway variables (proxy, CA bundle, Python, Node, Go, Rust, JVM, .NET, Android) are set but not passed, split into names the server's env can supply and names the policy refuses there too. Add a matching openclaw doctor note for configured bundle LSP servers, reading the doctor and installed Gateway service environments. Both print names only and skip secret-looking names. Document the LSP server environment and how to pass variables. * test(lsp): build credentialed proxy URL fixtures at runtime Secret scanners flag scheme://user:pass@host literals. Split the synthetic proxy URL so the runtime value and assertions stay identical. * fix(doctor): evaluate every workspace's bundle LSP config for withheld env names * docs(lsp): list GRADLE_USER_HOME as newly withheld and refused in env The host exec env policy lets a child inherit GRADLE_USER_HOME, so bundle LSP servers got it before the allowlist; it is now withheld and the policy refuses it in a server's env. Name it in the docs and pin the behavior. --------- Co-authored-by: VACInc <3279061+VACInc@users.noreply.github.com>
Summary
High Level TLDR
Language servers that plugin bundles declare in
.lsp.json(or manifestlspServers) were started with the Gateway's whole environment: provider API keys, Gateway and hook tokens, secret-manager credentials, anything loaded from.env. Bundle MCP stdio servers, which use the samecommand/args/envlaunch config, already start from a short allowlist. This change gives LSP servers the same allowlisted base (plus locale, temp, XDG and toolchain locations language servers read) and keeps the server's ownenvworking. Because some language servers relied on other inherited variables (proxies, CA bundles, virtualenvs), the Gateway now names those variables once per server when it starts one, andopenclaw doctornames them for configured bundle LSP servers, with how to pass each one.What Problem This Solves
Fixes: every bundle-declared LSP server holds a copy of the Gateway's secrets in its process environment for its lifetime, readable from
/proc/<pid>/environby anything running as the same user and inherited by anything the language server starts (build tools, compilers, project scripts).User Impact
Bundle LSP servers no longer receive Gateway credentials. Tools and behavior are unchanged: a real stdio LSP server started through the bundle LSP runtime still initializes, its
lsp_*tool still answers, and its configuredenvstill applies. A language server that relied on some other inherited Gateway variable must now get it another way; the Gateway log andopenclaw doctorname the affected variables (names only), and the docs list exactly what is inherited and how to pass the rest.Upgrade note
HOME,LOGNAME,PATH,TERM,USER(standard system variables on Windows);LANG,LANGUAGE,LC_*,TZ,TMPDIR,TMP,TEMP; theXDG_*base directories;GOROOT,GOMODCACHE,GOBIN,JAVA_HOME,RUSTUP_HOME,RUSTUP_TOOLCHAIN; then the server's ownenv. Everything else in the Gateway environment is no longer passed.HTTP_PROXY,HTTPS_PROXY,ALL_PROXY,NO_PROXY, lowercase forms), CA bundle variables (SSL_CERT_FILE,SSL_CERT_DIR,NODE_EXTRA_CA_CERTS,REQUESTS_CA_BUNDLE,CURL_CA_BUNDLE),GRADLE_USER_HOME(the host exec env policy lets a child inherit it but refuses it in a server'senv), and any variable outside the host exec env policy lists (for exampleCARGO_TARGET_DIR,DOTNET_ROOT,ANDROID_HOME,MAVEN_HOME).GOPATH,CARGO_HOME,GOFLAGS,GOPROXY,GOPRIVATE,VIRTUAL_ENV,CONDA_PREFIX,PYTHONPATH,NODE_OPTIONS,NODE_PATH.bundle-lsp: server "gopls" starts without these Gateway environment variables. DOTNET_ROOT: add to the server's "env" in its bundle .lsp.json if it needs them. HTTPS_PROXY, VIRTUAL_ENV: refused by the host exec env policy, also in "env"; a server that needs them must set them itself (for example, a wrapper script as its "command"). See https://docs.openclaw.ai/plugins/bundles#lsp-server-environment.openclaw doctorprints a "Bundle LSP environment" note with the same split per configured server, reading both the doctor process and the installed Gateway service environment. Only a curated list of commonly needed, non-secret names is reported; values are never printed and names that look like secrets (TOKEN,KEY,SECRET,PASSWORD,CREDENTIAL,AUTH,COOKIE,SESSION) are skipped.envin the bundle.lsp.json. For a name the policy refuses inenvtoo (proxy, CA bundle,VIRTUAL_ENV, Go settings), point the server'scommandat a wrapper script that sets it. Docs: https://docs.openclaw.ai/plugins/bundles#lsp-server-environmentRoot Cause
createBundleLspToolRuntime(); the child's/proc/<pid>/environand the server's own answer through thelsp_hover_*agent tool both showed all four canaries (output below).spawnLspServerProcess()insrc/agents/agent-bundle-lsp-process.tsbuilds the child env withsanitizeHostExecEnv({ baseEnv: process.env, overrides: config.env }). That helper removes only the dangerous-key policy (loader/interpreter pivots), so credentials pass through. The Gateway loads~/.openclaw/.envand config env sources intoprocess.env.OpenClawStdioClientTransport), has started servers from the MCP SDKgetDefaultEnvironment()allowlist (HOME,LOGNAME,PATH,SHELL,TERM,USER; the standard system variables on Windows) plus configuredenvsince5f7b44045dc("fix(mcp): tear down stdio process trees"), matching the SDK's ownStdioClientTransportdefault. The LSP spawner never adopted that base.Why This Change Was Made
spawnLspServerProcess()now passes a base built fromgetDefaultEnvironment()plus a short allowlist copied from the Gateway env:LANG,LANGUAGE,LC_*,TZ,TMPDIR/TMP/TEMP, theXDG_*base directories,GOROOT,GOMODCACHE,GOBIN,JAVA_HOME,RUSTUP_HOME,RUSTUP_TOOLCHAIN(matched case-insensitively on Windows). These are the locations language servers commonly read; none is a credential. They are inherited rather than left to the bundleenvbecause bundle authors, not operators, write thatenv, and the exec override policy already refuses theXDG_*and rustup names there. The base still goes throughsanitizeHostExecEnv(), so the dangerous-key and override policies are unchanged:SHELLis still dropped, andGOPATHandCARGO_HOMEstay dropped because the host exec env policy blocks them on inheritance (they were not inherited before this change either). Keeping those two would mean bypassing that shared policy for LSP only, which this PR does not do.The base env, the withheld-name detection, and the hint text live in
src/agents/agent-bundle-lsp-env.tsand are shared by the spawn-time warning and the doctor note (src/commands/doctor-bundle-lsp-env.ts, contributiondoctor:bundle-lsp-env). Withheld names are classified with the existinginspectHostExecEnvOverrides()policy check, so the hint tells the truth about whether the server'senvcan supply each name. The doctor note loads bundle LSP config for every configured agent workspace, the same per-workspace resolution the runtime uses, and evaluates every workspace's launch config for a server name before merging the names, so a workspace that supplies a variable in itsenvdoes not hide that another workspace's server of the same name lacks it.Scope: bundle LSP servers only. Bundle MCP stdio servers already use the allowlist and are unchanged. Independent of the open Signal daemon (#179198) and hook token (#179199) PRs; no shared code. With #179199, the hook token would also be withheld here, but this change no longer needs it for LSP.
Real behavior proof
Behavior fixed: environment of a bundle-declared LSP server started by the bundle LSP runtime, and the operator-facing warning and doctor note for variables it no longer gets.
Environment: Linux, Node 24.19, this branch and its base
7e3fdabe52a. A script set four synthetic canaries inprocess.env(OPENCLAW_GATEWAY_TOKEN,OPENCLAW_HOOK_TOKEN,OP_CONNECT_TOKEN,OPENAI_API_KEY), wrote a temporary Claude-format bundle whose.lsp.jsondeclares a small real stdio LSP server (Content-Length framed JSON-RPC; answersinitializeandtextDocument/hoverwith which canary names it sees) withenv: { LSP_LOG_LEVEL: "verbose" }, rancreateBundleLspToolRuntime()with the built process owner, executed the resultinglsp_hover_envprobeagent tool, read the server's/proc/<pid>/environ, then disposed the runtime.Before (base):
After (this branch):
The server initialized and answered its tool call in both runs, and the configured
envvalue arrived in both.Warning and doctor note: same real bundle and server, with
HTTPS_PROXY(a URL carrying a fake user and password),NO_PROXY,SSL_CERT_FILE,VIRTUAL_ENV,GOFLAGS,GOPATH,GOMODCACHE,GOBIN,DOTNET_ROOT,OPENAI_API_KEY, andNPM_TOKENset to synthetic values in the Gateway env. The runtime was created twice (two turns), the warnings the runtime logged were captured, and the doctor note was built through the realloadEnabledBundleLspConfig()for the same bundle.Before (previous head
a97b326aa37):After (this head):
OPENAI_API_KEYandNPM_TOKENappear in neither output, and no value appears anywhere.Shipped
openclaw doctor, two workspaces reusing a server name: builtdistfor the previous headc0258c621a6and this head846f7a99a1a, then rannode dist/index.js doctor --non-interactiveunderenv -iwith an isolatedHOME,OPENCLAW_STATE_DIR, andOPENCLAW_CONFIG_PATH(no installed service, Gateway port pinned to an unused port). The config has two agents with separate workspaces. Each workspace holds an enabled workspace Claude bundle (.openclaw/extensions/kotlin-a,kotlin-b) whose.lsp.jsondeclares serverkotlin; workspace A's server setsANDROID_HOMEin itsenv, workspace B's does not. The doctor env hadANDROID_HOMEand a runtime-generatedOPENAI_API_KEYcanary.Before (
c0258c621a6): the contribution ran and printed nothing, because the first workspace'skotlinconfig hid the second.After (
846f7a99a1a):The canary appears 0 times in either full doctor log, and no
ANDROID_HOMEvalue appears.Performance: same host and workload,
createBundleLspToolRuntime()start (spawn plusinitialize) to ready, 1 warmup plus 7 measured starts per run, withHTTPS_PROXY,VIRTUAL_ENV, andDOTNET_ROOTset so the withheld-name check runs. Previous head vs this branch, four interleaved rounds: previous head medians 186.5 / 177.7 / 174.4 / 171.4 ms, this branch 181.3 / 170.4 / 183.6 / 166.9 ms; the final head after the last edit measured 181.5 / 167.7 / 177.3 / 180.2 ms. The ranges overlap and the winner flips between rounds, so there is no measurable difference. The first change (secret scrub) measured the same way against base7e3fdabe52a: base 162.3 / 174.1 / 176.2 / 167.4 ms, scrub 179.5 / 173.8 / 163.3 / 164.7 ms. The change adds one pass over the parent environment and one check of about thirty names per server start.Latest-stable upgrade run through the shipped Gateway and Doctor (added 2026-10-21, head
846f7a99a1a): fully isolated throwaway prefix,HOME,OPENCLAW_HOME,OPENCLAW_STATE_DIR,OPENCLAW_CONFIG_PATH, andXDG_RUNTIME_DIR(no user bus, no installed service), Gateway on an unused loopback port, Node 24.19. The model is a loopback OpenAI-compatible stub so turns complete without a real provider. Gateway env: runtime-generated fakeOPENCLAW_GATEWAY_TOKEN,OPENAI_API_KEY,OPENCLAW_HOOK_TOKEN, plusCARGO_TARGET_DIR,HTTPS_PROXY,NO_PROXY. A Claude-format bundleenvprobe-bundledeclares one stdio LSP serverenvprobethat records the env var names it starts with (names only) and answersinitialize.npm install -g --prefix $T/prefix openclaw@2026.10.5(npmlatest),openclaw plugins install --accept-capabilities ./envprobe-bundle,openclaw gateway run --port <port>, thenopenclaw agent --agent main -m "say hi"through the Gateway (replyprobe ok).distbuilt in the PR worktree,OpenClaw 2026.10.5 (846f7a9)). Ran Doctor the wayopenclaw updatedoes (OPENCLAW_UPDATE_IN_PROGRESS=1 openclaw doctor --fix --non-interactive --no-workspace-suggestions); it migrated the agent database (v25 -> v31) and printed:Credential names appear nowhere in Doctor output, and none of the three fake credential values appears in any log from the run.
probe ok):.lsp.json, added"env": { "CARGO_TARGET_DIR": "<path>" }and pointedcommandat a wrapper script that exportsHTTPS_PROXYandNO_PROXYand then runs the server; re-applied withopenclaw plugins install --force --accept-capabilities ./envprobe-bundle(Applied in Gateway generation 3., no Gateway restart). Next turn (replyprobe ok):The granted
CARGO_TARGET_DIRreaches the server throughenv; the refused names reach it only through the wrapper, which the Gateway warning and Doctor still mention because they cannot see what a wrapper sets. The fake credentials stay withheld after recovery. Throwaway Gateway and stub stopped afterwards.Notes from the run: the PR build's
openclaw doctor --non-interactivewithout--fixstopped at the existing agent database migration gate (stable writes schema v25, this base needs v31), which is the normal stable-to-mainupgrade gate and why step 2 uses the update path's--fix. Hand-editing the installed copy of.lsp.jsonunder the state dir was picked up by Doctor (a fresh process) but not by the already-running Gateway until the bundle was re-applied withplugins install --force; this branch does not touch bundle config loading or caching.What was not tested
lsp_*tool: the upgrade run drives real Gateway turns that start the server, but the stub model makes no tool call.openclaw doctorreading an installed Gateway service environment: all runs above use isolated state with no installed service (the service env read is covered by unit tests). The upgrade run uses this branch's worktreedist, not an npm-packed tarball of it. Thedoctor:bundle-lsp-envcontribution runner (workspace list plus doctor env, likedoctor:web-fetch-proxy) has no dedicated test;doctor-health-contributions.test.tsis at its line-cap ratchet.GRADLE_USER_HOME: these were inherited before and are now withheld, and the host exec env policy also refuses them in a server'senv. The warning, doctor note, and docs name them and the wrapper-script route; this is the compatibility tradeoff.Verification
src/agents/agent-bundle-lsp-runtime.windows-spawn.test.ts: tests for Gateway secrets withheld whilePATH,HOME,LC_ALL,RUSTUP_HOMEare kept; configuredenvstill applied;GOMODCACHE/GOBINkept whileGOPATH/CARGO_HOMEstay dropped; one warning per server across two starts that names withheld variables split by whetherenvcan supply them, never values, neverNPM_TOKEN; and a name the server'senvsupplies is not listed. On the previous head the three new tests fail; with this head all 8 pass. Added on321e3376f43:GRADLE_USER_HOMEsurvives the host exec env policy alone but is withheld from the LSP child and reported as refused (fails whenGRADLE_USER_HOMEis added to the LSP allowlist; 9 pass on this head).src/commands/doctor-bundle-lsp-env.test.ts(8 tests): names per configured server and category, no values or secret names; quiet without runnable bundle LSP servers, without any listed variable set, and for remote Gateways; omits names a server'senvsupplies; evaluates each workspace's config when two workspaces reuse a server name (fails onc0258c621a6: no note; passes on846f7a99a1a); includes the installed Gateway service environment; does not read the service for a non-default install identity.agent-bundle-lsp-runtime.test.ts,doctor-health-contributions.test.ts,doctor-health.update-scope.test.ts,host-env-security.test.tsstill pass (138 tests across the 6 files).pnpm check:changedon846f7a99a1a: all lanes pass (typecheck core and core tests, lint, format, deprecated API, mock export, line-cap ratchets) except two that fail on things this branch does not touch: the max-lines suppression ratchet (threeui/srcfiles) and the advisory core test shard root budget (shardsagents-root,agents-tools,gateway-root,infra,plugins-platformalready over 720 roots on the base; the new test file is outside those shards).pnpm docs:check-links:anchors: no findings fordocs/plugins/bundles.md(the new#lsp-server-environmentanchor resolves); the remaining findings are in unrelated pages.CI run 39616436281 on head
f33802d5bf6: the one failed job,checks-node-changed-compact-large-15(job), and theopenclaw/ci-gatered that follows from it are inherited frommain, not caused by this branch.pr-failure-reportprinted "Classification unavailable", so the comparison was done by hand. All 6 failures are insrc/commands/cleanup-live-state.test.ts(registered reset/uninstall workspace guard > handles workspace warning ..., lines 185 and 192). The error isCannot safely remove OpenClaw state because workspace configuration could not be resolved: agents.defaults: Unrecognized key: "heartbeat". The newest completed scheduledmainCI run, 39608923095 (bedbf6761e0), fails the same 6 tests with the same message inchecks-node-compact-small-9(job). The fixture atcleanup-live-state.test.ts:164still setsagents.defaults.heartbeat, which became an unrecognized key onmainafter feat(automations): migrate heartbeat jobs through Doctor #179387. This branch does not touch that test, the cleanup command, or the config schema. The security review on this head passed.CI run 39622230808 on head
c0258c621a6: the failed jobchecks-node-changed-compact-large-13is the same inheritedsrc/commands/cleanup-live-state.test.tsfailure described above (registered reset/uninstall workspace guard > handles workspace warning ...).CI run 39670707818 on head
846f7a99a1a: the failed jobchecks-node-changed-compact-large-6(job) and theopenclaw/ci-gatered that follows from it are inherited frommain, not caused by this branch. The one failure issrc/cli/gateway-status-route-cold-imports.test.ts > keeps plain-config status off the full config runtime(expected true to be falseat line 93). ScheduledmainCI runs 39662150265 (a24b17a9227,checks-node-compact-small-34, job) and 39654415683 (2a597857a05) fail the same test with the same assertion. Locally the test passes on this branch's base and on this head, and fails on plainmainata83e3190ce6(themaincommit CI merged this head into) and at548a331adb1.git bisectbetween this branch's base anda83e3190ce6names37e2f26636e(fix(status): reconcile degraded secret diagnostics #126786) as the first failing commit. This branch does not touch the gateway status route,src/config/io.runtime.ts, or that test.