Jump to content

PHP INCLUDE CODE-SECURITY ADVICE PLEASE


flashback

Recommended Posts

[quote author=Branden Wagner link=topic=101505.msg401828#msg401828 date=1153608019]they way i do it is by folder

include("includes/". $_REQUEST['file']);[/quote]

This doesn't make any sense, if you don't use a function like basename(). Otherwise the "hacker" can still put something like file=../../top.secret in the request data and access more or less everything the webserver user is allowed to.

Better take an array with elements containing the allowed files, something like:

[code=php:0]<?php
$includes = array(
              'news' => 'news.html',
              'home' => 'home.html',
              //      ...
            );
                     
if (!empty($_GET['id']) && isset($includes[$_GET['id']])) {
    $include = $_GET['id'];
} else {
    $include = 'news';
}

include $includes[$include];
?>[/code]
Maybe not the most helpful advice, but [b]never trust user input[/b]!

$_REQUEST is supplied directly by the user, and so it is pure madness to call files based on this input.

I would suggest that you need to rethink your structure from scratch, if security is something you are concerned about.

At a bare minimum,you need to analyse (and sanitise) this data in order that it can only match pages that you intend to be public.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.