Skip to main content
May 21, 2008
Question

Combating SQL Injection

  • May 21, 2008
  • 2 replies
  • 1308 views
Using CFMX7:

In trying to block out SQL Injection we are implementing ‘<cfquery params’ on all related query statements for our application, however this is an undertaking for several queries that need to be validated with params.

In the meantime, we have been exploring methods which include the ODBC statement lockouts in CF Admin for the database connection.

What we have found is the following; setting the Allowed SQL of ‘DROP’ to FALSE, will catch an injection of DROP TABLE only if that statement is in the actual body of the query, alone.

This is trapped as exception:

<cfquery name="tryDrop" datasource="mydatasource">
DROP TABLE mytest
</cfquery>


However, the following is NOT caught:

<cfquery name="tryDrop" datasource="mydatasource">
UPDATE mytest SET sortorder = 5; DROP TABLE mytest
</cfquery>


In this case, the ODBC still allows the DROP statement to be executed.

We have also tested this case as shown above as well as a SQL INJECT item using a variable for an INT field (below), which also is allowed.

<cfset myString = “1; DROP TABLE mytest;”> <!--- simulate a form variable, INT field --->
<cfquery name="tryDrop" datasource="mydatasource">
UPDATE mytest SET sortorder = #myString#
</cfquery>


Is there a patch or fix that will correct the ODBC level to prevent this case?

Note: after the setting the SQL Command DROP to false, we tried restarting CF Service and also tried suspending all ODBC connections for that datasource and neither solved the problem.

Any information would be appreciated.
    This topic has been closed for replies.

    2 replies

    Inspiring
    May 21, 2008
    JR Bob Dobbs wrote:
    > Deny DROP (and also CREATE, ALTER, REVOKE, GRANT and other metadata related permissions) to database user account associated with your datasource.

    Well to the database user account used for the web application. Some
    user account or the other would need these permissions, just not that one.
    Inspiring
    May 21, 2008
    quote:

    Originally posted by: Newsgroup User
    JR Bob Dobbs wrote:
    > Deny DROP (and also CREATE, ALTER, REVOKE, GRANT and other metadata related permissions) to database user account associated with your datasource.

    Well to the database user account used for the web application. Some
    user account or the other would need these permissions, just not that one.



    To clarify:

    By "datasource" I mean the value of the datasource attribute of the cfquery tag, not the database to which it refers. Permissions should be limited for the user account under which your ColdFusion server executes queries.
    May 21, 2008
    So the solution you are describing is still outside the CFAdmin and now on the database level. Correct?
    Inspiring
    May 21, 2008
    Deny DROP (and also CREATE, ALTER, REVOKE, GRANT and other metadata related permissions) to the database user account associated with your datasource.