There is a minor security issue where this configuration file could potentially have been previously customized with private information (e.g. the location/configuration of password protected directories, internal proxy configuration etc).
If the site was then moved to Apache based hosting then this information is now visible (e.g. http://www.d8sites.org/web.config).
This is particularly an issue if the rules were not re-implemented in the Apache .htaccess file meaning (for example) a password protected directory is now both unprotected and easily discovered. Obviously the first of these is a serious issue on it's own, but I don't think that is a reason not to prevent the latter.
For the same reasons .htaccess should probably also be blocked in web.config.
| Comment | File | Size | Author |
|---|---|---|---|
| #30 | 2948579-30.patch | 2.64 KB | greggles |
| #27 | interdiff-2948579-15-27.txt | 871 bytes | mcdruid |
| #27 | 2948579-27.patch | 2.65 KB | mcdruid |
| #15 | interdiff.txt | 2.9 KB | longwave |
| #15 | 2948579-15.patch | 2.65 KB | longwave |
Comments
Comment #2
dkan commentedComment #3
chi commentedThis makes sense for me.
Comment #5
interx commentedThe patch works well.
As mentioned, if you have a modified web.config from a previous hosting environment, there might be a potential security issue.
But even if you use an unmodified version it still makes sense to disallow access. On multiple occasions a security audit on a Drupal site mentioned the public access to web.config. Even though it was explicitly mentioned that it was the vanilla version in use, access had to be blocked anyhow. This patch does just that on Apache.
Comment #6
alexpottThis is only doing half of the fix suggested in the issue summary - blocking web.config from .htaccess. It's not blocking .htaccess from web.config - not that I'm sure that that is necessary because it is a hidden file - but I don't know how IIS works. Also I think we should block web.config in the root directory specifically - not all .config files. Plus this is testable in \Drupal\Tests\system\Functional\System\HtaccessTest
Comment #7
gregglesHere's an untested patch that:
* adds blocking for .htaccess from web.config
* adds a test for the htaccess change
@alexpott can you clarify how common you think it is for sites to want to allow downloading a .config file? It seems to me like a sufficiently obscure use case that it would be OK to block by default.
@interX could you review/test again on both apache and iis?
Comment #9
gregglesThe fail was in the test I added, so indeed that needs work.
Comment #10
alexpott@greggles I guess it is super uncommon - but if someone has a site sharing .config files for different .NET configurations then they'd suddenly stop working no?
Comment #11
gregglesWe already block config files in yml so while I agree it could be disruptive it seems like a small price to pay in exchange for the extra security.
Comment #12
alexpott@greggles sure but why not add
|web\.configaftercomposer\.(json|lock)Comment #13
chi commentedI agree
web\.configwill make the intention more clear.Comment #14
interx commentedThe last patch still works for me.
It is possible that web.config includes other .config files with an arbitrary name.
So I think it's a good idea to simply block all .config files, not just web.config. There might be some impact, although this should really be exceptional.
It is safer by default, these are configuration files after all. Like YML-files, if you would want to, you can still allow them to be served by explicitly overriding the rule in your vhost, folder, ...
Comment #15
longwaveThis patch explicitly blocks web.config and .htaccess from web.config itself, and also should fix the tests.
I did also notice that the regexes differ elsewhere in a few places - web.config blocks code-style.pl (not sure why) and what looks like SVN repository files, but not .make files - we should probably open another issue to unify this properly. Both files also block .xtmpl files, which are surely long obsolete.
Comment #16
mcdruid commentedFiled follow-up #3004242: Reconcile "Protect files and directories from prying eyes" patterns in .htaccess and web.config as suggested by @longwave
Comment #17
alexpottI feel that what we're doing here is putting a plaster on a wet leg and really we should be recommending https://www.drupal.org/node/2767907 and in fact deprecating our let's serve all the code because why not pattern.
But +1 to better protection for now.
Comment #18
beckydev commentedTested @longwave's patch in #15 in an Apache environment and can confirm web.config is no longer served up.
Comment #20
sammuell commentedThe pentest tool Nessus Pro regards the presence of a web.config file as a medium threat (web.config File Information Disclosure).
The amount of disclosed information is negligible because Drupal is oss anyway, unless the file has been altered manually. Nontheless, it would be good practice to block access to the file.
Comment #21
beckydev commentedTo echo @sammuell, this has also been flagged in my workplace by Qualys' scanner.
Comment #22
gregglesBumping priority as this does feel at least normal to me.
To folks advocating for this issue - please download the patch, apply it, test it out, confirm it works well for you, test it out in various environments. That will help push it along the most at this point.
Comment #23
mcdruid commentedI manually tested the patch on both webservers.
Apache before:
...and after:
IIS before:
...and after:
I know very little about IIS but it looks like it won't serve out
.htaccessby default - AFAICS requests for any "dotfile" without a file extension result in a 404.With the patch we get a 403 instead though, which makes sense.
This is an older version of IIS on a VM I had lying around, so perhaps someone with a more up-to-date environment and more knowledge of IIS could confirm.
Comment #24
mcdruid commentedD7 port: #3047412: Block web.config in .htaccess (and vice-versa) [D7 port]
Comment #25
rabbitlair commentedI think the patch from #15 can be improved with a couple of minor details:
- The file mode changes for the files
core/modules/system/tests/fixtures/HtaccessTest/.htaccessandcore/modules/system/tests/fixtures/HtaccessTest/web.configmay be not needed- There is a missing slash to escape the dot character on the web.config file name from the Match directive on web.config file (it should be
web\.configinstead ofweb.config)This patch fixes both details.
Comment #27
mcdruid commentedI think those "file mode changes" are actually new 0-byte files which are required for the test.
This patch puts those back in, but adds the slash in to
web\.configas per the last comment by @rabbitlairComment #28
gregglesLooks good to me.
Comment #29
alexpottWhy does this block web.config as well? I would have thought that IIS has this covered - no?
Our .htaccess file should block web.config files and our web.config file should block .htaccess (maybe - personally I have nfi what IIS does with files starting with a . - seems okay to be explicit though). But I can't see a reason why our web.config should be responsible for web.config security on IIS.
Comment #30
gregglesThanks for the feedback, @alexpott. This should be the same as #27 but without blocking web.config in the web.config.
Comment #31
mcdruid commented(edit: I cross-posted with @greggles so I've removed my patches which are likely identical - hopefully the notes about my testing etc... are still of some use though)
Fair enough - you could argue a belt-and-braces approach to try and prevent mis-configured webservers serving out "their own" config file, but in that case we'd want to be consistent and block both files within both files.
Here's the patch with
web.configremoved from the web.config file.I tested this in a newer version of IIS (IIS 10 on Windows Server 2016) on an Azure VM (took a while to figure out that I needed the URL rewrite module and how to obtain and install that... but I digress).
I can confirm that a request for .htaccess yields a 403 with the new rule in place.
Requesting web.config itself produced an informative page including the following details:
So I take this to mean that denying this request is default behaviour in IIS, and that it may be possible to change this behaviour.
The same's typically true for apache and .htaccess as that behaviour is determined by a few lines in the config file e.g.
So unless we want to be extra-paranoid and try to prevent (mis-)configuration of these webservers granting access to their own config files, I think this patch achieves what we set out to do in this issue, and no more.
Back to RTBC (if tests pass).
I'll make the same change in the D7 port issue/patch.
Comment #32
mcdruid commentedTests did pass; so back to RTBC.
Comment #33
alexpottCrediting @DKAN for filing the issue.
Crediting myself, @interX, @beckydev, and @sammuell for issue comments that have helped to move the patch along.
Committed dfa4cde and pushed to 8.8.x. Thanks!
This improvement will ship in 8.8.0 - so in 6 months time but this is not eligible for backport to 8.7.x because it is a task and not a bug.