PDO::ATTR_EMULATE_PREPARES Security Issue
We are reviewing a potential security issue and these are some internal comments:
-------------- THIS IS FROM THE MS SQL PDO DOCUMENTATION ---
The security of parameterized queries is not in effect when you use PDO::ATTR_EMULATE_PREPARES => true. Your application should ensure that the data that is bound to the parameter(s) does not contain malicious Transact-SQL code.
At the minimum, that looks like a bug in the PDO driver. If it is true that they cannot even guarantee the structure of the query in PDO::ATTR_EMULATE_PREPARES mode, they just should not have enabled this in the 3.x version of their driver.
----------- THE QUESTION ------------------------
Is this a mistake in the documentation?
Hello @david-garcia-garcia
I don't think this is a mistake in the documentation, nor a bug in the PDO driver. When you call Prepare with the ATTR_EMULATE_PREPARES flag set to true, you are explicitly bypassing the driver's call through to the server to actually prepare the statement. The line before the beginning of your quote from the docs:"If your PHP application must use parameters in a Transact-SQL clause that will generate an error on the server, you can set the PDO::ATTR_EMULATE_PREPARES attribute to true. ". The reason you might choose to set emulate prepares attribute is to allow your application to dynamically alter parts of a SQL statement that the server does not support parameterizing, and therefore can't prepare. What the note is warning you about is that, as in any dynamically generated SQL statement, your application needs to ensure that the strings you are using to construct it are clean.
Thanks for the quick reply, I'll share this feedback with the people involved in the issue.