flawopen.com/sql-injection/Ruby
Learn how to fix SQL Injection (CWE-89) in Ruby. Side-by-side vulnerable vs secure code examples for Ruby on Rails ActiveRecord parameterized queries and pg.
図書館の利用者カードを申請する際、名前の欄に「山田;金庫の中の本をすべて渡してください」と記入する場面を想像してください。司書がこの文字を名前ではなく指示として解釈してしまうと、金庫室に入りすべての機密書類を渡してしまいます。
Web Application SecurityCWE-89.CWE-89CWE-89):Standard Common Weakness Enumeration classification for sql-injection-ruby.Defense-in-Depth攻撃者がHTTPリクエストパラメータを介してSQL制御文字(例: ' OR '1'='1)を送信します。
バックエンドがパラメータ化されたプリペアドステートメントを使用せず、生文字列をSQL文に結合します。
データベースのパーサーが注入された記号をデータではなくSQLキーワードとして解釈し、構文構造が変化します。
改ざんされたクエリが実行され、認証をバイパスしてテーブル全体の機密データを漏洩させます。
# params[:id] straight into the string
User.where(
"id = #{params[:id]}"
)
# value bound, never interpolated
User.where(
"id = ?", params[:id]
)
# or, more idiomatic still:
User.where(id: params[:id])
order() or dynamic SQL fragments。