Click on the slide!

eMiner Community Directory

Social Networking Directory

Community Networking Directory eMiner Community Directory is an advanced Web 2.0 Social Networking Community for Business owners and website administrator's to interact with each other. More than just a directory! We believe Internet users a…

More...
Click on the slide!

Enviro-Vac Hazardous Materials Contractor

Safety First!

Enviro-Vac™ is one of the largest full service environmental contracting companies in Western Canada. The company has been in operation since 1976 and has offices in Victoria, Vancouver and Edmonton.

More...
Click on the slide!

Live Geeks Canada

Buy Live Geeks Canada .com

Live Geeks Canada .com is a domain we have owned and developed for years. We don't really have the time required to keep it up. It is up to date with Joomla 1.5.11 and Community…

More...
Click on the slide!

Enviro-Wrap Containment Systems Inc.

Environmental Wrap and Containment Projects

Enviro-Wrap ™ requires less maintenance and offers a tighter seal and superiour wind resistance compared to traditional tarping systems. Enviro-Wrap lets construction superintendents and project managers sleep at night. No more lying awake, listening to…

More...
Click on the slide!

Movie Club Ticket

Movie Club Ticket for Sale

The Movie Club Ticket domain is for sale. Comes complete with Joomla 1.5.11 installed, hosting for one year, the new Community Builder component installed, advance JCE editor, an advanced professional template from Rocketthemes and much…

More...
Click on the slide!

Jumla Times

Jumla Time 'Style' News

Jumla Times 'Style' News is about Joomla extensions, templates, components, modules, plugins and testing them all out.

More...
Click on the slide!

Media Data Hosting

High Quality Hosting for Joomla

Hosting Products and ServicesMedia Data Hosting offers hosting for Joomla with a server set up to support the functions of the Joomla content management system. Easily add search engine friendly URL's to your website!

Click on the slide!

My Biker Space

My Biker Space for Motorcyclists

Motorcyclist's Community! Expand your Riding Group Invite Old Friend's and Plan a Ride Upload Photos, Link Videos Blog Create your Biker Group or join others

More...
Click on the slide!

Canadian Biker Magazine

Canadian Biker Magazine Uniquely Canadian

For more than 27 years, Canadian Biker Magazine has offered a uniquely Canadian take on the sport and lifestyle of motorcycling. Beginning as a newsprint tabloid and evolving into the glossy magazine it is today…

More...
Click on the slide!

AnE Vibe

A' n E Vibe will be Press Plus 1 soon

A'n E Vibe will be making an official change of their name to Press Plus 1.com in the near future after June 2009. (This is not an official statement only the guess of one person)…

More...
What are Magic quotes?
Written by Wikipedia   
Thursday, 20 September 2007

Magic quotes is a controversial feature of the PHP scripting language, intended to help prevent inexperienced developers from writing code which is vulnerable to SQL injection attacks. This feature is officially deprecated as of PHP 5.3.0, and removed in PHP 6 due to security concerns[1].

Contents

Concept

The rationale behind magic quotes is to "help code written by beginners from being dangerous."[2] Single quotes, double quotes, backslashes and null characters in all user-supplied data all have a backslash prepended to them before being passed to the script in the $_GET, $_POST and $_COOKIE global variables. Developers can then in theory use string concatenation safely to construct SQL queries with data provided by the user.

Criticism

Magic quotes are enabled by default in new installations of PHP, and since their operation is behind the scenes and not immediately obvious, developers may be unaware of their existence and the potential problems that they can introduce. The PHP documentation points out several pitfalls and recommends that, despite being enabled by default, they should be disabled.[3]

