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]
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.