Spokalyالإنجليزية تبدأ من السمع
مقابلات العمل · مبرمج · متقدّم

مقابلة مطوّر ويب: أساسيات الأمان وكلمات المرور والحقن والصلاحياتWeb Developer: Security Basics, Passwords, Injection and Access

  • Kamal
  • Lina
0:00 / 2:46
الشريط الملوّن مقسوم حسب المتكلّم، فترى من يتحدّث ومتى.

النص

  1. Kamal
    Thanks 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.
  2. Lina
    Understood. I'll explain what I know and I'll say when I'm unsure.
  3. Kamal
    How should a web application store user passwords?
  4. Lina
    Never 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.
  5. Kamal
    Why not a fast hash like SHA-256?
  6. Lina
    Because 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.
  7. Kamal
    Now a query. A developer builds the SQL text by joining a string with the username from the login form. What is the risk?
  8. Lina
    It'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.
  9. Kamal
    How do you prevent it?
  10. Lina
    I 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.
  11. Kamal
    Is escaping the quotes enough?
  12. Lina
    I wouldn't rely on that. Parameterized queries are the right first choice. Manual escaping is easy to get wrong.
  13. Kamal
    Different 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?
  14. Lina
    The 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.
  15. Kamal
    How do you fix it?
  16. Lina
    On 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.
  17. Kamal
    Last question. What would you not feel confident doing alone?
  18. Lina
    Designing 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.
  19. Kamal
    That's a sensible answer. Thank you, Lina.