[Security] Essential Sites to Read When Understanding SQL Injection Countermeasures

Tadashi Shigeoka ·  Thu, November 10, 2011

Referencing the blog of Hiroshi Tokumaru, author of ‘Easy-to-Understand PHP Textbook’, I’ve compiled articles to read when understanding “SQL injection countermeasures” for my own reference.

・参考:「SQLインジェクション対策」でGoogle検索して上位15記事を検証した - ockeghem(徳丸浩)の日記

First, here’s an excerpt from the summary section of the above article:

  • Don't dynamically construct SQL
  • Use static placeholders for SQL parameter specification

As long as you follow these two rules, SQL injection vulnerabilities will not occur in principle, even if there are bugs in applications or SQL calling libraries.

When writing about SQL injection, please always include the following messages:
  • Simply use prepared statements
  • Never attempt to construct SQL using string concatenation
  • Read IPA's "Safe SQL Calling Methods"
引用元:[SQLインジェクション対策]Webアプリケーションとかの入門本みたいのを書く人への心からのお願い。 - *「ふっかつのじゅもんがちがいます。」 withぬこ

For those wondering “What are prepared statements?”, these resources explain it clearly and are recommended:

プリペアドステートメント - データベース接続(PEAR::DB) - PEAR入門

PHP: プリペアドステートメントおよびストアドプロシージャ - Manual  

Below are articles to read when understanding “SQL injection countermeasures”:

・初心者向け:[SQLインジェクション対策]Webアプリケーションとかの入門本みたいのを書く人への心からのお願い。 - *「ふっかつのじゅもんがちがいます。」 withぬこ

・中級者向け:PHPでのSQLインジェクション対策 - エスケープ・クォート編 — Let’s Postgres

Once you understand the basics, read IPA’s “Safe SQL Calling Methods”:

情報処理推進機構:情報セキュリティ:脆弱性対策:安全なウェブサイトの作り方

That’s all from the Gemba.