Skip to content
Software development
ASD ISMISM-1276

ASD ISM 1276 Use safe database query methods

What it says

Parameterised queries or stored procedures, instead of dynamically generated queries, are used by software for database interactions.

Quoted as published. Everything else on this page is written by Control Stack.

In plain English

Software must reach databases only through parameterised queries or stored procedures, never dynamically generated queries (query text put together while the software runs), whatever goes into them.

Software must use parameterised queries or stored procedures for every database interaction, instead of dynamically generated queries, assembled as text at run time, often with input joined in. A parameterised query has placeholders whose values are passed separately from the query text, so they cannot change the query. A stored procedure is a routine saved in the database and called with parameters. Either is acceptable, but a procedure that builds and runs query text inside itself is still dynamic. The ISM applies this to software the organisation develops or commissions.

Why it matters

Joining input into query text is what makes SQL injection possible: crafted input rewrites the query, letting a malicious actor read, alter or delete data or reach the database server. With values passed separately, input stays data and cannot change what the query does.

How to implement

  1. Find every query whose text is built from variable data.

    Search the code for database calls that join or format strings, including raw-query features of data access libraries, stored procedure calls written as text and AI features that write their own queries. Static application security testing (ISM-0402) can flag many.

  2. Rewrite each as a parameterised query or stored procedure call.

    Put a placeholder wherever a value goes and pass the values through the database driver's parameter binding. Call stored procedures with bound parameters too, not by building the call as text. Give AI features fixed parameterised queries to call instead of writing their own.

  3. Check stored procedures for query text built inside them.

    A procedure that assembles a query from its parameters and executes it is still a dynamically generated query. Rewrite it with fixed statements that use its parameters directly.

  4. Handle parts that cannot be placeholders.

    Table names, column names and sort direction usually cannot be passed as parameters, so write a fixed query for each allowed option and use the input only to choose one. Where a component you cannot change builds queries from text, treat it as a shortfall to fix or replace, not as compliant.

Keep it running

Keep a static analysis rule or code review check that flags any new query whose text is built from variable data, and fail the build on it. Recheck when adopting a new data access library or database, since raw-query features can bring dynamic queries back.

Evidence and audit

  1. Check 1 of 3What an auditor asks for

    Ask for

    A static analysis scan and code search of the software's repositories for queries whose text is built from variable data.

    Look at

    Every database call the scan finds that is not a parameterised query or a stored procedure call with bound parameters.

    Good evidence

    No database call builds query text from variable data; every call uses placeholders with bound values or calls a stored procedure with bound parameters.

  2. Check 2 of 3What an auditor asks for

    Ask for

    The definitions of the stored procedures the software calls, or a sample of them.

    Look at

    Whether any procedure assembles query text from its parameters and executes it.

    Good evidence

    No examined stored procedure builds and executes query text from its parameters.

  3. Check 3 of 3What an auditor asks for

    Ask for

    A test in which a unique marker value is entered through a sample of inputs, with the database's statement log for that session.

    Look at

    How the marker reaches the database, using its statement log and, where the driver or the log merges values into the statement text, the code that sends it.

    Good evidence

    For every sampled input, the marker is bound to a placeholder or a stored procedure parameter, and no code joins it into query text.

Mappings

Closest match in ISO/IEC 27001: A.8.25, Secure development life cycle, which this control partially meets.

ISO 27001

ISO/IEC 27001: 2 mappings

  • A.8.25Secure development life cyclePartially meets
  • A.8.28Secure codingPartially meets

Mappings show how controls relate across frameworks. They do not imply full equivalence or certification.