1

これを読む:

https://www.owasp.org/index.php/SQL_Injection_Prevention_Cheat_Sheet

動的SQL部分には、次のようなさまざまなものがあります。

So, if you had an existing Dynamic query being generated in your code that was going to Oracle that looked like this:
 String query = "SELECT user_id FROM user_data WHERE user_name = '" + req.getParameter("userID") 
 + "' and user_password = '" + req.getParameter("pwd") +"'";
 try {
     Statement statement = connection.createStatement( … );
     ResultSet results = statement.executeQuery( query );
 }
You would rewrite the first line to look like this:
Codec ORACLE_CODEC = new OracleCodec();
 String query = "SELECT user_id FROM user_data WHERE user_name = '" + 
   ESAPI.encoder().encodeForSQL( ORACLE_CODEC, req.getParameter("userID")) + "' and user_password = '"
   + ESAPI.encoder().encodeForSQL( ORACLE_CODEC, req.getParameter("pwd")) +"'";
And it would now be safe from SQL injection, regardless of the input supplied.

しかし、後者は次のように述べています。

Oracle 10g escaping

An alternative for Oracle 10g and later is to place { and } around the string to escape the entire string. However, you have to be careful that there isn't a } character already in the string. You must search for these and if there is one, then you must replace it with }}. Otherwise that character will end the escaping early, and may introduce a vulnerability.

例を見ませんでしたが、これはCodec ORACLE_CODEC.... の代わりに中括弧を使用できるということですか? 誰にも例がありますか?ありがとう。

4

1 に答える 1

3

いいえ、これは注射防止技術ではありません。インジェクションに対して脆弱ではないことを 100% 確実にする唯一の方法は、準備済みステートメントを使用し、クエリに挿入する必要があるすべてのユーザー入力に対してパラメーターをバインドすることです。それ以下の場合は、サイコロを振っているだけです。

于 2012-08-14T21:37:02.710 に答える