interview-questions

Security Questions

1. What is SQL injection?

SQL injection is a type of security vulnerability that occurs in an application’s data layer, where an attacker can insert or “inject” malicious SQL statements into an otherwise benign SQL query.

How It Happens

Impact

Prevention Techniques

  1. Use Prepared Statements (Parameterized Queries): They ensure that an attacker cannot change the intent of a query, even if SQL commands are inserted by an attacker.
  2. Use Stored Procedures: They can encapsulate the SQL logic and prevent direct access or manipulation.
  3. Input Validation: Ensure rigorous validation checks (like type, pattern, length) on all user input.
  4. Escaping User Input: If parameterized queries are not possible, ensure user input is properly escaped.
  5. Least Privilege: Ensure that the database user used by the application has the least privileges necessary.
  6. Regularly Update and Patch: Keep the database system and software up to date with the latest patches.

2. What is XSS?

Cross-Site Scripting (XSS) is a security vulnerability that allows an attacker to inject malicious scripts into content from otherwise trusted websites. XSS attacks occur when an application includes untrusted data in a web page without proper validation or escaping.

Types of XSS Attacks

  1. Reflected XSS: The malicious script comes from the current HTTP request. Typically, the attacker tricks a user into clicking a link that contains the script.
  2. Stored XSS: The malicious script is stored on the target server, such as in a database, and is then presented to users within the web application.
  3. DOM-based XSS: The vulnerability exists in the client-side code rather than the server-side. The attack occurs when the web application’s client-side script writes user-provided data to the Document Object Model (DOM).

Impact

Prevention Techniques

  1. Data Sanitization: Escaping user input to ensure that it is treated as data, not as code.
  2. Content Security Policy (CSP): Implementing CSP headers to restrict sources of executable scripts.
  3. Validate Input: Implementing rigorous validation for all user inputs.
  4. Use Secure Frameworks: Using frameworks that automatically escape XSS by design.
  5. Regularly Update Libraries: Keeping all libraries and frameworks up to date.

3. How can you stop your DBA from making off with a list of your users’ passwords?

This is an open question that has no single correct answer. The interviewer is looking for a discussion of the tradeoffs between different approaches. Things that we want to here here are:

4. What is Cross-Site Request Forgery (CSRF)?

5. What is parameter tampering?

Parameter tampering is a form of web security vulnerability where an attacker manipulates parameters exchanged between client and server in order to modify application data, such as user credentials and permissions, prices in e-commerce sites, etc. This manipulation can occur in various ways, including altering hidden fields or query strings in URLs.

How It Happens

Impact

Prevention Techniques

  1. Validation on Server-Side: Ensure all data received from the client is validated on the server side.
  2. Use of Session Variables: Store important data in server-side session variables instead of sending it back and forth to the client.
  3. Avoid Revealing Sensitive Information: Minimize the use of sensitive information in parameters, especially in visible ones like URL query parameters.
  4. HTTPS: Use HTTPS to encrypt data in transit, preventing tampering during transmission.
  5. Regular Security Audits: Conduct security audits and penetration testing to identify and fix vulnerabilities.

6. What is a DoS attack? And what is a DDoS attack?

DoS Attack

DDoS Attack

Differences