# Verifying uploaded files with ClamAV before upstream

**URL:** <https://www.ruby-forum.com/t/verifying-uploaded-files-with-clamav-before-upstream/211192>\
**Category:** NGINX\
**Created:** [August 29, 2011, 12:01am UTC](https://www.ruby-forum.com/t/verifying-uploaded-files-with-clamav-before-upstream/211192 "2011-08-29T00:01:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [August 29, 2011, 12:01am UTC](https://www.ruby-forum.com/t/verifying-uploaded-files-with-clamav-before-upstream/211192/1 "2011-08-29T00:01:26Z")

</div>

Hi!

I have a webapp that allows users to upload files. But before that  
webapp sees the files, I need to check them for viruses (with ClamAV).  
Requests are proxied by Nginx with a classic proxy\_pass directive.

I have tried tu use the embedded Perl module, without success.

Specifically, I successfully got access to the body of the client  
request (i.e. the uploaded file’s content), but have problem with the  
reply…

If a virus is found, I want to reply with e.g. “403 Forbidden”. But if  
the file is clean, I want the webapp to get it via proxy\_pass as  
usual. I could only manage either always 403, or always pass to upstream  
☹

Is it possible to do that with the Perl module? I would prefer that  
solution as I don’t have much time for the alternative 🙂

If not, could I write a handler module to do that? I read Evan M.'s  
guide to Nginx modules, but I’m not sure how to pass control to another  
handler in the “no-virus” case.

–  
Jérémie

---

<div class="post-metadata">

**Author:** ![jpi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/cdc98d/32.png) [@jpi](https://www.ruby-forum.com/u/jpi)\
**Post date:** [August 29, 2011, 8:46am UTC](https://www.ruby-forum.com/t/verifying-uploaded-files-with-clamav-before-upstream/211192/2 "2011-08-29T08:46:15Z")

</div>

Take note that while you are processing the content using embedded Perl  
or  
lua, the nginx worker which is processing is blocked, thus not serving  
anything. It migth be a better solution to check for viruses inside your  
webapp.

---

<div class="post-metadata">

**Author:** ![jpi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/cdc98d/32.png) [@jpi](https://www.ruby-forum.com/u/jpi)\
**Post date:** [August 29, 2011, 8:56am UTC](https://www.ruby-forum.com/t/verifying-uploaded-files-with-clamav-before-upstream/211192/3 "2011-08-29T08:56:07Z")

</div>

If you where to create a web service (JSON?) for clamav checking then  
you  
could use asyncronous lua requests to do the virus checking.

---

<div class="post-metadata">

**Author:** ![jpi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/cdc98d/32.png) [@jpi](https://www.ruby-forum.com/u/jpi)\
**Post date:** [August 30, 2011, 2:38am UTC](https://www.ruby-forum.com/t/verifying-uploaded-files-with-clamav-before-upstream/211192/4 "2011-08-30T02:38:11Z")

</div>

Thanks for the answers.

I didn’t knew about embedded Perl blocking the whole Nginx process. So I  
guess it’s not a solution for us ☹

I’ll try asynchronous Lua requests as soon as possible (this week).  
Meanwhile, we’re still investigating the in-house development of a  
dedicated handler module; we’ll eventually need another module someday  
for other purposes…
