File: 0002-Prevent-directory-traversal-attack.patch

package info (click to toggle)
ruby-mixlib-archive 0.2.0-1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 156 kB
  • ctags: 22
  • sloc: ruby: 233; makefile: 3
file content (41 lines) | stat: -rw-r--r-- 1,483 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
From: Hleb Valoshka <375gnu@gmail.com>
Date: Mon, 17 Jul 2017 17:35:45 +0300
Subject: Prevent directory traversal attack

---
 lib/mixlib/archive.rb       | 2 ++
 spec/mixlib/archive_spec.rb | 4 ++--
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/lib/mixlib/archive.rb b/lib/mixlib/archive.rb
index 478cd96..d22224e 100644
--- a/lib/mixlib/archive.rb
+++ b/lib/mixlib/archive.rb
@@ -21,6 +21,8 @@ module Mixlib
     Log.level = :error
 
     def extract(destination, perms: true, ignore: [])
+      ignore = [/^\.$/, /\.{2}/] + ignore
+
       create_and_empty(destination)
 
       extractor.extract(destination, perms: perms, ignore: ignore)
diff --git a/spec/mixlib/archive_spec.rb b/spec/mixlib/archive_spec.rb
index 2d9b7a7..2055034 100644
--- a/spec/mixlib/archive_spec.rb
+++ b/spec/mixlib/archive_spec.rb
@@ -44,12 +44,12 @@ describe Mixlib::Archive do
     end
 
     it "runs the extractor" do
-      expect(extractor).to receive(:extract).with(destination, { perms: true, ignore: [] })
+      expect(extractor).to receive(:extract).with(destination, { perms: true, ignore: [/^\.$/, /\.{2}/] })
       archive.extract(destination)
     end
 
     it "passes options to the extractor" do
-      expect(extractor).to receive(:extract).with(destination, { perms: false, ignore: [] })
+      expect(extractor).to receive(:extract).with(destination, { perms: false, ignore: [/^\.$/, /\.{2}/] })
       archive.extract(destination, perms: false)
     end
   end