<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Do the SelectLayerByAttribute or MakeFeatureLayer tools have any sort of internal checking for SQL Injection? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/do-the-selectlayerbyattribute-or-makefeaturelayer/m-p/441801#M34607</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Taking your question at face value, i.e., does SelectLayerByAttribute or similar tools have internal checking for SQL injection, I think the answer is pretty clearly no.&amp;nbsp; I just did a quick check using SelectLayerByAttribute, and I was able to drop a table in SQL Server by injecting extra SQL into the where_clause of the tool.&amp;nbsp; Since MS Access doesn't support multiple SQL statements, it didn't work on personal geodatabases.&amp;nbsp; It also didn't work on file geodatabases, which I am guessing is for the same reason.&amp;nbsp; Of course, I could use less invasive SQL injection with all three to return more records than intended.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Although I didn't check all DBMSes and all forms of SQL injection, the fact that I could successfully use some SQL injection with some DBMSes gives a strong indication the tools themselves are not doing any internal checks for SQL injection.&amp;nbsp; I think Esri would say these tools are simply passing SQL along, and that hardening against SQL injection should be taking place elsewhere.&amp;nbsp; Not only would programming internal checks get complicated and quickly, it would likely involve putting big constraints on how SQL is used with those tools.&amp;nbsp; Always a trade off.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The tools you reference might not be hardened against SQL injection, but that doesn't mean the floodgates are open.&amp;nbsp; There are still multiple layers in the application stack between these tools and the interface of ArcGIS Server that users will be interacting with.&amp;nbsp; One thing Esri introduced, I can't remember when exactly, is &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#/About_standardized_queries/015400000641000000/"&gt;standardized queries for ArcGIS Server&lt;/A&gt;.&amp;nbsp; In terms of publishing GP tools, there may be extra precautions in place, I don't know.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am a firm believer in seeing is believing, especially with ArcGIS.&amp;nbsp; Regardless of what the documentation does or doesn't say, I say test it and see for yourself.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 09 Feb 2015 20:45:39 GMT</pubDate>
    <dc:creator>JoshuaBixby</dc:creator>
    <dc:date>2015-02-09T20:45:39Z</dc:date>
    <item>
      <title>Do the SelectLayerByAttribute or MakeFeatureLayer tools have any sort of internal checking for SQL Injection?</title>
      <link>https://community.esri.com/t5/python-questions/do-the-selectlayerbyattribute-or-makefeaturelayer/m-p/441800#M34606</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm making a GP tool for ArcGIS server to generate some standard reports with user input. I'm making a tool that allows for user input into a formatted query. I'd like to make sure I don't allow people to blow it up.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As an example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;parameter_1 = &amp;lt;USER INPUT&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;def query(parameter_1):&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;query = "PIN = '{0}'".format(parameter_1)&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;SPAN style="font-family: 'courier new', courier; line-height: 1.5;"&gt;arcpy.management.MakeFeatureLayer(source_fc, 'test_layer', query)&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;print query&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, sans-serif;"&gt;Usually the operation will go as this:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;parameter_1 = '110101010101'&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;def query(parameter_1):&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;query = "PIN = '{0}'".format(parameter_1)&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;arcpy.management.MakeFeatureLayer(source_fc, 'test_layer', query)&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;print query&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;gt; ExecuteTool()&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;PIN = '&lt;SPAN style="font-family: 'courier new', courier;"&gt;110101010101'&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, sans-serif;"&gt;Theoretically the user could&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: arial, helvetica, sans-serif;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;parameter_1 = '110101010101; DROP TABLE pin'&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;def query(parameter_1):&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;query = "PIN = '{0}'".format(parameter_1)&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;arcpy.management.MakeFeatureLayer(source_fc, 'test_layer', query)&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;print query&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;gt; ExecuteTool()&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;??????&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Feb 2015 13:33:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/do-the-selectlayerbyattribute-or-makefeaturelayer/m-p/441800#M34606</guid>
      <dc:creator>christopherfricke2</dc:creator>
      <dc:date>2015-02-09T13:33:31Z</dc:date>
    </item>
    <item>
      <title>Re: Do the SelectLayerByAttribute or MakeFeatureLayer tools have any sort of internal checking for SQL Injection?</title>
      <link>https://community.esri.com/t5/python-questions/do-the-selectlayerbyattribute-or-makefeaturelayer/m-p/441801#M34607</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Taking your question at face value, i.e., does SelectLayerByAttribute or similar tools have internal checking for SQL injection, I think the answer is pretty clearly no.&amp;nbsp; I just did a quick check using SelectLayerByAttribute, and I was able to drop a table in SQL Server by injecting extra SQL into the where_clause of the tool.&amp;nbsp; Since MS Access doesn't support multiple SQL statements, it didn't work on personal geodatabases.&amp;nbsp; It also didn't work on file geodatabases, which I am guessing is for the same reason.&amp;nbsp; Of course, I could use less invasive SQL injection with all three to return more records than intended.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Although I didn't check all DBMSes and all forms of SQL injection, the fact that I could successfully use some SQL injection with some DBMSes gives a strong indication the tools themselves are not doing any internal checks for SQL injection.&amp;nbsp; I think Esri would say these tools are simply passing SQL along, and that hardening against SQL injection should be taking place elsewhere.&amp;nbsp; Not only would programming internal checks get complicated and quickly, it would likely involve putting big constraints on how SQL is used with those tools.&amp;nbsp; Always a trade off.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The tools you reference might not be hardened against SQL injection, but that doesn't mean the floodgates are open.&amp;nbsp; There are still multiple layers in the application stack between these tools and the interface of ArcGIS Server that users will be interacting with.&amp;nbsp; One thing Esri introduced, I can't remember when exactly, is &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#/About_standardized_queries/015400000641000000/"&gt;standardized queries for ArcGIS Server&lt;/A&gt;.&amp;nbsp; In terms of publishing GP tools, there may be extra precautions in place, I don't know.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am a firm believer in seeing is believing, especially with ArcGIS.&amp;nbsp; Regardless of what the documentation does or doesn't say, I say test it and see for yourself.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Feb 2015 20:45:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/do-the-selectlayerbyattribute-or-makefeaturelayer/m-p/441801#M34607</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2015-02-09T20:45:39Z</dc:date>
    </item>
  </channel>
</rss>

