Text editors create temporary or ".bak" files, version control systems create "hidden" directories and files. SQL backups are left littering the filesystem, translations, you name it. Database credentials and other sensitive information can be exposed this way. We see this issue cropping up again and again; you may refer to the discussions at #1907704: Restrict temporary files created by text editors and #581706: Protect .git, .hg and .bzr directories in .htaccess for more background. Let's aim to solve the larger problem.
Blacklist solutions such as
<FilesMatch "\.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(\.git.*|\.hg.*|\.bzr.*|\.svn.*|\.cvs.*|Entries.*|Repository|Root|Tag|Template)$">
in .htaccess have been proposed. However, we should be using a whitelist.
Is .htaccess the best way to implement this? Maybe not. In any case, a whitelist makes more sense.
Comments
Comment #1
gregglesI totally agree in theory. However, I'm not sure if we can ever do a whitelist given that path module lets people create "pages" with any extension they want. Maybe there's a way in apache directives to say "only apply this whitelist to actual files on the filesystem"?
Comment #2
mfbAs I mentioned in #581706: Protect .git, .hg and .bzr directories in .htaccess, .well-known is a hidden directory that should be whitelisted (whether the .well-known path is generated by a drupal module or is on the file system), as per https://tools.ietf.org/html/rfc5785
Comment #11
rhovlandComment #12
greggles9 years later and it's time for some updated language.