且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

预备语句和二阶SQL注入

更新时间:2022-10-14 18:23:22

您所读的是普通垃圾.只是写了一点头绪都没有.

您不应将准备好的语句用于查询,而应将其用于数据.每次必须在查询中添加变量时,都必须仅通过占位符进行设置.因此,您的查询分离理论毫无意义:SELECT或ALTER或GRANT或其他无关紧要.唯一重要的是-是否有任何变量进入查询.

I have read somewhere here that using prepared statements in PDO makes your app only immune to first order SQL injections, but not totally immune to second order injections.

My question is: if we used prepared statements in all queries inlcuding SELECT queries and not only in INSERT query, then how can a second order sql injection be possible?

For example in the following queries there is no chance for a 2nd order injection:

write:

INSERT INTO posts (userID,text,date) VALUES(?,?,?)

read:

SELECT * FROM posts WEHRE userID=?

delete:

DELETE FROM posts WHERE userID=?

What you have read is a plain rubbish. Someone who wrote it just have no clue.

You should use prepared statements not for the query but for the data. Every time you have to add a variable into query, you have to make it via placeholder only. So, your query separation theory makes no sense: it doesn't matter if it SELECT or ALTER or GRANT or whatever. The only thing that matters - if any variable goes into query or not.