Repository navigation
fix: recognize the offckb daemon when its CLI path contains spaces #533
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
8effa01
fix: recognize the offckb daemon when its CLI path contains spaces
humble-little-bear b0b7da7
fix: compare daemon paths with the host path module, not process.plat…
humble-little-bear 06d53c2
test: keep the real stale-miner process listing out of node command u…
humble-little-bear 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@offckb/cli': patch | ||
| --- | ||
|
|
||
| - daemon: identify a running offckb daemon by anchoring the node executable and CLI script path in the process command line, so `offckb node stop` works when the CLI path contains spaces (e.g. macOS `~/Library/Application Support/...`) |
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,75 @@ | ||
| import path from 'path'; | ||
| import { commandLineRunsScript } from '../src/util/daemon'; | ||
|
|
||
| const POSIX_NODE = '/usr/local/bin/node'; | ||
| const WIN_NODE = 'C:\\Program Files\\nodejs\\node.exe'; | ||
|
|
||
| describe('commandLineRunsScript (posix)', () => { | ||
| const script = '/Users/dev/Library/Application Support/offckb-nodejs/build/index.js'; | ||
|
|
||
| it('matches an unquoted ps -o args= line whose paths contain spaces', () => { | ||
| expect(commandLineRunsScript(`${POSIX_NODE} ${script} node --daemon`, script, 'darwin')).toBe(true); | ||
| expect(commandLineRunsScript(`/usr/bin/node ${script}`, script, 'linux')).toBe(true); | ||
| expect(commandLineRunsScript(`nodejs ${script} fiber start --daemon`, script, 'linux')).toBe(true); | ||
| }); | ||
|
|
||
| it('matches when the node executable itself also lives under a spaced path', () => { | ||
| const node = '/Users/dev/Library/Application Support/fnm/node'; | ||
| expect(commandLineRunsScript(`${node} ${script} node`, script, 'darwin')).toBe(true); | ||
| }); | ||
|
|
||
| it('rejects a foreign script, a truncated script and a non-node host', () => { | ||
| expect(commandLineRunsScript(`${POSIX_NODE} ${script}-other node`, script, 'darwin')).toBe(false); | ||
| expect(commandLineRunsScript(`${POSIX_NODE} ${script.slice(0, -3)} node`, script, 'darwin')).toBe(false); | ||
| expect(commandLineRunsScript(`/bin/bash ${script}`, script, 'darwin')).toBe(false); | ||
| expect(commandLineRunsScript(`${POSIX_NODE}`, script, 'darwin')).toBe(false); | ||
| expect(commandLineRunsScript('', script, 'darwin')).toBe(false); | ||
| }); | ||
|
|
||
| it('rejects a path that only shares a prefix with the expected script', () => { | ||
| expect( | ||
| commandLineRunsScript( | ||
| `${POSIX_NODE} /Users/dev/Library/Application Support/offckb-nodejs/build/index.js.bak node`, | ||
| script, | ||
| 'darwin', | ||
| ), | ||
| ).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('commandLineRunsScript (windows)', () => { | ||
| const script = 'C:\\Users\\Jane Doe\\AppData\\Local\\offckb-nodejs\\build\\index.js'; | ||
|
|
||
| it('matches a Win32_Process CommandLine that quotes arguments containing spaces', () => { | ||
| expect(commandLineRunsScript(`"${WIN_NODE}" "${script}" node --daemon`, script, 'win32')).toBe(true); | ||
| expect(commandLineRunsScript(`"${WIN_NODE}" "${script}"`, script, 'win32')).toBe(true); | ||
| }); | ||
|
|
||
| it('matches when only the script needs quoting', () => { | ||
| expect(commandLineRunsScript(`C:\\nodejs\\node.exe "${script}" node`, script, 'win32')).toBe(true); | ||
| }); | ||
|
|
||
| it('matches an unquoted Windows command line when neither path has spaces', () => { | ||
| const plain = 'C:\\offckb\\build\\index.js'; | ||
| expect(commandLineRunsScript(`C:\\nodejs\\node.exe ${plain} node --daemon`, plain, 'win32')).toBe(true); | ||
| }); | ||
|
|
||
| it('rejects a foreign script and a non-node host, case-insensitively for the script', () => { | ||
| expect(commandLineRunsScript(`"${WIN_NODE}" "${script}.bak"`, script, 'win32')).toBe(false); | ||
| expect(commandLineRunsScript(`"C:\\Windows\\System32\\cmd.exe" "${script}"`, script, 'win32')).toBe(false); | ||
| expect( | ||
| commandLineRunsScript( | ||
| `"${WIN_NODE}" "C:\\Users\\Jane Doe\\AppData\\Local\\offckb-nodejs\\build\\INDEX.JS" node`, | ||
| script, | ||
| 'win32', | ||
| ), | ||
| ).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| describe('commandLineRunsScript (posix absolute paths without spaces still work)', () => { | ||
| it('matches a simple absolute path', () => { | ||
| const script = path.posix.join('/opt', 'offckb', 'build', 'index.js'); | ||
| expect(commandLineRunsScript(`${POSIX_NODE} ${script} node`, script, 'linux')).toBe(true); | ||
| }); | ||
| }); |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
rg -n 'OFFCKB_CLI_PATH|beforeEach|afterEach|afterAll|beforeAll' tests/daemon-locale.test.tsRepository: ckb-devrel/offckb
Length of output: 577
🏁 Script executed:
Repository: ckb-devrel/offckb
Length of output: 5169
Clean up the temporary directory in
finally.afterEachalready restoresprocess.env.OFFCKB_CLI_PATH. However, a failed assertion beforefs.rmSyncleaves the temporary directory behind. Wrap the test body intry/finallyand keep the existing environment restoration.♻️ Suggested fix
process.env.OFFCKB_CLI_PATH = script; const startedAt = new Date(2026, 7, 13, 12, 36, 26); + try { mockExecFile.mockImplementation((file: string, args: string[], options: any, callback?: any) => { const cb = typeof options === 'function' ? options : callback; if (file === 'ps') { @@ - fs.rmSync(dir, { recursive: true, force: true }); + } finally { + fs.rmSync(dir, { recursive: true, force: true }); + }🧰 Tools
🪛 ast-grep (0.45.3)
[warning] 165-165: Filesystem path is not a string literal; a request-/variable-derived path can enable path traversal. Validate and normalize the path before use.
Context: fs.writeFileSync(script, '')
Note: [CWE-22] Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
(detect-non-literal-fs-filename-typescript)
🤖 Prompt for AI Agents