9
By default Apache denies access to files whose name begins with .ht
, as an example .htaccess
:
<Files ~ "^\.ht">
Require all denied
</Files>
But I notice that many files use the prefix .
, like the .gitignore
. I believe that this file does no harm, I still think that the use of the point in the prefix is "strongly" directed to configuration files. I think it might be interesting to deny access to these files in general by doing something like:
RewriteEngine On
# Checa se o arquivo existe
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_FILENAME} -f
# Emite status HTTP 403
RewriteRule ^(\.|/\.) - [F,L]
In IIS maybe it’s something like:
<rule name="Redirect to routes" stopProcessing="true">
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<match url="^(\.|/\.)" ignoreCase="false" />
<action type="AbortRequest" />
</rule>
Add the file check because if the file does not exist it should emit 404 and not 403.
This would be a "good use", or maybe the .
as prefix has other uses besides settings files?
If this then trade for a "group" of file types:
(^|/)\.(git|gitignore|yml|svn)$
On Unix file systems, files starting with
.
are considered "hidden", and do not appear when listing the files of a directory usingls
(it must be saidls -a
to see them). Therefore it is common for configuration files to start by the dot, but not necessarily all files starting by the dot are by being configuration. Of course, all of this is orthogonal to the question of whether or not they should be hidden by Apache/IIS; this is a "business" decision for you, and there are no technical arguments either for or against.– Wtrmute
A doubt in htaccess, there is no need to escape the point and bar ?
RewriteRule ^(\.|/\.) - [F,L]
– MagicHat
@Magichat the bar is an escape to the point, in case the point without the backslash would be like saying "match anything, including multiple lines", the
\.
is like saying just point, because this is Regex. Note: the normal bar/
has nothing to do with the escape, it is used to check if the PATH is inside a "folder", like: if you find a file in root^\.
as:.git
, if you find a file inside a folderfoo/bar/.git
– Guilherme Nascimento
@Wtrmute is this same the premise of my thinking and why I formulated the question. Thank you ;)
– Guilherme Nascimento
William, that would be a good use yes. I follow the own Apache who claims to be good practice.
– jzferreira
So, if you really don’t want the guy to know you have those files, launch a 404 even. This is how I want gitlab to do with private projects: those who are outside do not even see the possibility of these projects exist. This gives an extra layer of security, even more if it is something with confidential information, as may be the case of internal files in the directory
.git
– Jefferson Quesado
@Jeffersonquesado is precisely this my doubt, I was thinking of making them purely invisible, ie if creating a route on the type server on wikipedia https://pt.wikipedia.org/wiki/.htaccess the user of a route web framework could create something like wikipedia did, custom page :) Thank you!
– Guilherme Nascimento
Want the answer on ISS or Apache? I got confused.
– Don't Panic
@Everson is not ISS is IIS, is the server used by Microsoft
– Guilherme Nascimento
@Why did you give me a downvote? Seriously I explained to you in a good way, I will not deny your posts because this is not ideal, but really I explained everything to you in a good way, it was the opportunity for you to improve, I did not even deny your answer there, you really think that this was necessary?
– Guilherme Nascimento
@Guilhermenascimento was not actually downvote, but Favorites to see what the correct answer was. But I tried to change and I’m not getting it until the question is edited. Please, I could edit anything to put in the correct option?
– Don't Panic
Corrected! Thank you.
– Don't Panic
@Everson Okay, thank you. I’ll take a look at the RFC if I find something on the subject and let you know, maybe you can formulate an answer ;) ... I wanted to give the opportunity for someone to answer on the subject.
– Guilherme Nascimento