php-doc-en/reference/mongo/security.xml
Kristina Chodorow c37ea4fd5a added link to MongoDB injection page
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@310022 c90b9560-bf6c-de11-be94-00142212c4b1
2011-04-07 21:04:46 +00:00

68 lines
2.1 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<section xml:id="mongo.security" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>Security</title>
<section>
<title>Request Injection Attacks</title>
<para>
If you are passing <literal>$_GET</literal> parameters to your queries, make
sure that they are cast to strings first. Users can insert associative
arrays in GET requests, which could then become unwanted $-queries.
</para>
<para>
A fairly innocuous example: suppose you are looking up a user's information
with the request <emphasis>http://www.example.com?username=bob</emphasis>.
Your application does the query
<literal>$collection->find(array("username" => $_GET['username']))</literal>.
</para>
<para>
Someone could subvert this by getting
<emphasis>http://www.example.com?username[$ne]=foo</emphasis>, which PHP
will magically turn into an associative array, turning your query into
<literal>$collection->find(array("username" => array('$ne' => "foo")))</literal>,
which will return all users not named "foo" (all of your users, probably).
</para>
<para>
This is a fairly easy attack to defend against: make sure $_GET's parameters
are the type you expect before you send them to the database (cast them to
strings, in this case).
</para>
<para>
Thanks to <link xlink:href="&url.mongodb.injection;">Phil</link> for pointing this out.
</para>
<para>
See <link xlink:href="&url.mongodb.dochub.security;">the main documentation</link>
for more information about SQL-injection-like issues with MongoDB.
</para>
</section>
</section>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->