-
Notifications
You must be signed in to change notification settings - Fork 91
fix(cli): sanitize NODE_OPTIONS to prevent --localstorage-file warning #1078
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+254
−6
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| #!/usr/bin/env bash | ||
| # Shell wrapper for llxprt CLI that sanitizes NODE_OPTIONS before invoking node. | ||
| # This prevents warnings from --localstorage-file flags that may be set by IDEs. | ||
|
|
||
| if [[ -n "${NODE_OPTIONS}" ]]; then | ||
| # Remove --localstorage-file with optional value (but don't consume following flags starting with -) | ||
| # Handles: --localstorage-file, --localstorage-file=value, --localstorage-file value | ||
| NODE_OPTIONS=$(echo "${NODE_OPTIONS}" | sed -E 's/(^|[[:space:]])--localstorage-file(=[^[:space:]]*|[[:space:]]+[^-][^[:space:]]*)?//g' | sed -E 's/[[:space:]]+/ /g' | sed -E 's/^[[:space:]]+|[[:space:]]+$//g') | ||
| export NODE_OPTIONS | ||
| fi | ||
|
|
||
| # Get the directory where this script is located | ||
| SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd) | ||
|
|
||
| # Execute the main CLI entry point | ||
| exec node --no-deprecation "${SCRIPT_DIR}/dist/index.js" "$@" |
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| #!/usr/bin/env bash | ||
| # Sanitize NODE_OPTIONS to remove --localstorage-file flags that may cause warnings. | ||
| # This must happen BEFORE node is invoked, since Node parses NODE_OPTIONS at startup. | ||
|
|
||
| if [[ -n "${NODE_OPTIONS}" ]]; then | ||
| # Remove --localstorage-file with optional value (but don't consume following flags starting with -) | ||
| # Handles: --localstorage-file, --localstorage-file=value, --localstorage-file value | ||
| SANITIZED=$(echo "${NODE_OPTIONS}" | sed -E 's/(^|[[:space:]])--localstorage-file(=[^[:space:]]*|[[:space:]]+[^-][^[:space:]]*)?//g' | sed -E 's/[[:space:]]+/ /g' | sed -E 's/^[[:space:]]+|[[:space:]]+$//g') | ||
| export NODE_OPTIONS="${SANITIZED}" | ||
| fi | ||
|
|
||
| # Execute the remaining arguments | ||
| exec "$@" |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2025 Vybestack LLC | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { describe, it, expect } from 'vitest'; | ||
| import { execSync } from 'child_process'; | ||
| import { join, dirname } from 'path'; | ||
| import { fileURLToPath } from 'url'; | ||
|
|
||
| const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
| const scriptPath = join(__dirname, '..', 'sanitize-node-options.sh'); | ||
|
|
||
| function runWithNodeOptions(nodeOptions, command = 'echo "$NODE_OPTIONS"') { | ||
| const env = { ...process.env }; | ||
| if (nodeOptions !== undefined) { | ||
| env.NODE_OPTIONS = nodeOptions; | ||
| } else { | ||
| delete env.NODE_OPTIONS; | ||
| } | ||
|
|
||
| try { | ||
| return execSync(`${scriptPath} bash -c '${command}'`, { | ||
| env, | ||
| encoding: 'utf-8', | ||
| }).trim(); | ||
| } catch (error) { | ||
| throw new Error(`Script failed: ${error.message}`); | ||
| } | ||
| } | ||
|
|
||
| describe('sanitize-node-options.sh', () => { | ||
| it('should remove --localstorage-file without value', () => { | ||
| const result = runWithNodeOptions('--localstorage-file'); | ||
| expect(result).toBe(''); | ||
| }); | ||
|
|
||
| it('should remove --localstorage-file with equals value', () => { | ||
| const result = runWithNodeOptions('--localstorage-file=/some/path'); | ||
| expect(result).toBe(''); | ||
| }); | ||
|
|
||
| it('should remove --localstorage-file with space-separated value', () => { | ||
| const result = runWithNodeOptions('--localstorage-file /some/path'); | ||
| expect(result).toBe(''); | ||
| }); | ||
|
|
||
| it('should preserve other options before --localstorage-file', () => { | ||
| const result = runWithNodeOptions( | ||
| '--max-old-space-size=4096 --localstorage-file', | ||
| ); | ||
| expect(result).toBe('--max-old-space-size=4096'); | ||
| }); | ||
|
|
||
| it('should preserve other options after --localstorage-file', () => { | ||
| const result = runWithNodeOptions( | ||
| '--localstorage-file --enable-source-maps', | ||
| ); | ||
| expect(result).toBe('--enable-source-maps'); | ||
| }); | ||
|
|
||
| it('should preserve options on both sides', () => { | ||
| const result = runWithNodeOptions( | ||
| '--max-old-space-size=4096 --localstorage-file --enable-source-maps', | ||
| ); | ||
| expect(result).toBe('--max-old-space-size=4096 --enable-source-maps'); | ||
| }); | ||
|
|
||
| it('should not modify NODE_OPTIONS when not set', () => { | ||
| const result = runWithNodeOptions(undefined); | ||
| expect(result).toBe(''); | ||
| }); | ||
|
|
||
| it('should handle empty NODE_OPTIONS', () => { | ||
| const result = runWithNodeOptions(''); | ||
| expect(result).toBe(''); | ||
| }); | ||
|
|
||
| it('should pass through to child command', () => { | ||
| const result = runWithNodeOptions( | ||
| '--localstorage-file', | ||
| 'echo "hello world"', | ||
| ); | ||
| expect(result).toBe('hello world'); | ||
| }); | ||
|
|
||
| it('should allow node to run without warning when NODE_OPTIONS has --localstorage-file', () => { | ||
| // This test verifies that node runs successfully without the warning | ||
| const result = runWithNodeOptions( | ||
| '--localstorage-file', | ||
| 'node -e "console.log(\\"success\\")"', | ||
| ); | ||
| expect(result).toBe('success'); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
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.
Check warning
Code scanning / CodeQL
Shell command built from environment values Medium test
Copilot Autofix
AI 8 days ago
In general, to fix this kind of issue you should avoid building a single shell command string that mixes paths and dynamic values. Instead, either (1) call the program directly with
execFileSyncorspawnand pass arguments as an array, or (2) if you must use a shell, provide the command and its arguments via theexecFileSync/spawninterface rather than interpolating them into one string.For this specific code, the best fix with minimal functional change is to replace
execSync’s single-string command with a call that passes the script path and its arguments as an array. The shell semantics we need are: runsanitize-node-options.shwith argumentsbash,-c, and the providedcommandstring. That is equivalent to invokingexecSyncwithscriptPathas the file to execute and['bash', '-c', command]as the arguments. This preserves behavior (including use ofbash -cand the currentcommandstring) while preventingscriptPathfrom being embedded inside a larger shell command, and it stops the shell from re-parsingscriptPath. Concretely, inscripts/tests/sanitize-node-options.test.js, change line 24 to callexecSync(scriptPath, ['bash', '-c', command], { ... })instead of using a template string. No new imports or helper functions are needed.