Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

register_globals on / off - I think I'm missing the point

1 view
Skip to first unread message

+mrcakey

unread,
Oct 24, 2007, 6:57:09 AM10/24/07
to
I understand that register_globals was turned off by default as, unless
you initialised it, it could be altered by a malicious coder.

What I don't understand is how the $_POST['foo'] form is any more
secure. Surely Mr Malicious Coder can still just send his own version
of $_POST['foo']?

Obviously I'm missing something, I just can't figure out what!

+mrcakey

C. (http://symcbean.blogspot.com/)

unread,
Oct 24, 2007, 7:15:00 AM10/24/07
to

On its own, it probably isn't a big problem - its how it interacts
with the rest of the code e.g.:

<?php
require_once("array_of_admin_users.inc.php");
if (in_array($admin_users, $_SESSION['user'])) {
$admin_user=true;
}

if ($admin_user) { ...

What happens when a non-admin users connects using
http://example.com/transfer_funds.php?admin_user=1 ?

See also http://pear.reversefold.com/dokuwiki/doku.php?id=phpfaqs#why_is_register_globals_bad

C.


Steve

unread,
Oct 24, 2007, 9:08:04 AM10/24/07
to

"C. (http://symcbean.blogspot.com/)" <colin.m...@gmail.com> wrote in
message news:1193224500....@e9g2000prf.googlegroups.com...

> On 24 Oct, 11:57, +mrcakey <mrca...@nospam.nospam> wrote:
>> I understand that register_globals was turned off by default as, unless
>> you initialised it, it could be altered by a malicious coder.
>>
>> What I don't understand is how the $_POST['foo'] form is any more
>> secure. Surely Mr Malicious Coder can still just send his own version
>> of $_POST['foo']?
>>
>> Obviously I'm missing something, I just can't figure out what!
>>
>> +mrcakey
>
> On its own, it probably isn't a big problem - its how it interacts
> with the rest of the code e.g.:
>
> <?php
> require_once("array_of_admin_users.inc.php");
> if (in_array($admin_users, $_SESSION['user'])) {
> $admin_user=true;
> }
>
> if ($admin_user) { ...

based on that code, nothing.


AnrDaemon

unread,
Oct 24, 2007, 10:45:08 AM10/24/07
to
Greetings, +mrcakey.
In reply to Your message dated Wednesday, October 24, 2007, 14:57:09,

m> I understand that register_globals was turned off by default as, unless
m> you initialised it, it could be altered by a malicious coder.

m> What I don't understand is how the $_POST['foo'] form is any more
m> secure.

It is more secure, than $foo. For sure.

m> Surely Mr Malicious Coder can still just send his own version
m> of $_POST['foo']?

Yep, but You can't accidentally fetch it by using $foo somewhere in Your
script.
You should call $_POST['foo'] explicitly to deal with user input.

m> Obviously I'm missing something, I just can't figure out what!

Hope I've explained it enough to give You a point.


--
Sincerely Yours, AnrDaemon <anrd...@freemail.ru>

+mrcakey

unread,
Oct 31, 2007, 12:36:02 PM10/31/07
to

Essentially then register_globals exposes ALL your variables to attack
from outside rather than just those you're fetching explicitly from
$_GET, $_POST etc. I understand now. Thanks to all who replied.

+mrcakey

la...@portcommodore.com

unread,
Oct 31, 2007, 4:31:35 PM10/31/07
to
On Oct 31, 9:36 am, +mrcakey <mrca...@nospam.nospam> wrote:

> Essentially then register_globals exposes ALL your variables to attack
> from outside rather than just those you're fetching explicitly from
> $_GET, $_POST etc. I understand now. Thanks to all who replied.
>
> +mrcakey

Note: If you can't be sure your code is going to be always in a
globals off environment, it is recommended all variables used in the
script are initialized early on in the script (even the empty ones).
Also one gotcha with globals on is if you do $foo = $_POST['foo'];
don't initialize $foo until you've made sure $_POST['foo'] is empty.


NC

unread,
Oct 31, 2007, 5:48:22 PM10/31/07
to

What you are missing is a realization that with register_globals = On,
the malicious coder can initialize ANY variable, regardless of whether
the script expects to receive it via CGI.

Let's say, you have something like this:

// Tons of code here...
// The script processes incoming data and, depending on the
// program flow, may or may not initialize the $bar variable.
if (isset($bar)) {
$result = mysql_query("DELETE FROM the_table WHERE bar='$bar'");
}
// Tons of code here too...

Now let's say that register_globals = On and malicious coder
submitted
$_REQUEST['bar'] = '%'. The server receives it and initializes $bar =
'%'. If $bar is not changed elsewhere, the script issues the
following MySQL query:

DELETE FROM the_table WHERE bar='%'

meaning, delete all records from the_table.

Granted, the above example is not a good coding practice, but with
register_globals = Off it is still safe (the malicious user cannot
initialize $bar and thus alter the program flow), while with
register_globals = On it is a security risk.

Cheers,
NC

Gordon Burditt

unread,
Oct 31, 2007, 9:44:50 PM10/31/07
to
>DELETE FROM the_table WHERE bar='%'
>
>meaning, delete all records from the_table.

No, that's not what it means.

DELETE FROM the_table WHERE bar LIKE '%'

means delete all records from the_table. The first query means delete
all records where bar is of length one and contains a single percent sign.

Lesson here: use = instead of LIKE unless you actually *need*
pattern-matching. Also, turn off register_globals.


NC

unread,
Nov 1, 2007, 4:15:06 PM11/1/07
to
On Oct 31, 6:44 pm, gordonb.kw...@burditt.org (Gordon Burditt) wrote:
>
> > DELETE FROM the_table WHERE bar='%'
>
> > meaning, delete all records from the_table.
>
> No, that's not what it means.
>
> DELETE FROM the_table WHERE bar LIKE '%'
>
> means delete all records from the_table. The first query
> means delete all records where bar is of length one and
> contains a single percent sign.

You're right, of course. I just wanted a simple illustration, so I
misinterpreted the meaning of the SQL query to make a point. In the
real world, the attacker would use something like:

$_REQUEST['bar'] = "' OR bar LIKE '%"

Cheers,
NC

0 new messages