Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Detecting SQL Injection

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Detecting SQL Injection. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Arch Capital is reviewing user-supplied text before it reaches a security filter. Write a function that detects whether an input string contains likely SQL injection patterns.

Given a string text, return True if it contains a suspicious SQL injection pattern, otherwise return False.

A string is considered suspicious if, after lowercasing it, it contains any of the following:

  1. A SQL comment marker: --, /*, or */
  2. A statement separator: ;
  3. A tautology pattern such as or 1=1 or or '1'='1'
  4. A SQL keyword sequence commonly used in injection attempts, such as union select, drop table, or insert into

Treat repeated spaces, tabs, and newlines as whitespace. Matching should be case-insensitive.

Constraints

  • 1 <= len(text) <= 10^4
  • text contains printable ASCII characters and whitespace
  • Matching is case-insensitive
  • Return a boolean value

Function Signature

def detect_sql_injection(text):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output