You find code that builds a SQL query by joining strings with user input. What is the risk and how do you fix it?
AI security · Beginner 3
Short answer
It is open to SQL injection: an attacker can type input that changes the query itself, to read, change or delete data. The fix is parameterised queries, so input is always treated as data and never as SQL. I would add least-privilege database accounts, input validation as a second layer, and a test with malicious input.
Deeper answer
When code does something like "SELECT * FROM users WHERE email = '" + email + "'", a quote in the input ends the string and the rest is run as SQL. Parameterised queries, or an ORM used properly, send the query and the values separately, so the database never parses the input as code.
Escaping by hand and blocklists of words like DROP are weak because attackers find encodings and edge cases. Defence in depth helps: the app's database user should have only the rights it needs, errors should not show SQL to users, and a web application firewall can catch common payloads. Search the codebase for the same pattern, because one bad query usually means others.
What a strong answer covers
- Names SQL injection: input changes the query
- Fix is parameterised or prepared statements
- Adds least-privilege database account
- Rejects blocklists or hand escaping as the main fix
- Tests and searches for the same pattern elsewhere
Answer it out loud in the mock interview about 1.5 min
Follow-ups to expect
- Why is escaping quotes by hand not enough?
- Can an ORM still be vulnerable to SQL injection?
Common mistakes
- Relying on a blocklist of SQL keywords
- Fixing the one query and not searching for the same pattern elsewhere
Learn it
Web app security and the OWASP Top 10
- Attackers now use LLMs to write phishing emails. What changes for defenders, and what still works?
- What is attack success rate in AI red teaming, and what are its limits as a metric?
- Threat model an LLM chatbot for a retail bank that can answer questions and show a customer's recent transactions.
- What is the CIA triad, and how would you use it to judge a security problem?
- What is data poisoning, and how would you protect a model you train or fine-tune from it?
- As a security engineer, how would you protect a company's finance team from deepfake voice or video calls from the 'CEO'?
- What is the difference between hashing and encryption, and which do you use for passwords?
- An employee's laptop shows signs of malware at 11 pm. Walk me through your incident response.
- Explain least privilege. How would you apply it to a new team's cloud and app access?
- Your SOC wants an LLM copilot to summarise alerts and suggest actions. What are the risks and how do you manage them?
- What is tool poisoning in MCP or agent tools, and how do you defend an agent against it?
- What is MITRE ATT&CK, and how does a detection team actually use it?
- A vendor says their ML intrusion detector is 99% accurate. Why might it still drown your SOC in false alarms?
- What is a model extraction attack, and how would you defend a model you serve through an API?
- Walk me through the OWASP Top 10 for LLM applications. Which risks would you check first in a RAG chatbot?
- How would you defend a company against phishing? Where do SPF, DKIM and DMARC fit in?
- A teammate wants to load a model file they downloaded from a public hub. What supply chain risks do you check?
- You are asked to red-team your company's customer support chatbot before launch. How do you go about it?
- Tell me about a security incident or near miss you handled. What did you do and what changed afterwards?
- Staff are pasting company data into public AI tools without approval. How would you handle shadow AI?
- Your SOC gets thousands of SIEM alerts a day and analysts are ignoring them. How do you fix alert fatigue?