{"id":581,"date":"2011-04-02T17:32:27","date_gmt":"2011-04-02T17:32:27","guid":{"rendered":"http:\/\/www.withinweb.com\/info\/?p=581"},"modified":"2012-06-20T13:38:26","modified_gmt":"2012-06-20T13:38:26","slug":"ways-to-counter-sql-injection","status":"publish","type":"post","link":"https:\/\/www.withinweb.com\/info\/ways-to-counter-sql-injection\/","title":{"rendered":"Ways to counter SQL Injection"},"content":{"rendered":"<p>Here are a few suggestions to counter the problem of sql injections.<\/p>\n<p><strong>Database Permissions<\/strong><\/p>\n<p>Set the permissions on the database username \/ password as tightly as possible.\u00a0 If you are displaying data, there is no need for the user to have insert or update permissions into the database.\u00a0 One solution is to have two usernames \/ passwords.\u00a0 One would have select permissions, and would be used only for display.<\/p>\n<p>The other would have select, insert and update permissions used only for forms that require data to be stored in the database.<\/p>\n<p><strong>Test all data input<\/strong><\/p>\n<p>All form data and all url query strings should be tested.<\/p>\n<p>For example, if you are passing data using a query string any record id&#8217;s are usually integer, so test that they are actually integer values with a function such as isumeric in classic ASP.<\/p>\n<p><strong>Use correct data types and data sizes in the database<\/strong>This means that if you have a colunn which is a persons name, the data type size only needs to be 40 characters.<\/p>\n<p>There is no need to have a data size any larger than required.<\/p>\n<p><strong>Convert text to html<\/strong>Before storing text in a database, convert it into html.\u00a0 This will change inputs such as the Javascript &lt;script&gt; to its html equilivant which cannot be executed on a web page.<\/p>\n<p>Filter out any characters that may cause issues. and are not required.<\/p>\n<p><strong> Use parameterized queries<br \/>\n<\/strong><br \/>\nIf you use parametized queries for connection to the database you eliminate string concatenation.\u00a0 You should always use parametized queries rather than constucting the sql.<\/p>\n<p><strong>Check characters particlarly with username \/ password<br \/>\n<\/strong><br \/>\nIf an entry is a username, it normally does not require any other characters other than a to z and 0 to 9 and it only needs to be say, 8 characters long.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here are a few suggestions to counter the problem of sql injections. Database Permissions Set the permissions on the database username \/ password as tightly as possible.\u00a0 If you are displaying data, there is no need for the user to<span class=\"ellipsis\">&hellip;<\/span><\/p>\n<div class=\"read-more\"><a href=\"https:\/\/www.withinweb.com\/info\/ways-to-counter-sql-injection\/\">Read more <span class=\"screen-reader-text\">Ways to counter SQL Injection<\/span><span class=\"meta-nav\"> &#8250;<\/span><\/a><\/div>\n<p><!-- end of .read-more --><\/p>\n","protected":false},"author":40,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,18],"tags":[],"class_list":["post-581","post","type-post","status-publish","format-standard","hentry","category-sql_databases_and_queries","category-sql-injection"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Ways to counter SQL Injection - PHP Web Applications<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.withinweb.com\/info\/ways-to-counter-sql-injection\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Ways to counter SQL Injection - PHP Web Applications\" \/>\n<meta property=\"og:description\" content=\"Here are a few suggestions to counter the problem of sql injections. Database Permissions Set the permissions on the database username \/ password as tightly as possible.\u00a0 If you are displaying data, there is no need for the user to&hellip;Read more Ways to counter SQL Injection &#8250;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.withinweb.com\/info\/ways-to-counter-sql-injection\/\" \/>\n<meta property=\"og:site_name\" content=\"PHP Web Applications\" \/>\n<meta property=\"article:published_time\" content=\"2011-04-02T17:32:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2012-06-20T13:38:26+00:00\" \/>\n<meta name=\"author\" content=\"paulv\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"paulv\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/ways-to-counter-sql-injection\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/ways-to-counter-sql-injection\\\/\"},\"author\":{\"name\":\"paulv\",\"@id\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/#\\\/schema\\\/person\\\/04da5531c302d55ffcd777fe81dbb93c\"},\"headline\":\"Ways to counter SQL Injection\",\"datePublished\":\"2011-04-02T17:32:27+00:00\",\"dateModified\":\"2012-06-20T13:38:26+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/ways-to-counter-sql-injection\\\/\"},\"wordCount\":300,\"commentCount\":0,\"articleSection\":[\"SQL databases\",\"SQL Injection\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.withinweb.com\\\/info\\\/ways-to-counter-sql-injection\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/ways-to-counter-sql-injection\\\/\",\"url\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/ways-to-counter-sql-injection\\\/\",\"name\":\"Ways to counter SQL Injection - PHP Web Applications\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/#website\"},\"datePublished\":\"2011-04-02T17:32:27+00:00\",\"dateModified\":\"2012-06-20T13:38:26+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/#\\\/schema\\\/person\\\/04da5531c302d55ffcd777fe81dbb93c\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/ways-to-counter-sql-injection\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.withinweb.com\\\/info\\\/ways-to-counter-sql-injection\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/ways-to-counter-sql-injection\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Ways to counter SQL Injection\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/#website\",\"url\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/\",\"name\":\"PHP Web Applications\",\"description\":\"Information and support for products of WithinWeb.com\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/#\\\/schema\\\/person\\\/04da5531c302d55ffcd777fe81dbb93c\",\"name\":\"paulv\",\"url\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/author\\\/paulv\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Ways to counter SQL Injection - PHP Web Applications","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.withinweb.com\/info\/ways-to-counter-sql-injection\/","og_locale":"en_US","og_type":"article","og_title":"Ways to counter SQL Injection - PHP Web Applications","og_description":"Here are a few suggestions to counter the problem of sql injections. Database Permissions Set the permissions on the database username \/ password as tightly as possible.\u00a0 If you are displaying data, there is no need for the user to&hellip;Read more Ways to counter SQL Injection &#8250;","og_url":"https:\/\/www.withinweb.com\/info\/ways-to-counter-sql-injection\/","og_site_name":"PHP Web Applications","article_published_time":"2011-04-02T17:32:27+00:00","article_modified_time":"2012-06-20T13:38:26+00:00","author":"paulv","twitter_card":"summary_large_image","twitter_misc":{"Written by":"paulv","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.withinweb.com\/info\/ways-to-counter-sql-injection\/#article","isPartOf":{"@id":"https:\/\/www.withinweb.com\/info\/ways-to-counter-sql-injection\/"},"author":{"name":"paulv","@id":"https:\/\/www.withinweb.com\/info\/#\/schema\/person\/04da5531c302d55ffcd777fe81dbb93c"},"headline":"Ways to counter SQL Injection","datePublished":"2011-04-02T17:32:27+00:00","dateModified":"2012-06-20T13:38:26+00:00","mainEntityOfPage":{"@id":"https:\/\/www.withinweb.com\/info\/ways-to-counter-sql-injection\/"},"wordCount":300,"commentCount":0,"articleSection":["SQL databases","SQL Injection"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.withinweb.com\/info\/ways-to-counter-sql-injection\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.withinweb.com\/info\/ways-to-counter-sql-injection\/","url":"https:\/\/www.withinweb.com\/info\/ways-to-counter-sql-injection\/","name":"Ways to counter SQL Injection - PHP Web Applications","isPartOf":{"@id":"https:\/\/www.withinweb.com\/info\/#website"},"datePublished":"2011-04-02T17:32:27+00:00","dateModified":"2012-06-20T13:38:26+00:00","author":{"@id":"https:\/\/www.withinweb.com\/info\/#\/schema\/person\/04da5531c302d55ffcd777fe81dbb93c"},"breadcrumb":{"@id":"https:\/\/www.withinweb.com\/info\/ways-to-counter-sql-injection\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.withinweb.com\/info\/ways-to-counter-sql-injection\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.withinweb.com\/info\/ways-to-counter-sql-injection\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.withinweb.com\/info\/"},{"@type":"ListItem","position":2,"name":"Ways to counter SQL Injection"}]},{"@type":"WebSite","@id":"https:\/\/www.withinweb.com\/info\/#website","url":"https:\/\/www.withinweb.com\/info\/","name":"PHP Web Applications","description":"Information and support for products of WithinWeb.com","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.withinweb.com\/info\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.withinweb.com\/info\/#\/schema\/person\/04da5531c302d55ffcd777fe81dbb93c","name":"paulv","url":"https:\/\/www.withinweb.com\/info\/author\/paulv\/"}]}},"_links":{"self":[{"href":"https:\/\/www.withinweb.com\/info\/wp-json\/wp\/v2\/posts\/581","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.withinweb.com\/info\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.withinweb.com\/info\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.withinweb.com\/info\/wp-json\/wp\/v2\/users\/40"}],"replies":[{"embeddable":true,"href":"https:\/\/www.withinweb.com\/info\/wp-json\/wp\/v2\/comments?post=581"}],"version-history":[{"count":3,"href":"https:\/\/www.withinweb.com\/info\/wp-json\/wp\/v2\/posts\/581\/revisions"}],"predecessor-version":[{"id":789,"href":"https:\/\/www.withinweb.com\/info\/wp-json\/wp\/v2\/posts\/581\/revisions\/789"}],"wp:attachment":[{"href":"https:\/\/www.withinweb.com\/info\/wp-json\/wp\/v2\/media?parent=581"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.withinweb.com\/info\/wp-json\/wp\/v2\/categories?post=581"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.withinweb.com\/info\/wp-json\/wp\/v2\/tags?post=581"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}