Preventing SQL Injection for Column Names

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Preventing SQL Injection for Column Names

    I've noticed how the cfquery tag will automatically escape single quote
    characters embedded in variables used in SQL statements, but is there a built
    in way to prevent SQL injection if I'm using a variable as part of an "order
    by" clause?

    For example:

    Select ColumnA, ColumnB
    From MyTable
    Order By #Url.ColumnNameVariable#

    What's to prevent the user from entering something like this (with special
    characters encoded of course, I'm not encoding them here for clarity):

    [url]http://www.mysite.com/mypage.cfm?ColumnNameVariable=Amount;[/url] insert into
    MyTable values (0, 0)

    The net result would be that they inserted a record into MyTable. Of course
    they could do more dangerous stuff too like dropping tables, xp_cmdshell, etc..

    Thanks in advance!

    datac0re Guest

  2. Similar Questions and Discussions

    1. Getting column data without column names
      Hello all, I'm trying to write a coldfusion program to display account data such as name, address, phone #, etc. I retrieve this data from an ...
    2. counting column and getting column names
      Im using an Access database that will probably be switched over to Oracle later, but I need to find out how to get the number of columns in an...
    3. Preventing SQL Injection Attacks
      In article <qdu3gvs8qq052805u6rtb08gmc1bblv5oc@4ax.com>, James wrote: This is an option and most effective: $query = "select * from sample...
    4. SQL Injection and preventing querystring abuse
      Hi all, A recent project that I had finished and went live with no apparant problems. My client received an email from a user who mentioned...
    5. How to get column names using SQL?
      In article <a06d6e69.0307100719.2e206e69@posting.google.com>, minjie@excite.com says... SYSCAT.COLUMNS To show the columns of this view: ...
  3. #2

    Default Re: Preventing SQL Injection for Column Names

    What's to prevent the user from entering it? nothing
    What's to prevent it from working? you and your code :-)

    Semicolons are a red flag for maliciousness. Don't let them in anywhere that
    isn't using a cfqueryparam.

    You can't use <cfqueryparam> in this case, but using that as much as possible
    helps alot.

    Kronin555 Guest

  4. #3

    Default Re: Preventing SQL Injection for Column Names

    You should already be doing something like this:
    <CFPARAM name="Url.ColumnNameVariable" type="variableName"
    default="N0_VALUE_SENT"> <!--- Use a sensible default or the value
    "N0_VALUE_SENT". --->

    This will automatically stop apostrophes, semicolons, etc. Encoded or not.

    However, this is not a substitute for using cfqueryparam!
    If you cannot use cfqueryparam directly in the SQL, put the SQL in a stored
    procedure. At the very least, use a switch/case to limit the possibilities
    (don't use Form or URL variables directly in SQL).

    Finally, all of the above still isn't enough for data columns. Remember that
    if the user can store any data at all, you must guard against cross-site
    scripting too.
    HTMLEditFormat covers that contingency, for the most part.

    Regards,
    -- MikeR


    MikerRoo Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139