Drupal: .htaccess Access Deny
August 21, 2014 – 7:59 am | No Comment

In this article I will tell how to forbid access to certain resources for some clients. The instructions will include descriptions of different directives.

Read the full story »
CSS Templates

Contain reviews and news about CSS Templates.

Freebies

Contain freebies such as icons, graphics, headers and images for your websites.

Fun Stuff

Contains other fun stuff for entertainment or interesting site showcase.

How-To

Contain technical elaborations on some specific workarounds or common tweak.

Joomla Templates

Contains reviews and news about Joomla templates.

Home » How-To

Drupal: Secure include()

Submitted by on September 18, 2010 – 4:17 amNo Comment

It is necessary to include files (include) with a maximum safety.

Solution:
Here are PHP functions which include files:

  • include
  • include_once
  • require
  • require_once

Attacks try to execute a code from other site.
To protect yourselves from such attacks you should:

  • Verify passed data.
    Make verification with a regular expression or other data means gotten by a scripts.
  • PHP settings
    Make sure that there are the following strings in php.ini file:allow_url_include = Off //including files forbidden by URL (for non-local files)
    allow_url_fopen = Off //opening URLs forbidden, only local files
    register_globals = Off // disable initialization of global variables
    safe_mode = On //enable safe_mode
  • Use absolute path.
    Include a file with absolute path only. If file doesn’t exist PHP search this file in folders from include_path.
  • Specify files which can be included in a code
    If included files are known, then you should use switch for verification.

    global $page;
    switch ($page)
    {
    case ”:
    include (“pages/main.php”);
    break;
    case ‘page1′:
    include (“pages/folder/page1.php”);
    break;
    }

    It would be better to pass some code as a parameter instead of file name. For example, md5-sum of a path to a file.

  • Verify file existing.
    You can verify if a local file exists with file_exists() function. If there are many files, server may be overloaded – be careful!
  • Limit files uploading
    Limit file extensions users can upload to a server.
  • Exclude from including folders users upload their files to.
    Do not include files from folders with files uploaded by users.
  • Do not include files from system folders.
    Clear paths of this kind “../../../../usr/local/apache/logs/access.log” by stripslashes() function

Leave a comment!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.