Project

General

Profile

RE: File upload virus scanning ยป attachment-patch.txt

Matt Page, 2021-06-03 10:55

 
validate :validate_max_file_size, :validate_file_extension, **:virus_scan**

# Scans the file for viruses
def virus_scan

# write to tmp file
if @temp_file
f = Tempfile.new('av')
f.binmode
if @temp_file.respond_to?(:read)
buffer = ""
while (buffer = @temp_file.read(8192))
f.write(buffer)
end
else
f.write(@temp_file)
end

# hand off to scanner
f.flush
result = %x[ /usr/local/bin/clamd-hook.sh #{f.path} ]
if result.squish == "0"
logger.info('virus detected, file rejected')
errors.add(:base, 'Malware detected!')
end

f.close!

end

end
    (1-1/1)