by sepositus · 1y ago · 0 comments
I'm not the biggest expert on databases, although I've worked with them a bit, but how does this occur in the first place? Usually, associations are done with primary/foreign keys. What database would allow null in that case?
Robert'); DROP TABLE Students;--
And see that it now provides 'Robert DROP TABLE Students'
Problem solved! And then later somebody else comes along, ignorant of the sanitization step, and provides NULL
But the code strips special characters and adds quotes, so they've actually inserted: 'NULL' final String myNullString = "" + null;
System.out.println(myNullString);CREATE TABLE orders ( id INT PRIMARY KEY, customer_id INT NULL, FOREIGN KEY (customer_id) REFERENCES customers(id) );
vs
CREATE TABLE orders ( id INT PRIMARY KEY, customer_id INT NOT NULL, FOREIGN KEY (customer_id) REFERENCES customers(id) );