Let's say I have a web application that gets input from the user and saves it in a database. Let's further assume that there are no security vulnerabilities -- it correctly escapes user input, uses bind parameters, whatever.
Must data retrieved from the database be treated with suspicion (i.e. as potentially tainted/malicious)?
Example (not sure of the result because I'm afraid to try it). This is the database:
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);
Then I run this pseudo-code (maybe from PHP, for example):
# 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