clamby 1.6.1 → 1.6.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cc73965f059691dd46a23b5d0fd7ba7d6e5d1103859bfe68124780c12ca56639
4
- data.tar.gz: f666ead4b14e3dc024ed92ca6842928cc4256d424df0ff25299a7c5eb3c5762f
3
+ metadata.gz: 81853e9529f298f606bb599f22da044e9ada2f805d2d6f6635caac455450e93e
4
+ data.tar.gz: d122cf67adcfd0187c8fabd7153ca7fe20643b075f9bcfe77c8d482075462f74
5
5
  SHA512:
6
- metadata.gz: dcdb2f76042a1cd6751095e30201d635adf0e847defeaeb4d61b174a52ea6c355e4afa567e4770df388b9a2ee79e8c5ef0826486adc46e9ea21d308b4ebc83c8
7
- data.tar.gz: 65beb709c82e4cce7804fe696bbc71d81b6951a2c38cf22ea6c1e2bd42536b55ede204c06a1b78cbba10fe778ef7db0d6b436ec02a80c0e6cafc0b0238bce8f7
6
+ metadata.gz: c56dc7d74dfa3e29eeeca5d44b0cee9fc55efbc55269bcee95cd5108cb8c09ac8faa5a353bd6932ae7602adf1686bec8df4671a5afd57997bb0bdf605d2c2bdc
7
+ data.tar.gz: 85b9072343ce8061cb67ab7607a52570f6d42459e9ad3467c3497c381a9df6cdea3832435dd276e306b1b5fdc1a8bb415940e0a90371027f65497952f215a89b
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
18
  .DS_Store/
19
+ .byebug_history
data/.travis.yml CHANGED
@@ -4,12 +4,14 @@ before_install:
4
4
  - gem install rake
5
5
  - gem install rspec
6
6
  rvm:
7
- - 2.0.0
8
- - 2.1.1
9
7
  - 2.3.4
10
8
  - 2.4.1
11
9
  - 2.5.3
12
- install:
10
+ - 2.6.3
11
+ - 2.6.5
12
+ - 2.6.6
13
+ - 2.7.2
14
+ install:
13
15
  - sudo apt-get install clamav
14
16
  - sudo freshclam
