Job interviews2:46
Job interviews · Software developer · Advanced
Web Developer: Security Basics, Passwords, Injection and Accessمقابلة مطوّر ويب: أساسيات الأمان وكلمات المرور والحقن والصلاحيات
- Kamal
- Lina
0:00 / 2:46
Transcript
- KamalThanks for coming, Lina. These are basic security questions that every web developer should be able to answer. I'm not looking for an expert, just clear thinking.
- LinaUnderstood. I'll explain what I know and I'll say when I'm unsure.
- KamalHow should a web application store user passwords?
- LinaNever in plain text, and not encrypted either, because encryption can be reversed. I'd store a hash made with a slow password hashing algorithm, such as Argon2id or bcrypt, with a unique salt for each password. The library usually handles the salt.
- KamalWhy not a fast hash like SHA-256?
- LinaBecause fast hashes let an attacker try a huge number of guesses per second if the database leaks. A slow algorithm makes each guess expensive. The unique salt also stops precomputed lookup tables.
- KamalNow a query. A developer builds the SQL text by joining a string with the username from the login form. What is the risk?
- LinaIt's SQL injection. The user's input becomes part of the SQL command, so an attacker can change the logic of the query, for example to read or change data they should not touch.
- KamalHow do you prevent it?
- LinaI use parameterized queries, so the SQL structure is fixed and the values are sent separately. An ORM usually does this for me, but I'd still be careful with any raw query. For things like a column name or a sort direction, which can't be parameters, I'd allow only a fixed list of values.
- KamalIs escaping the quotes enough?
- LinaI wouldn't rely on that. Parameterized queries are the right first choice. Manual escaping is easy to get wrong.
- KamalDifferent problem. A user opens the page for order one thousand and, by changing the number in the address to one thousand and one, sees another customer's order. What is wrong?
- LinaThe server checks that the user is logged in, which is authentication, but it doesn't check that this order belongs to this user, which is authorization. It's a broken access control problem.
- KamalHow do you fix it?
- LinaOn every request, the server must check that the current user is allowed to see that specific order, for example by filtering the query by the user's ID. I wouldn't trust hiding the link in the interface, because the user can send any request. And I'd add a test for it.
- KamalLast question. What would you not feel confident doing alone?
- LinaDesigning a full authentication system from scratch, or reviewing cryptography. For those I'd use well-tested libraries and ask a security specialist to review it.
- KamalThat's a sensible answer. Thank you, Lina.