Protect yourself on Neovim v0.12.5
The fix is on Neovim's release-0.12 branch but not in a release yet. Until it ships, install the fixed netrw file yourself.
-
Download the patched
netrw.viminto your config. Neovim loads it in place of the bundled copy.mkdir -p ~/.config/nvim/autoload && curl -fsSL https://raw.githubusercontent.com/neovim/neovim/release-0.12/runtime/pack/dist/opt/netrw/autoload/netrw.vim -o ~/.config/nvim/autoload/netrw.vim -
Delete your netrw history, which may already hold a planted payload.
rm -f ~/.local/state/nvim/netrw/.netrwhist
Tested against stock v0.12.5: the chain no longer fires and netrw works normally. Remove ~/.config/nvim/autoload/netrw.vim once you upgrade to a fixed release.
nvim . runs the payloadThe bug
The same chain fires through vscode-neovim.
The crafted directory name
assets'|call system('id>PWNED.txt')|let x='
What netrw writes to .netrwhist, with the injected part highlighted
let g:netrw_dirhist_1='/home/victim/totally-normal-project/assets'|call system('id>PWNED.txt')|let x=''
The vulnerable line and the fix in s:NetrwBookHistSave()
- call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")+ call setline(lastline,'let g:netrw_dirhist_'.cnt."=".string(g:netrw_dirhist_{cnt}))
Fixed in vim 9.2.0495, still in Neovim v0.12.5. It needs two directory-browse actions.