Issue
SELECT *
FROM admin_table
WHERE username = '' OR '1'='1' AND password = '';
SELECT *
FROM admin_table
WHERE username = '' OR 1=1 OR '1'='1' AND password = '';
How do the above two SQL statements get interpreted by SQL Server?
What are the scenarios the WHERE clause is always True?
Solution
WHEREis true ifusernameis blank, or ( 1=1 (ie. true) andpasswordis blank), so either one has to be blankWHEREis true ifusernameis blank, or 1=1, or ( 1=1 andpasswordis blank) so always true.
The real solution is NOT to try and outsmart SQL injection by sanitizing or writing odd queries. The solution is to separate code and data. Code is executed, data is not. Therefore, always parameterize your queries.
In my personal opinion, the biggest issue facing SQL as a language is that it encourages ad-hoc interpreted scripts that mix code with data absolutely everywhere.
If code had to be compiled fully before it got anywhere near the DB, injection would not be such an issue.
Answered By - Charlieface Answer Checked By - Robin (sql.easybugfix Admin)
Post a Comment
Post a Comment