Question 1
What is the primary purpose of validating API input data?
- To improve API performance.
- To ensure data conforms to expected formats and prevent security vulnerabilities.
- To simplify API documentation.
- To reduce the size of API request payloads.
- To automatically generate API client libraries.
Question 2
Which type of injection attack is most directly mitigated by proper input sanitization and escaping?
- Denial of Service (DoS)
- Cross-Site Scripting (XSS)
- Buffer Overflow
- Session Hijacking
- DNS Poisoning
Question 3
If an API endpoint expects an integer representing a user ID, what is a recommended validation technique?
- Allow any string as input.
- Check if the input is numeric and within a reasonable range.
- Assume the client will always send a valid integer.
- Base64 encode the integer before sending.
- Hash the integer before sending.
Question 4
Consider the following code snippet (pseudocode): `if (request.getParameter('order') == 'name') { sortBy(name); }`. What security risk does this code pose if the 'order' parameter is not validated?
- SQL Injection
- Command Injection
- LDAP Injection
- Path Traversal
- XSS
Question 5
What is the principle of 'least privilege' and how does it apply to API security?
- Granting all API users administrative access for simplicity.
- Granting API users only the minimum necessary permissions to perform their tasks.
- Restricting API access to only internal network users.
- Using the shortest possible passwords for API authentication.
- Regularly changing API keys even without known breaches.
Question 6
Which of the following is NOT a common method for validating API input data?
- Whitelisting allowed characters.
- Blacklisting disallowed characters.
- Regular expression matching.
- Schema validation (e.g., using JSON Schema).
- Ignoring all input validation and trusting the client.
Question 7
Why is it important to sanitize data even after it has been validated?
- Validation is sufficient and sanitization is unnecessary.
- Different parts of the application may have different security requirements, requiring sanitization for specific contexts (e.g., HTML output).
- Sanitization is only necessary for database inputs, not other parts of the application.
- Sanitization improves API performance.
- Sanitization is only required for legacy applications.
Question 8
Which of the following is a common defense against SQL injection attacks?
- Using prepared statements or parameterized queries.
- Disabling database logging.
- Allowing direct user input in SQL queries.
- Using a weak database password.
- Exposing database credentials in client-side code.
Question 9
What is the purpose of input encoding (e.g., URL encoding, HTML encoding)?
- To compress data for faster transmission.
- To convert data into a format suitable for transmission or storage, preventing interpretation as code.
- To encrypt data for security.
- To obfuscate data to hide it from attackers.
- To reduce the size of data stored in the database.
Question 10
An API endpoint receives a file upload. Which of the following validation steps is MOST important from a security perspective?
- Checking the file size to prevent large uploads.
- Validating the file extension against an allowed list.
- Scanning the file content for malware.
- Storing the file outside the webroot.
- All of the above.