Skip to content

Commit 7088926

Browse files
committed
patch 9.2.0280: [security]: path traversal issue in zip.vim
Problem: [security]: path traversal issue in zip.vim (Michał Majchrowicz) Solution: Detect more such attacks and warn the user. Github Advisory: GHSA-jc86-w7vm-8p24 Signed-off-by: Christian Brabandt <[email protected]>
1 parent fe05143 commit 7088926

4 files changed

Lines changed: 31 additions & 1 deletion

File tree

runtime/autoload/zip.vim

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
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

src/testdir/samples/evil.zip

265 Bytes
Binary file not shown.

src/testdir/test_plugin_zip.vim

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,3 +274,25 @@ def g:Test_zip_fname_evil_path()
274274
assert_match('zipfile://.*::etc/ax-pwn', @%)
275275
bw
276276
enddef
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

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,8 @@ static char *(features[]) =
734734

735735
static int included_patches[] =
736736
{ /* Add new patch number below this line */
737+
/**/
738+
280,
737739
/**/
738740
279,
739741
/**/

0 commit comments

Comments
 (0)