Magic quotes

aesthetics  →
being  →
complexity  →
database  →
enterprise  →
ethics  →
fiction  →
history  →
internet  →
knowledge  →
language  →
licensing  →
linux  →
logic  →
method  →
news  →
perception  →
philosophy  →
policy  →
purpose  →
religion  →
science  →
sociology  →
software  →
truth  →
unix  →
wiki  →
essay  →
feed  →
help  →
system  →
wiki  →
critical  →
discussion  →
forked  →
imported  →
original  →
Magic quotes
[ temporary import ]
please note:
- the content below is remote from Wikipedia
- it has been imported raw for GetWiki
Magic quotes was a feature of the PHP scripting language, wherein strings are automatically escaped—special characters are prefixed with a backslash—before being passed on. It was introduced to help newcomers write functioning SQL commands without requiring manual escaping. It was later described as intended to prevent inexperienced developers from writing code that was vulnerable to SQL injection attacks.This feature was officially deprecated as of PHP 5.3.0 and removed in PHP 5.4, due to security concerns.WEB,weblink
work = PHP Manual, 2014-01-17,,


The current revision of the PHP manual mentions that the rationale behind magic quotes was to "help [prevent] code written by beginners from being dangerous."WEB,weblink PHP:Why use magic quotes?, PHP documentation, 2007-02-19, It was however originally introduced in PHP 2 as a php.h compile-time setting for msql, only escaping single quotes, "making it easier to pass form data directly to msql queries".WEB,weblink If the MAGIC_QUOTES variable is defined in the php.h file then these quotes will be automatically escaped making it easier to pass form data directly to msql queries., 2011-03-27, It originally was intended as a "convenience feature, not as [a] security feature."WEB,weblink Magic Quotes is oft-understood, even by journeymen PHP programmers, WEB,weblink Re: [PHP3] what are magic_quotes?, PHP-dev mailing list, 1999-08-27, 2011-01-17, The use scope for magic quotes was expanded in PHP 3. 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, $_REQUEST, $_POST and $_COOKIE global variables. Developers can then in theory use string concatenation to construct safe SQL queries with data provided by the user. (This was most accurate when PHP 2 and PHP 3 were current, since the primary supported databases allowed only 1-byte character sets.)


Magic quotes were enabled by default in new installations of PHP 3 and 4, but could be disabled through the magic_quotes_gpc configuration directive. Since the operation of magic quotes was behind the scenes and not immediately obvious, developers may have been unaware of their existence and the potential problems that they could introduce. The PHP documentation pointed out several pitfalls and recommended that, despite being enabled by default, they should be disabled.WEB,weblink PHP:Why not to use magic quotes, PHP documentation, 2007-02-19, Problems with magic quotes included:
  • Not all data that are supplied by the user are intended for insertion into a database. They 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 into even widely used software.WEB,weblink Quotation marks are double escaped when editing a comment, WordPress issue tracker, 2007-02-19,
  • Not all data that are supplied by the user and used in a database query are 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 is 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.WEB,weblink addslashes() versus mysql_real_escape_string(), Chris Shiflett, 2007-02-19, WEB,weblink Changes in release 5.0.22 (24 May 2006), MySQL AB, MySQL 5.0 Reference Manual, 2007-02-19,
  • While many database management systems 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 vice versa.
  • Adding magic quotes and subsequently removing them where appropriate incurs a small but unnecessary amount of 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 that because of these problems, the magic quotes feature would be removed from PHP 6.WEB,weblink Minutes PHP Developers Meeting, PHP Group, 2005-11-12, 2007-02-19, When development of PHP 6 stalled and development continued on the 5.x branch instead, the feature was deprecated in PHP 5.3.0 and removed in 5.4.

Other approaches

  • Some languages such as PerlWEB,weblink Introduction to Perl's Taint Mode, Dan Ragle,, 2006-04-18, 2007-03-21, and RubyWEB,weblinkweblink" title="">weblink Locking Ruby in the Safe, Programming Ruby, 2014-05-21, 2009-05-30, opt for an approach involving data tainting, where data from untrusted sources, such as user input, are considered "tainted" and can not be used for dangerous operations until explicitly marked as trustworthy, usually after validation 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 are safe or unsafe.WEB,weblink Making Wrong Code Look Wrong, Joel on Software: Painless Software Management, Joel Spolsky, 2005-05-11, 2007-02-19,
  • Modern database engines and libraries use parameterised queries to pass data to the database separately from SQL commands, greatly reducing the need to escape data before constructing the queries.

See also



External links

- content above as imported from Wikipedia
- "Magic quotes" does not exist on GetWiki (yet)
- time: 2:27pm EDT - Mon, Mar 18 2019
[ this remote article is provided by Wikipedia ]
LATEST EDITS [ see all ]
M.R.M. Parrott