~ in CLI path arguments is not expanded outside of scan
Version
@openai/codex-security 0.1.1
OS
Windows 11 (root cause applies to any shell/OS that doesn't pre-expand ~ for a program's arguments)
Steps to reproduce
- Run:
codex-security bulk-scan repos.csv --output-dir ~/security-scans
Expected behavior
~ expands to the user's home directory, matching the behavior of codex-security scan, which already expands ~ in its own path arguments.
Observed behavior
~ is treated as a literal folder name. The command writes output to ./~/security-scans instead of $HOME/security-scans, leaving a stray directory named ~ in the current working directory. The same issue affects:
bulk-scan <input-csv>and--output-direxport <scan-dir>,--output,--source-rootscans list <repository>,--scan-rootinstall-hook <repository>- the output directory prompted for in the interactive bulk-scan wizard
Besides writing to the wrong location, resuming a bulk scan from a different working directory fails to find the earlier ledger, since the literal ~ path doesn't resolve consistently.
Suggested fix
Every affected call site in sdk/typescript/src/cli.ts resolves the path with a bare resolve(), which never expands ~. A small wrapper around the existing expandHome helper (already used by scan) fixes it at every call site:
Before:
inputPath = resolve(currentDirectory, args.input);
outputDir = resolve(currentDirectory, options.outputDir);
After:
function resolveCliPath(directory: string, value: string): string {
return resolve(directory, expandHome(value));
}
...
inputPath = resolveCliPath(currentDirectory, args.input);
outputDir = resolveCliPath(currentDirectory, options.outputDir);
The same resolveCliPath swap applies to the other affected arguments: scans list's --repository/--scan-root, export's --output/--source-root, install-hook's repository argument, and the bulk-scan wizard's output-directory prompt.
I independently audited the current public projection and confirmed that the bug is broader than the two bulk-scan call sites, but still has a clean, bounded fix.
Path-typed call sites that should use a shared resolveCliPath(directory, value) helper:
scans list: repository plus both uses of--scan-root(cli.ts)install-hook: repository passed togit -C(cli.ts)bulk-scan: CSV input and output directory (cli.ts)export: scan directory, explicit output, and source root (cli.ts); the--output -stdout sentinel should keep bypassing path resolution- interactive bulk-scan output selection (bulk-scan-discovery.ts)
The existing expandHome behavior is a good compatibility boundary: expand only ~, ~/..., and ~\\...; keep ~user literal.
One guardrail: I would not replace every remaining bare resolve() globally. The validation/patch input path at cli.ts:1918 accepts either a filename or literal finding text, so eager tilde expansion there could reinterpret user text as a file.
Suggested regression coverage (no model or network call needed):
- Pure path cases:
~,~/child,~\\child,~user/child, ordinary relative, and absolute paths. - CLI tests with isolated
HOMEandUSERPROFILEfor each path-typed command above. - A bulk-scan wizard test whose prompt returns
~/custom-results. - Assert that no literal
<cwd>/~directory is created. - Preserve
export --output -unchanged.
This should make the change cross-platform while avoiding accidental expansion of non-path positional input.
Hey Huang, thanks for the comment and further thoughts. For the detailed audit. I implemented the suggested bounded fix in my fork:
- Added a shared
resolveCliPath()for the path-typed CLI inputs you identified. - Expanded
~,~/…, and~\…while preserving~user/…. - Kept non-path inputs and
export --output -unchanged. - Added regression coverage for CLI paths, the bulk-scan wizard, and direct
expandHome()behavior. - Verified that no literal
<cwd>/~directory is created.
I'll link the changes I made on my fork below if you want to see it.
Main fix:
Implementation: https://github.com/Dheerajsom/codex-security/commit/61786cf
Regression coverage: https://github.com/Dheerajsom/codex-security/commit/563c47b0c31524708add217f2fc8967b1045b189
Related closed issue #42 fixed tilde expansion for CODEX_HOME inside configuration preflight only. This issue concerns a different call site: path-valued CLI and bulk-scan arguments. #143 attempted that broader CLI-path fix but was closed without merging, so #42's resolution does not resolve this report and there is currently no active replacement PR.
Fixed on main by #492, which expands home-relative values for the reported CLI and bulk-scan paths. The related knowledge-base path is covered by #254.
Thanks for reporting this. I believe this is resolved by #492, which makes ~ expansion consistent across CLI commands. Please feel free to reopen if you still run into it on the latest version.