Interview › Security & DevSecOps
What is an injection attack, and how do you prevent SQL injection? [Advanced]
Answer
An injection attack occurs when untrusted input is interpreted as code or commands by an interpreter such as SQL, shell, LDAP, or NoSQL. SQL injection is prevented with parameterized queries, prepared statements, input validation, least-privilege database users, and avoiding dynamic SQL string concatenation.
Technical explanation
Escaping alone is error-prone and should not be the primary control when parameterization is available.
ORMs help but can still be unsafe if raw query strings are built from user input.
Least-privilege database roles limit damage if injection occurs.
Hands-on example
Unsafe: SELECT * FROM users WHERE name = '<user input>'
Safe Java pattern:
PreparedStatement ps = conn.prepareStatement("SELECT * FROM users WHERE name =?");
ps.setString(1, userInput);
ResultSet rs = ps.executeQuery();
Check how well your resume matches the role with our free resume checker— match score, ATS check, and the skills you're missing.
More Security & DevSecOps interview questions
- What is the difference between encoding, encryption, and hashing? [Advanced]
- Why do you hash and salt passwords rather than encrypt them? [Advanced]
- How do you prevent privilege escalation in a Kubernetes cluster? [Advanced]
- What are Kubernetes Pod Security Standards (privileged, baseline, restricted)? [Advanced]
- What are Linux capabilities, and why drop them in containers? [Advanced]
- What is the difference between authentication and authorization? [Advanced]
- What is certificate management, and how do tools like cert-manager help? [Advanced]
- What is the difference between a WAF, an IDS, and an IPS? [Advanced]