File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2020" 2025 Dec 20 by Vim Project: use :lcd instead of :cd
2121" 2026 Feb 08 by Vim Project: use system() instead of :!
2222" 2026 Mar 08 by Vim Project: Make ZipUpdatePS() check for powershell
23+ " 2026 Apr 01 by Vim Project: Detect more path traversal attacks
2324" License: Vim License (see vim's :help license)
2425" Copyright: Copyright (C) 2005-2019 Charles E. Campbell {{{1
2526" Permission is hereby granted to use and distribute this code,
@@ -367,6 +368,11 @@ fun! zip#Write(fname)
367368 return
368369 endif
369370
371+ if simplify (a: fname ) = ~ ' \.\.[/\\]'
372+ call s: Mess (' Error' , " ***error*** (zip#Write) Path Traversal Attack detected, not writing!" )
373+ return
374+ endif
375+
370376 let curdir= getcwd ()
371377 let tmpdir= tempname ()
372378 if tmpdir = ~ ' \.'
@@ -481,7 +487,7 @@ fun! zip#Extract()
481487 if fname = ~ ' /$'
482488 call s: Mess (' Error' , " ***error*** (zip#Extract) Please specify a file, not a directory" )
483489 return
484- elseif fname = ~ ' ^[.]\?[.]/'
490+ elseif fname = ~ ' ^[.]\?[.]/' || simplify (fname) = ~ ' \.\.[/\\] '
485491 call s: Mess (' Error' , " ***error*** (zip#Browse) Path Traversal Attack detected, not extracting!" )
486492 return
487493 endif
Original file line number Diff line number Diff line change @@ -274,3 +274,25 @@ def g:Test_zip_fname_evil_path()
274274 assert_match (' zipfile://.*::etc/ax-pwn' , @% )
275275 bw
276276enddef
277+
278+ def g: Test_zip_fname_evil_path2 ()
279+ CheckNotMSWindows
280+ # needed for writing the zip file
281+ CheckExecutable zip
282+
283+ CopyZipFile (" evil.zip" )
284+ defer delete (" X.zip" )
285+ e X.zip
286+
287+ :1
288+ var fname = ' foobar'
289+ search (' \V' .. fname)
290+ exe " normal \<cr> "
291+ normal x
292+ assert_false (filereadable (' /tmp/foobar' ))
293+ :w
294+ var mess = execute (' :mess' )
295+ assert_match (' Path Traversal Attack' , mess)
296+ assert_match (' zipfile://.*::.*tmp/foobar' , @% )
297+ bw !
298+ enddef
Original file line number Diff line number Diff line change @@ -734,6 +734,8 @@ static char *(features[]) =
734734
735735static int included_patches [] =
736736{ /* Add new patch number below this line */
737+ /**/
738+ 280 ,
737739/**/
738740 279 ,
739741/**/
You can’t perform that action at this time.
0 commit comments