Skip to main content

Deny access to .svn folders on Apache


We have a rails application in subversion that we deploy with Capistrano but have noticed that we can access the files in '/.svn', which presents a security concern.



I wanted to know what the best way to do this. A few ideas:



  • Global Apache configuration to deny access

  • Adding .htaccess files in the public folder and all subfolders

  • Cap task that changes the permissions



I don't really like the idea of deleting the folders or using svn export, since I would like to keep the 'svn info' around.


Source: Tips4allCCNA FINAL EXAM

Comments

  1. The best option is to use Apache configuration.

    Using htaccess or global configuration depends mainly on if you control your server.

    If you do, you can use something like


    <DirectoryMatch .*\.svn/.*>
    Deny From All
    </DirectoryMatch>


    If you don't, you can do something similar in .htaccess files with FilesMatch

    ReplyDelete
  2. One other way to protect the .svn files would be to use a redirect in the Apache config:

    RedirectMatch 404 /\\.svn(/|$)


    So instead of getting a 403 forbidden (and providing clues to would be attackers) you get a 404, which is what we would expect when randomly typing in paths.

    ReplyDelete
  3. I do not like the idea of 404ing each file startig wit a dot.
    I'd use a more selective approach, either with the cvs I'm using in the project (svn in the example)

    RedirectMatch 404 /\\.svn(/|$)


    or a catch all cvs systems

    RedirectMatch 404 /\\.(svn|git|hg|bzr|cvs)(/|$)


    -- outdated answer follows (see comments) --

    I cant write comments yet so...
    The answer of csexton is incorrect, because an user cannot access the .svn folder, but can access any files inside it !
    e.g. you can access
    http://myserver.com/.svn/entries

    The correct rule is

    RedirectMatch 404 /\\.svn(/.*|$)

    ReplyDelete
  4. I think Riccardo Galli got it right. Even apache already had .svn setup as forbidden for me, but .svn/entries was certainly available...exposing my svn server, port number, usernames, etc.

    I actually figure, why not restrict .git as a preventative measure (say you don't use git yet but may someday at which time you will not be thinking about directory restrictions).

    And then I thought, why not restrict everything that should be hidden anyway? Can anyone conceive of a problem with this?

    RedirectMatch 404 /\\..*(/.*|$)


    I added the '.*' after the initial period - only difference from Riccardo. Seems to 404 .svn, .git, .blah, etc.

    ReplyDelete
  5. A RedirectMatch will respond with a 404, which is great.

    However, if "Options +Indexes" is enabled, then users will still be able to see the '.svn' directory from the Parent directory.

    Users won't be able to enter the directory-- this is where the '404 Not Found' comes in. However, they will be able to see the directory and provide clues to would be attackers.

    ReplyDelete
  6. I seems to me, Apache conf should be :

    <Directory ~ "\.svn">
    Order allow,deny
    Deny from all
    </Directory>

    ReplyDelete
  7. I'm not all that fond of RewriteMatch, so I used a RewriteRule instead:

    RewriteRule /\..*(/.*|$) - [R=404,L]


    The hyphen means "don't do any substitution". I also could not figure out why, in the examples above, the regex had two backslashes:

    /\\..*(/.*|$)


    So I took one out and it works fine. I can't figure out why you would use two there. Someone care to enlighten me?

    ReplyDelete
  8. I would rather deny access to all dot-files (eg: .htaccess, .svn, .xxx, etc.), as they normally don't need to be web-accessible.

    Here's the rule to achieve this:

    <LocationMatch "\/\..*">
    Order allow,deny
    Deny from all
    </LocationMatch>

    ReplyDelete
  9. Create a access rights file in your subversion server installation.

    e.g if you folder structure is

    /svn

    /svn/rights/svnauth.conf

    create a configuration file and enter the path of that file in your apache subversion configuration file which you would normally find at /etc/httpd/conf.d/subversion.conf

    In your svnauth.conf file define the rights as :

    access rights for Foo.com

    [foo.com:/trunk/source]

    dev1=rw

    dev2=rw
    .....

    This way you can control the access rights from one single file and at much granular level.

    For more information peruse through the svn red book.

    ReplyDelete

Post a Comment

Popular posts from this blog

Why is this Javascript much *slower* than its jQuery equivalent?

I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...

Is it possible to have IF statement in an Echo statement in PHP

Thanks in advance. I did look at the other questions/answers that were similar and didn't find exactly what I was looking for. I'm trying to do this, am I on the right path? echo " <div id='tabs-".$match."'> <textarea id='".$match."' name='".$match."'>". if ($COLUMN_NAME === $match) { echo $FIELD_WITH_COLUMN_NAME; } else { } ."</textarea> <script type='text/javascript'> CKEDITOR.replace( '".$match."' ); </script> </div>"; I am getting the following error message in the browser: Parse error: syntax error, unexpected T_IF Please let me know if this is the right way to go about nesting an IF statement inside an echo. Thank you.