DP-420 practice question 3 of 25

You have a database in an Azure Cosmos DB Core (SQL) API account. You need to create an Azure function that will access the database to retrieve records based on a variable named accountnumber. The solution must protect against SQL injection attacks. How should you define the command statement in the function?

Full set: 144 questions
Answer options
A: cmd = "SELECT * FROM Persons p WHERE p.accountnumber = 'accountnumber'"
B: cmd = "SELECT * FROM Persons p WHERE p.accountnumber = LIKE @accountnumber"
C: cmd = "SELECT * FROM Persons p WHERE p.accountnumber = @accountnumber" Correct answer
D: cmd = "SELECT * FROM Persons p WHERE p.accountnumber = '" + accountnumber + "'"
Correct Answer:
C. cmd = "SELECT * FROM Persons p WHERE p.accountnumber = @accountnumber"
Explanation

Using parameterized queries is the recommended mitigation against SQL injection in Cosmos DB. Parameters are referenced with the @ symbol inside the query text and are supplied separately to the SDK or Azure Function binding, ensuring the input is treated strictly as data.

Why Incorrect

A. Embeds user input directly in the query string, leaving it vulnerable to injection.
B. “= LIKE @accountnumber” is syntactically invalid and still insecure.
D. String concatenation of user input bypasses parameterization and permits injection attacks.

References

1. Microsoft Docs – “Parameterized queries in Azure Cosmos DB SQL API”

section “Syntax” (https://learn.microsoft.com/azure/cosmos-db/sql/query-parameterized).

2. Microsoft Docs – “Azure Functions Cosmos DB binding”

subsection “Using parameters in queries” (https://learn.microsoft.com/azure/azure-functions/functions-bindings-cosmosdb-v2-output).

Scroll to Top