Re: Preventing SQL Injection/ Cross Site Scripting

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Eric Butera wrote:
One thing you might want to keep in mind is that this little "fix" is
going to get executed on each request if you just throw it in an
include.
...big snip...

That means lots function calls happened before you could even say
hello world.  You might want to add wrapper functions accessor
functions around $_GET and $_POST so that you're only stripping when
really necessary.

You could always take out the lines from that "fix" which you don't need.
For example, if you use the $_POST[] array, you probably don't need to fix $HTTP_POST_VARS too, and if you don't use cookies at all, there's no need to spend CPU cycles un-magic_quote_gpc'ing any of the cookie stuff.

The problem with wrappers is they're always executed, even for people who don't have the magic quotes problem. What I liked about lumping it all together as a massive operation at the start is I could put my fix in a single if() block to skip it if it's not necessary. Those who have PHP installations that aren't tainted with magic_quotes_gpc can run the script with almost no performance hit at all... faster than if the script had wrappers. It also keeps the rest of the code pretty. ;-)

If you're frequently accessing a superglobal through a wrapper (for example in a loop where you compare it with values in a long array or something), you're still back to executing several function calls. That's just "out of the frying pan and into the fire". Of course a smart optimization would be to call the wrapper only once, declare a variable to store the result, and use this variable for comparison inside your loop.

Now if we extend that mentality even further we can declare the variable as global at the start of the script and call the wrapper only once at the start too! Now we've essentially created an un-magic_quote_gpc'd copy of the superglobal. So the next logical thought is "if we're never using the magic quoted value in the code, why make a *copy* of the superglobal? Why not just operate *directly* on it?".

That's the train of thought that led to my little fix anyhow.  :-)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux