fix(vscode): block lifecycle scripts in all dlx commands#3108
Merged
fix(vscode): block lifecycle scripts in all dlx commands#3108
Conversation
…ly chain attacks Several dlx/npx invocations were missing script protection or had --ignore-scripts placed after the package name (where it gets passed to nx instead of npx). Created a shared `buildSafeDlxCommand` helper that returns the correct flag or env var per package manager, and updated all four call sites to use it. Also changed the periodic AI check from a 3-hour repeating interval to a single randomized startup delay since re-checking isn't needed. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
|
View your CI Pipeline Execution ↗ for commit f90602e
☁️ Nx Cloud last updated this comment at |
Contributor
There was a problem hiding this comment.
✅ The fix from Nx Cloud was applied automatically
We ran nx format:write on the two files modified by the PR (apps/vscode/src/nx-init.ts and libs/vscode/mcp/src/lib/periodic-ai-check.ts) to resolve the format:check failure. The PR's code changes were not formatted according to the workspace's Prettier configuration, causing the CI format check to fail. These formatting fixes will allow the format:check task to pass without altering any logic.
Tip
✅ We verified this fix by re-running nx-cloud record -- yarn nx format:check --verbose.
Suggested Fix changes
diff --git a/apps/vscode/src/nx-init.ts b/apps/vscode/src/nx-init.ts
index fda15cca..755b0545 100644
--- a/apps/vscode/src/nx-init.ts
+++ b/apps/vscode/src/nx-init.ts
@@ -41,9 +41,7 @@ export function initNxInit(context: ExtensionContext) {
const packageManagerCommand = await getPackageManagerCommand(
workspacePath ?? '',
);
- const { prefix, env } = buildSafeDlxCommand(
- packageManagerCommand.dlx,
- );
+ const { prefix, env } = buildSafeDlxCommand(packageManagerCommand.dlx);
const command = `${prefix} nx@latest init`;
const task = new Task(
{ type: 'nx' },
diff --git a/libs/vscode/mcp/src/lib/periodic-ai-check.ts b/libs/vscode/mcp/src/lib/periodic-ai-check.ts
index 5e4f450b..06d14140 100644
--- a/libs/vscode/mcp/src/lib/periodic-ai-check.ts
+++ b/libs/vscode/mcp/src/lib/periodic-ai-check.ts
@@ -141,8 +141,7 @@ async function constructCommand(
: buildSafeDlxCommand(packageManagerCommands.dlx, { npxCacheDir });
return {
- command:
- `${prefix} nx@latest configure-ai-agents ${flags}`.trim(),
+ command: `${prefix} nx@latest configure-ai-agents ${flags}`.trim(),
env,
};
}
@@ -677,8 +676,7 @@ async function runAiAgentCheckLegacy() {
source: 'notification',
});
- const { command: setupCmd, env: setupEnv } =
- await constructCommand('');
+ const { command: setupCmd, env: setupEnv } = await constructCommand('');
const task = new Task(
{ type: 'nx' },
TaskScope.Workspace,
🎓 Learn more about Self-Healing CI on nx.dev
Co-authored-by: MaxKless <MaxKless@users.noreply.github.com>
jaysoo
approved these changes
Apr 7, 2026
MaxKless
added a commit
to nrwl/nx
that referenced
this pull request
Apr 8, 2026
## Current Behavior When Nx pulls `nx@latest` into a temporary directory (for example from daemon latest resolution or `configure-ai-agents`/`init` handoff), Yarn Berry can still run lifecycle scripts unless disabled via environment configuration. ## Expected Behavior All temporary `nx@latest` installs disable lifecycle scripts consistently, including Yarn Berry, by always setting `YARN_ENABLE_SCRIPTS=false` in the install process environment. ## Related Issue(s) N/A. Follow-up parity change related to nrwl/nx-console#3108. Fixes #N/A
FrozenPandaz
pushed a commit
to nrwl/nx
that referenced
this pull request
Apr 9, 2026
## Current Behavior When Nx pulls `nx@latest` into a temporary directory (for example from daemon latest resolution or `configure-ai-agents`/`init` handoff), Yarn Berry can still run lifecycle scripts unless disabled via environment configuration. ## Expected Behavior All temporary `nx@latest` installs disable lifecycle scripts consistently, including Yarn Berry, by always setting `YARN_ENABLE_SCRIPTS=false` in the install process environment. ## Related Issue(s) N/A. Follow-up parity change related to nrwl/nx-console#3108. Fixes #N/A (cherry picked from commit 593b8a5)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
npx/yarn dlx/pnpm dlxinvocations either had no--ignore-scriptsprotection or placed the flag after the package name, where it gets passed tonxinstead ofnpx. This is the primary supply chain attack vector — lifecycle scripts from transitive dependencies run during package fetch.buildSafeDlxCommandhelper (libs/shared/npm/src/lib/safe-dlx-command.ts) that returns the correct flag or env var for each package manager:--ignore-scriptsfor npx,YARN_ENABLE_SCRIPTS=falsefor yarn berry,npm_config_ignore_scripts=truefor pnpm, and a no-op for bun.nx-init.ts,periodic-ai-check.ts,get-cloud-onboarding-url.ts, andinit-nx-cloud-view.ts.Key decisions
VAR=value commandsyntax because that doesn't work on Windows.--ignore-scriptsfromdlx, and pnpmdlxdoesn't support it either — both need env vars instead.nx-init.tswas hardcoded tonpxregardless of the user's package manager. Now it detects the PM and uses the helper.