假设我有一个Web应用程序从用户那里获取输入并将其保存在数据库中。让我们进一步假设没有安全漏洞 - 它正确地逃避用户输入,使用绑定参数,无论如何。转义/清理从数据库检索到的数据
必须从数据库中检索到的数据是否被怀疑(即可能被污染/恶意)?
示例(结果不确定,因为我害怕尝试它)。这是数据库:
create table mytable (id int primary key, name varchar(50));
create table othertable (name varchar(50), xyz int,
... `name` is an fk ...);
insert into mytable (id, name) values(1, '"abc"; drop table mytable;');
insert into othertable (name, xyz) values('"abc"; drop table mytable;', 45475);
然后我跑这个伪代码(也许从PHP为例):
# run query 'select * from mytable where id = 1';
# put the `name` in $name
# run query 'select * from othertable where name = $name'
# $name is not escaped, no other precautions taken