]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0481: runtime(netrw): command injection possible via maps v9.2.0481
authorChristian Brabandt <cb@256bit.org>
Thu, 14 May 2026 18:46:56 +0000 (18:46 +0000)
committerChristian Brabandt <cb@256bit.org>
Thu, 14 May 2026 18:52:08 +0000 (18:52 +0000)
Problem:  runtime(netrw): command injection possible via crafted
          directory names in NetrwMaps() (Christopher Lusk)
Solution: Temporarily remove B flag in NetrwMaps() to prevent command
          injection

Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/pack/dist/opt/netrw/autoload/netrw.vim
src/testdir/test_plugin_netrw.vim
src/version.c

index 8681091f09196a43140a5d95339fd9d07683187e..176cdcb87f9fadbd46139b69fd9db68903ec998e 100644 (file)
@@ -4810,6 +4810,12 @@ endfunction
 
 " s:NetrwMaps: {{{2
 function s:NetrwMaps(islocal)
+    " remove B flag from 'cpo' so that \<CR>, \<Bar>, etc. inside
+    " interpolated path names play back as literal text rather than
+    " the actual key — without this, a crafted directory name can
+    " inject keystrokes into the cmdline the mapping is typing
+    let _cpo = &cpo
+    set cpo-=B
 
     " mouse <Plug> maps: {{{3
     if g:netrw_mousemaps && g:netrw_retmap
@@ -5054,6 +5060,7 @@ function s:NetrwMaps(islocal)
         " support user-specified maps
         call netrw#UserMaps(0)
     endif " }}}3
+    let &cpo = _cpo
 endfunction
 
 " s:NetrwCommands: set up commands                              {{{2
index 72bf8300e6ea74b9c768bfb69b954ff85c4a38ff..4256dc9d2a6e2e2c2b5b965b8a1f4acde41c70cb 100644 (file)
@@ -731,6 +731,7 @@ func Test_netrw_mf_command_injection()
   let path = tempname()
   let fname = 'x" . execute("silent! !touch poc") . "'
   call mkdir(path, 'R')
+  let _cwd = getcwd()
   exe "cd " path
   call writefile([], fname)
   Explore .
@@ -738,6 +739,25 @@ func Test_netrw_mf_command_injection()
   :norm mf
   :norm mf
   call assert_false(filereadable('poc'), 'Command injection via mf command')
+  exe "cd " _cwd
+  bw!
 endfunc
 
+function Test_netrw_NetrwMaps_CR_dirname()
+  CheckNotMSWindows
+
+  let tmpdir = tempname() . '/evil<CR>:let g:netrw_pwn=1<CR>'
+  call mkdir(tmpdir, 'pR')
+  call assert_true(isdirectory(tmpdir))
+  exe ":Explore " tmpdir
+  " Fire D
+  " If the commands are injected successfully,
+  " this fails with
+  "  Vim(let):E488: Trailing characters: \ @ command line script
+  call feedkeys("D\<C-c>\<C-c>", "xt")
+  call assert_false(exists("g:netrw_pwn"))
+
+  unlet! g:netrw_pwn
+  bw!
+endfunction
 " vim:ts=8 sts=2 sw=2 et
index df580d3de13cea2966091c869403bf09ac5da16e..10a787cacb11a04d4d8ebcd4b1579bd7522ec00e 100644 (file)
@@ -729,6 +729,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    481,
 /**/
     480,
 /**/