假设我有一个 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