Subversion with mod_security

I ran into a bit of an issue while setting up a new subversion server today. On that box we're running mod_security on all vhosts to add another layer of security to our web apps. I got everything configured with the the security, but when I was testing, I kept getting 403 errors when I attempted to get the files in anything other than a web browser.

After scratching my head for a while, I looked at the Apache logs, and noticed that mod_rewrite was causing the issue with lines like this:

[Tue Mar 06 13:46:46 2007] [error] [client xxx.xxx.xxx.xxx] mod_security: Access denied with code 403. Pattern match "!(^$|^application/x-www-form-urlencoded$|^multipart/form-data)" at HEADER("Content-Type") [severity "EMERGENCY"] [hostname "svn.example.com"] [uri "/test"]

I stumbled on Charl van Niekerk's entry on this. One of the comments suggested that the following is the bare minimum to run mod_security on a vhost running subversion:

SecFilterSelective REQUEST_METHOD "^(PROPFIND|PROPPATCH)$" allow
SecFilterSelective REQUEST_METHOD "^(REPORT|OPTIONS)$" allow
SecFilterSelective REQUEST_METHOD "^(MKACTIVITY|CHECKOUT)$" allow
SecFilterSelective REQUEST_METHOD "^(PUT|DELETE|MERGE)$" allow

This should be in the first directives in your mod_security call:

<IfModule mod_security.c>

# Enable ModSecurity
SecFilterEngine On

# Allow SVN requests
   SecFilterSelective REQUEST_METHOD "^(PROPFIND|PROPPATCH)$" allow
   SecFilterSelective REQUEST_METHOD "^(REPORT|OPTIONS)$" allow
   SecFilterSelective REQUEST_METHOD "^(MKACTIVITY|CHECKOUT)$" allow
   SecFilterSelective REQUEST_METHOD "^(PUT|DELETE|MERGE)$" allow

   ...
   # rest of your directives
</IfModule>

If you run a Subversion repository and have run into this issue, these security filters should help!

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
yorch's Gravatar Very usefull! Yesterday I have the same issue. Thanks a lot!
Some minutes ago, I got the error:
mod_security: Access denied with code 500.
When trying to commit changes. I think it has something to do with MKCOL SVN method (access log shows it on the same error's time).
So I added the following line right after the other SVN directives:
SecFilterSelective REQUEST_METHOD "^(MKCOL)$" allow
Now it works.
Hope this helps someone,
Regards,
Yorch.
# Posted By yorch | 3/20/07 12:38 AM
Podcast Hosting's Gravatar good programming, your security mode has solved many problems
# Posted By Podcast Hosting | 9/2/07 8:51 AM
Jack McCoy's Gravatar Very usefull! Yesterday I have the same issue. Thanks a lot!
Some minutes ago, I got the error:
mod_security: Access denied with code 500.
When trying to commit changes. I think it has something to do with MKCOL SVN method (access log shows it on the same error's time).
So I added the following line right after the other SVN directives:
SecFilterSelective REQUEST_METHOD "^(MKCOL)$" allow
Now it works.
Hope this helps someone,
Regards,
Yorch.
# Posted By Jack McCoy | 9/4/07 11:02 PM