Problems with magic quotes include:

  • Not all data that is supplied by the user is intended for insertion into a database. It may be rendered directly to the screen, stored in a session, or previewed before saving. This can result in backslashes being added where they are not wanted and being shown to the end user. This bug often creeps in even in widely used software.[4]
  • Not all data that is supplied by the user and used in a database query is obtained directly from sources protected by magic quotes. For instance, a user-supplied value might be inserted into a database -- protected by magic quotes -- and later retrieved from the database and used in a subsequent database operation. The latter use is not protected by magic quotes, and a naive programmer used to relying on them may be unaware of the need to protect it explicitly.
  • Magic quotes also use the generic functionality provided by PHP's addslashes() function, which is not Unicode aware and still subject to SQL injection vulnerabilities in some multi-byte character encodings. Database-specific functions such as mysql_real_escape_string() or, where possible, prepared queries with bound parameters are preferred.[5][6]
  • While many DBMS support escaping quotes with a backslash, the standard actually calls for using another quote. Magic quotes offer no protection for databases not set up to support escaping quotes with a backslash.
  • Portability is an issue if an application is coded with the assumption that magic quotes are enabled and is then moved to a server where they are disabled, or the other way round.
  • Adding magic quotes and subsequently removing them where appropriate incurs a small but unnecessary performance overhead.
  • Magic quotes do not protect against other common security vulnerabilities such as cross-site scripting attacks or SMTP header injection attacks.

In November 2005 the core PHP developers decided on account of these problems that the magic quotes feature would be removed from PHP 6.[7]

Other approaches

  • Some languages such as Perl[8] and Ruby[9] opt for an approach involving data tainting, where data from untrusted sources, such as user input, is considered "tainted" and can not be used for dangerous operations until explicitly marked as trustworthy, usually after validation and/or encoding. Since the construction of SQL queries is considered "dangerous" in this context, this forces the programmer to address the problem. Tainting does not solve the problem, but it does highlight those instances where there is a problem so that the programmer is able to solve them appropriately.
  • Joel Spolsky has suggested using a form of Hungarian notation that indicates whether data is safe or unsafe.[10]
  • Modern database engines and libraries use parametrised queries to pass data to the database separately from SQL commands, greatly reducing the need to escape data before constructing the queries.

References

  1. ^ "[http:http://php.net/manual/en/security.magicquotes.php PHP: Magic Quotes]". http:http://php.net/manual/en/security.magicquotes.php. Retrieved on 2009-05-02. 
  2. ^ "PHP:Why use magic quotes?". PHP documentation. http://uk.php.net/manual/en/security.magicquotes.why.php. Retrieved on 2007-02-19. 
  3. ^ "PHP:Why not to use magic quotes". PHP documentation. http://uk.php.net/manual/en/security.magicquotes.whynot.php. Retrieved on 2007-02-19. 
  4. ^ "Quotation marks are double escaped when editing a comment". WordPress issue tracker. http://trac.wordpress.org/ticket/2768. Retrieved on 2007-02-19. 
  5. ^ Chris Shiflett. "addslashes() versus mysql_real_escape_string()". http://shiflett.org/blog/2006/jan/addslashes-versus-mysql-real-escape-string. Retrieved on 2007-02-19. 
  6. ^ MySQL AB. "Changes in release 5.0.22 (24 May 2006)". MySQL 5.0 Reference Manual. http://dev.mysql.com/doc/refman/5.0/en/news-5-0-22.html. Retrieved on 2007-02-19. 
  7. ^ PHP Group (2005-11-12). "Minutes PHP Developers Meeting". http://www.php.net/~derick/meeting-notes.html#magic-quotes. Retrieved on 2007-02-19. 
  8. ^ Dan Ragle (2006-04-18). "Introduction to Perl's Taint Mode". webreference.com. http://www.webreference.com/programming/perl/taint/. Retrieved on 2007-03-21. 
  9. ^ "Locking Ruby in the Safe". Programming Ruby. http://www.rubycentral.com/book/taint.html. Retrieved on 2007-03-21. 
  10. ^ Joel Spolsky (2005-05-11). "Making Wrong Code Look Wrong". Joel on Software: Painless Software Management. http://www.joelonsoftware.com/articles/Wrong.html. Retrieved on 2007-02-19. 

External links

© This material from Wikipedia is licensed under the GFDL.
Comments (0)Add Comment

Write comment

busy
 
Next >