Grav: Disable direct access to .MD files via .htaccess

Created on 16 Oct 2015  路  5Comments  路  Source: getgrav/grav

And all other files that should not be exposed from the site root folder

enhancement

Most helpful comment

Apache warns against (over)use of modrewrit: https://httpd.apache.org/docs/2.4/rewrite/avoid.html
You should use RedirectMatch, for example like this:

## Begin - Security
# Block all direct access for these folders
RedirectMatch 404 (.git|tests|.AbiSuite|nbproject|.idea)
# Block access to specific file types for these system folders
RedirectMatch 404 (vendor)/(.*)\.(txt|xml|md|html|yaml|php|pl|py|cgi|twig|sh|bat|dist|json|exe)
# Block all direct access to .md files:
RedirectMatch 404 \.md
# Block access to specific files in the root folder
RedirectMatch 404 (composer.lock|composer.json|\.htaccess|LICENSE)
## End - Security

All 5 comments

If you give me the ok, I'll add the same for

  • .dependencies
  • .editorconfig
  • .gitignore
  • composer.json
  • composer.lock
  • LICENSE
  • nginx.conf
  • web.config

I guess its not a bad idea to have those blocked too. So yup :)

Apache warns against (over)use of modrewrit: https://httpd.apache.org/docs/2.4/rewrite/avoid.html
You should use RedirectMatch, for example like this:

## Begin - Security
# Block all direct access for these folders
RedirectMatch 404 (.git|tests|.AbiSuite|nbproject|.idea)
# Block access to specific file types for these system folders
RedirectMatch 404 (vendor)/(.*)\.(txt|xml|md|html|yaml|php|pl|py|cgi|twig|sh|bat|dist|json|exe)
# Block all direct access to .md files:
RedirectMatch 404 \.md
# Block access to specific files in the root folder
RedirectMatch 404 (composer.lock|composer.json|\.htaccess|LICENSE)
## End - Security

It's a good suggestion, however it poses another requirement for Grav on mod_alias, which might be an issue, or not.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghtmtt picture ghtmtt  路  3Comments

fvsch picture fvsch  路  3Comments

vico93 picture vico93  路  5Comments

bmrankin picture bmrankin  路  3Comments

tdulieu picture tdulieu  路  3Comments