Repository navigation
Description
Bug report form
- I have done a basic search of the issue tracker to find any existing issues that are similar.
- I have checked that my version is at least the latest stable release available via my installation method.
Describe the bug
nu <script> <args...> turns the arguments into the source main <args> and parses that source again. escape_for_script_arg quotes an argument only when string_should_be_quoted finds a listed special character, and three argument shapes slip through, so they are parsed as code instead of being passed as strings:
- Flag names. For an argument starting with
--, the part before the first=is never checked (L34-L46).--x;print INJECTEDand--x;print INJECTED=1both becomemain --x;print INJECTED..., which runsprint. - Redirection tokens.
o>,e>>,out+err>, and the other redirection forms contain no listed character, sonu script.nu o> fileredirects the script's output intofile(creating or truncating it) instead of passing two strings. - Spreads.
...$vardoes not start with$, so it stays unquoted and...$env.PATHis evaluated and spread into the arguments.
Any wrapper that forwards untrusted strings to nu script.nu is affected. #9939 and #11035 report other symptoms of the same re-parsing, but neither covers these shapes.
How to reproduce
-
Create the script:
'def main [--x, ...args] { $args | to nuon }' | save test.nu
-
From a POSIX shell, run it with each argument shape (the release 0.117.0 binary and the nightly
0.117.0-nightly.1+a481925behave identically):$ nu -n test.nu a 'b c' [a, "b c"] $ nu -n test.nu '--x;print INJECTED' INJECTED $ nu -n test.nu '--x;print INJECTED=1' INJECTED=1 $ nu -n test.nu 'o>' out.txt $ cat out.txt [] $ nu -n test.nu 'out+err>' out.txt $ cat out.txt [] $ nu -n test.nu 'e>>' out.txt [] $ cat out.txt $ env -i PATH=/usr/bin:/bin nu -n test.nu '...$env.PATH' [/usr/bin, /bin]
The first call shows normal behavior. In the flag cases print runs. In the redirection cases out.txt is created and the script receives no arguments. In the spread case the script receives the contents of $env.PATH.
Expected behavior
I expected nu to pass every command-line argument to main as data, the way it handles a and 'b c' above:
'--x;print INJECTED'is rejected as an unknown or malformed flag, or passed as a string, and never runsprint.nu test.nu 'o>' out.txtprints["o>", out.txt]and leavesout.txtuntouched.nu test.nu '...$env.PATH'prints["...$env.PATH"].
A possible fix direction is to treat an argument as a flag only when it is --name or --name=value with a plain identifier name, and to quote every other argument, including redirection tokens and spreads. Building the call from parsed values instead of re-parsing source text would avoid this class of bugs.
Configuration
| key | value |
|---|---|
| version | 0.117.0 |
| major | 0 |
| minor | 117 |
| patch | 0 |
| branch | |
| commit_hash | a481925 |
| build_os | linux-x86_64 |
| build_target | x86_64-unknown-linux-gnu |
| rust_version | rustc 1.97.1 (8bab26f4f 2026-07-14) |
| rust_channel | 1.97.1-x86_64-unknown-linux-gnu |
| cargo_version | cargo 1.97.1 (c980f4866 2026-06-30) |
| build_time | 2026-11-09 21:15:12 +00:00 |
| build_rust_channel | release |
| allocator | standard |
| features | dap, default, lsp, mcp, network, plugin, rustls-tls, sqlite, static-link-openssl, trash-support |
| installed_plugins | |
| experimental_options | example=false, dc-glob=false, reorder-cell-paths=true, pipefail=true, enforce-runtime-annotations=true, native-clip=false, cell-path-types=false |
This is the official 0.117.0 release binary, whose commit is also the current main head. The nightly 0.117.0-nightly.1+a481925 reproduces every case above.
Activity
docs(nushell): name the script argument shapes that run as code
docs(nushell): add script and path rules (#20)
fdncred commentedon Nov 10, 2026
Thanks for reporting this. I don't think it's a regression but definitely a bug. I'll work on it. I think we need to make
escape_for_script_argsmarter.fdncred commentedon Nov 10, 2026
Let me know if this fixes the issue for you #19486
hakula139 commentedon Nov 11, 2026
@fdncred Yes, this fixes the issue in my testing on Linux x86_64 with the CI artifact from run 42862116242, built from PR head 9d674d1 (CI merge commit 6363718).
The original injection-shaped flags now arrive unchanged in
$args, andprintdoes not execute. The redirection-shaped arguments (o>,out+err>,e>>,a>e>without.txt) arrive literally and leave the target's exact bytes untouched, and...$env.PATHstays literal. All 28 checks against the fixture passed, including the broader parser shapes,nu -c, glob and path expansion, typed values, and valid flags. The same harness against official 0.117.0 reproduced the injections, output truncation, and PATH spread.Thanks for the fix.
Stop script arguments from running as code (nushell#19486)