More on cleaning input data3rd July 2005, 972 views When you code with register_globals and magic_quotes_gpc off, it's easy to forget that some people do actually use them. Subsequently it's quite easy to inadvertently introduce vulnerabilities into your code when it's used on such a platform. The following code can be dropped into your app, into a common include for example, to fix this. Simply call dispelGlobals() and dispelMagicQuotes() and stop worrying.
<?php
Top 10 referrering pages
Link to meIf you use any of the code on this site (and if you don't I guess) or it makes your life easier, I'd appreciate a link - http://www.phpguru.org. Thanks!
Author: Richard Heyes
Posted: 3rd July 2005 18:10 David:
Quote> What's wrong with ini_set("register_globals", 0) > and ini_set("magic_quotes_gpc", 0)? It doesn't work, that's what.
Author: Julian Triber
Posted: 4th July 2005 04:06 Hey,
QuoteI already have something like your strip slashes function, but mine is an explicit call, and I run trim() while im stripping slashes, or just trim in the event that macgic quotes is not set. I would also point out that dispellGlobals hides the real issue, uninitlized variables. If you set error_reporting(E_ALL | E_NOTICE); when you code your going to elimiate the problem rather than treating the symptom.
Author: Chris Shiflett
Posted: 4th July 2005 05:19 In Richard's defense, this has little to do with treating a symptom. Yes, you should develop with E_ALL or E_STRICT to be alerted to the use of uninitialized variables, but that doesn't mean it's fine to enable register_globals if you follow this practice.
QuoteA lot of security has to do with theory, and this is one of them. The principle of Defense in Depth tells us that redundant safeguards have value. If you have a gas line in your house that has been known to leak, do you use a blowtorch around it? Do you try to make sure the leak is fixed? I'd suggest fixing the leak AND keeping blowtorches away. Defense in Depth.
Author: Allen Brooker
Posted: 4th July 2005 08:51 Richard Heyes:
Quote> David: > > What's wrong with ini_set("register_globals", > 0) > > and ini_set("magic_quotes_gpc", 0)? > > It doesn't work, that's what. The actions caused by magic_quotes_gpc and register_globals (namely the escaping of quotes and the creation of variables respectively) happen before your script is called. Switching these off at runtime will not undo the actions caused by them. Users should also be aware of magic_quotes_runtime and magic_quotes_sybase, which can be switched off at runtime (or alternatively, dealt with using a database wrapper).
Author: Brent O'Connor
Posted: 4th July 2005 15:46 The following is a method I use to stripslashes. I've used the php function array_map() if the variable is an array.
Quote<pre> <code> /** * Removes slashes in $this->_formDataArr added by magic quotes if magic quotes is turned on. * @return void */ function removeSlashes() { if (get_magic_quotes_gpc()) { //var_dump($this->_formDataArr); while (list($key,$value) = each($this->_formDataArr)) { $value = is_array($value) ? array_map('stripslashes', $value) : stripslashes($value); $this->_formDataArr[$key] = $value; } } } </code> </pre>
Author: David Coallier
Posted: 12th July 2005 15:41 Here's another reason why not to use register_globals even though Stefan doesn't think the same, this is an example of what can happen.
Quotehttp://www.hardened-php.net/index.37.html But yeah.. that's the kind of vulnerability that comes with register_globals and allow_url_fopen </regards> -David
Author: Stefan Esser
Posted: 14th July 2005 23:31 While this code has already been fixed by Richy.
QuoteTime to clear up some misunderstandings. a) People who say that this is just a line of defense and that it is better to switch of register_globals are totally wrong. This code (in the fixed version) is the easiest way to fix the problem. PHP Applications have to be secure, no matter if the server is secure or not. Switching off register_globals on a few servers, does not kill the problem of unitialised variables on other servers. This code (in the fixed form) however fixes the application. No matter if global variables where properly initialised or not, the application is finally rid of all future unitialised global variables problems. b) an include problem like include $GLOBALS['path']."/blah"; is not only exploitable with allow_url_fopen=on. There is still the possibility to read arbitrary files on the server with %00 attacks. There is still the problem of php://input in combination with %00 (I guess David Coallier has never heard of this) and yeah... as a last resort with allow_url_fopen you can directly include a remote url. -Stefan
Author: Jakub Vrána
Posted: 16th September 2005 13:08 You should take care also of $_FILES[]['name'] which is addslashed() too.
Quote
Author: Marko
Posted: 22nd March 2006 15:06 Hi. Beautiful content and website design. Sorry for my english. I am from albania.
Quote
Author: Arik
Posted: 24th April 2006 09:54 Help to choose a videocamera. What standard to choose?
Quote
Author: Yakov
Posted: 20th May 2006 21:58 And that if to add on a site a history of creation of a site?
Quote
Author: Metod
Posted: 28th May 2006 14:28 Help to choose a videocamera. What standard to choose?
Quote |

Comments
Posted: 3rd July 2005 17:59