mysql PDO and stored procedure dynamic SQL injection

前端 未结 1 1623
醉话见心
醉话见心 2021-01-16 04:33

As I have seen in many posts, dynamic SQL in stored procedure is vulnerable to SQL injection. But if we use previously PDO with prepared statement this still be unsafe?

相关标签:
1条回答
  • 2021-01-16 05:13

    Yes, of course.

    What if in_var is equal to ' UNION SELECT password from admins --?

    To avoid that, you should use not a cargo cult prepared statement but a real one, substituting your variable with a placeholder.

    SET @query = CONCAT("SELECT * FROM my_table  WHERE my_column = ? LIMIT 1;");
    
    PREPARE stmt FROM @query;
    EXECUTE stmt USING @in_var;
    
    0 讨论(0)
提交回复
热议问题