15
17
 
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ # v1.6.8
2
+ - [codezomb](https://github.com/kobaltz/clamby/commits?author=codezomb) - Allow paths to be escaped #37
3
+
4
+ # v1.6.5
5
+ - [bennacer860](https://github.com/kobaltz/clamby/commits?author=bennacer860) - Added config data dir option
6
+
7
+
8
+ # v1.6.2
9
+ - [emilong](https://github.com/kobaltz/clamby/commits?author=emilong) - Handle nil exit status of clamav executable.
10
+
1
11
  # v1.6.1
2
12
  - [broder](https://github.com/kobaltz/clamby/commits?author=broder) - Fixed issue with detecting clamdscan version when using custom config file
3
13
 
@@ -18,7 +28,7 @@
18
28
 
19
29
  # v1.3.2
20
30
  - [emilong](https://github.com/kobaltz/clamby/commits/master?author=emilong) added `stream` option
21
-
31
+
22
32
  # v1.3.1
23
33
  - [zealot128](https://github.com/kobaltz/clamby/commits/master?author=zealot128) added `silence_output` option
24
34
 
@@ -36,7 +46,7 @@
36
46
  - Refactor of logic
37
47
  - Cleanup
38
48
  - Thanks to @hderms for contributing!
39
-
49
+
40
50
  # v1.1.0
41
51
  - Changed `scan()` to `safe?()`
42
52
  - Added `virus?()`
@@ -63,7 +73,7 @@ HTTP request sent, awaiting response... 200 OK
63
73
  Length: 68 [application/octet-stream]
64
74
  Saving to: 'eicar.com'
65
75
 
66
- 100%[=================>] 68 --.-K/s in 0s
76
+ 100%[=================>] 68 --.-K/s in 0s
67
77
 
68
78
  2014-03-10 21:35:50 (13.0 MB/s) - 'eicar.com' saved [68/68]
69
79
 
data/README.md CHANGED
@@ -17,14 +17,14 @@ Just add `gem 'clamby'` to your `Gemfile` and run `bundle install`.
17
17
 
18
18
  You can use two methods to scan a file for a virus:
19
19
 
20
- If you use `safe?` to scan a file, it will return true if no viruses were found, false if a virus was found, and nil if there was a problem finding the file or if there was a problem using `clamscan`
20
+ If you use `safe?` to scan a file, it will return `true` if no viruses were found, `false` if a virus was found, and `nil` if there was a problem finding the file or if there was a problem using `clamscan`
21
21
 
22
- `safe?(path_to_file)`
22
+ `Clamby.safe?(path_to_file)`
23
23
 
24
- If you use `virus?` to scan a file, it will return true if a virus was found, false if no virus was found, and nil if there was a problem finding the file or if there was a problem using `clamscan`
24
+ If you use `virus?` to scan a file, it will return `true` if a virus was found, `false` if no virus was found, and `nil` if there was a problem finding the file or if there was a problem using `clamscan`
25
25
 
26
26
 
27
- `virus?(path_to_file)`
27
+ `Clamby.virus?(path_to_file)`
28
28
 
29
29
  In your model with the uploader, you can add the scanner to a before method to scan the file. When a file is scanned, a successful scan will return `true`. An unsuccessful scan will return `false`. A scan may be unsuccessful for a number of reasons; `clamscan` could not be found, `clamscan` returned a virus, or the file which you were trying to scan could not be found.
30
30
 
@@ -64,6 +64,25 @@ It's good to note that Clamby will not by default delete files which had a virus
64
64
  end
65
65
  ```
66
66
 
67
+ ## with ActiveStorage
68
+
69
+ With ActiveStorage, you don't have access to the file through normal methods, so you'll have to access the file through the `attachment_changes`.
70
+
71
+ ```ruby
72
+ class User < ApplicationRecord
73
+ has_one_attached :avatar
74
+ before_save :scan_for_viruses
75
+
76
+ private
77
+
78
+ def scan_for_viruses
79
+ return unless self.attachment_changes['avatar']
80
+
81
+ path = self.attachment_changes['avatar'].attachable.tempfile.path
82
+ Clamby.safe?(path)
83
+ end
84
+ end
85
+ ```
67
86
 
68
87
  # Configuration
69
88
 
@@ -161,6 +180,11 @@ This opens the root crontab file in a text editor. Add the following line
161
180
 
162
181
  `57 08 * * * sudo freshclam`
163
182
 
183
+ # Contributors
184
+
185
+ <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
186
+ <!-- ALL-CONTRIBUTORS-LIST:END -->
187
+
164
188
  # LICENSE
165
189
 
166
190
  Copyright (c) 2016 kobaltz
data/clamby.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.5"
21
+ spec.add_development_dependency "bundler"
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency "rspec"
24
24
  end
@@ -16,24 +16,28 @@ module Clamby
16
16
  def self.scan(path)
17
17
  return nil unless file_exists?(path)
18
18
 
19
- args = [path, '--no-summary']
19
+ args = [Shellwords.escape(path), '--no-summary']
20
20
 
21
21
  if Clamby.config[:daemonize]
22
22
  args << '--fdpass' if Clamby.config[:fdpass]
23
23
  args << '--stream' if Clamby.config[:stream]
24
24
  end
25
25
 
26
+ args << "-d #{Clamby.config[:datadir]}" if Clamby.config[:datadir]
27
+
26
28
  new.run scan_executable, *args
27
29
 
28
- case $CHILD_STATUS.exitstatus
30
+ # $CHILD_STATUS maybe nil if the execution itself (not the client process)
31
+ # fails
32
+ case $CHILD_STATUS && $CHILD_STATUS.exitstatus
29
33
  when 0
30
34
  return false
31
- when 2
35
+ when nil, 2
32
36
  # clamdscan returns 2 whenever error other than a detection happens
33
37
  if Clamby.config[:error_clamscan_client_error] && Clamby.config[:daemonize]
34
38
  raise Clamby::ClamscanClientError.new("Clamscan client error")
35
39
  end
36
-
40
+
37
41
  # returns true to maintain legacy behavior
38
42
  return true
39
43
  else
@@ -45,7 +49,9 @@ module Clamby
45
49
 
46
50
  # Update the virus definitions.
47
51
  def self.freshclam
48
- new.run 'freshclam'
52
+ args = []
53
+ args << "--datadir=#{Clamby.config[:datadir]}" if Clamby.config[:datadir]
54
+ new.run 'freshclam', *args
49
55
  end
50
56
 
51
57
  # Show the ClamAV version. Also acts as a quick check if ClamAV functions.
@@ -66,7 +72,7 @@ module Clamby
66
72
  self.command = args | default_args
67
73
  self.command = command.sort.unshift(executable_full)
68
74
 
69
- system(*self.command, system_options)
75
+ system(self.command.join(' '), system_options)
70
76
  end
71
77
 
72
78
  private
@@ -1,3 +1,3 @@
1
1
  module Clamby
2
- VERSION = "1.6.1"
2
+ VERSION = "1.6.8"
3
3
  end
data/lib/clamby.rb CHANGED
@@ -15,6 +15,7 @@ module Clamby
15
15
  :fdpass => false,
16
16
  :stream => false,
17
17
  :output_level => 'medium',
18
+ :datadir => nil,
18
19
  :executable_path_clamscan => 'clamscan',
19
20
  :executable_path_clamdscan => 'clamdscan',
20
21
  :executable_path_freshclam => 'freshclam',
@@ -134,9 +134,7 @@ describe Clamby::Command do
134
134
 
135
135
  it 'executes the clamscan executable from the custom path' do
136
136
  expect(runner).to receive(:system).with(
137
- "#{custom_path}/clamscan",
138
- '--no-summary',
139
- good_path,
137
+ "#{custom_path}/clamscan --no-summary #{good_path}",
140
138
  {}
141
139
  ) { system("exit 0", out: File::NULL) }
142
140
 
@@ -149,9 +147,7 @@ describe Clamby::Command do
149
147
 
150
148
  it 'executes the clamdscan executable from the custom path' do
151
149
  expect(runner).to receive(:system).with(
152
- "#{custom_path}/clamdscan",
153
- '--no-summary',
154
- good_path,
150
+ "#{custom_path}/clamdscan --no-summary #{good_path}",
155
151
  {}
156
152
  ) { system("exit 0", out: File::NULL) }
157
153
 
@@ -159,5 +155,11 @@ describe Clamby::Command do
159
155
  end
160
156
  end
161
157
  end
158
+
159
+ describe 'special filenames' do
160
+ it 'does not fail' do
161
+ expect(described_class.scan(special_path)).to be(false)
162
+ end
163
+ end
162
164
  end
163
165
  end
@@ -0,0 +1,2 @@
1
+ This is a virus-free file.
2
+ It is used by automated tests.
@@ -1,4 +1,5 @@
1
1
  RSpec.shared_context 'paths' do
2
+ let(:special_path) { File.expand_path('../../fixtures/safe (special).txt', __FILE__) }
2
3
  let(:good_path) { File.expand_path('../../fixtures/safe.txt', __FILE__) }
3
4
  let(:bad_path) { File.expand_path("not-here/#{rand 10e6}.txt", __FILE__) }
4
5
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clamby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.1
4
+ version: 1.6.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - kobaltz
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-10 00:00:00.000000000 Z
11
+ date: 2021-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.5'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.5'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -79,6 +79,7 @@ files:
79
79
  - spec/.DS_Store
80
80
  - spec/clamby/command_spec.rb
81
81
  - spec/clamby_spec.rb
82
+ - spec/fixtures/safe (special).txt
82
83
  - spec/fixtures/safe.txt
83
84
  - spec/spec_helper.rb
84
85
  - spec/support/shared_context.rb
@@ -86,7 +87,7 @@ homepage: ''
86
87
  licenses:
87
88
  - MIT
88
89
  metadata: {}
89
- post_install_message:
90
+ post_install_message:
90
91
  rdoc_options: []
91
92
  require_paths:
92
93
  - lib
@@ -101,14 +102,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
102
  - !ruby/object:Gem::Version
102
103
  version: '0'
103
104
  requirements: []
104
- rubygems_version: 3.0.2
105
- signing_key:
105
+ rubygems_version: 3.2.32
106
+ signing_key:
106
107
  specification_version: 4
107
108
  summary: Scan file uploads with ClamAV
108
109
  test_files:
109
110
  - spec/.DS_Store
110
111
  - spec/clamby/command_spec.rb
111
112
  - spec/clamby_spec.rb
113
+ - spec/fixtures/safe (special).txt
112
114
  - spec/fixtures/safe.txt
113
115
  - spec/spec_helper.rb
114
116
  - spec/support/shared_context.rb