Summary
MSSQL MCP database tools can construct T-SQL batches using caller-controlled identifiers and predicates, while parameterizing only data values. If an attacker can supply crafted arguments to an exposed tool, the resulting SQL injection may allow unauthorized data access or changes; the consequences depend on the SQL login's privileges.
Affected context
The issue affects MSSQL MCP tools in mssql-mcp-core and related server, reader, and writer components when caller-controlled table, column, index, schema, predicate, or state-filter values are interpolated into T-SQL. Affected releases are core and server versions before 0.6.0 and reader and writer versions before 0.5.0. Some row-count and preview queries run before confirmation checks, so those checks may not prevent unsafe SQL from executing.
Exploit preconditions
- Attack surface: MSSQL MCP tools that accept database identifiers, predicates, or filters.
- Required access: Ability to invoke an affected tool and provide its arguments; authentication and authorization requirements depend on the deployment.
- Trigger point: Construction and execution of a T-SQL batch, including preliminary row-count or preview queries.
- Why exploitation is possible: Caller-controlled SQL structure is interpolated into queries rather than constrained to trusted identifiers or safe predicate forms. Confirmation and row-limit controls may be evaluated after a query has already executed.
Why this happens
The underlying bug is SQL injection (CWE-89). Parameterizing data values does not make dynamically interpolated SQL identifiers or free-form predicates safe. When caller-controlled values are inserted into T-SQL structure without effective validation or safe construction, the database may interpret them as additional SQL logic.
Potential impact
- Attackers may read data beyond the intended scope.
- Attackers could modify or delete database records, or perform unauthorized DDL operations.
- Confirmation prompts or row limits may not protect queries that execute before those controls are applied.
- If the SQL login is privileged and
xp_cmdshellis enabled, database compromise could potentially lead to operating-system command execution.
General mitigation guidance
Defensive patterns focus on ensuring caller input cannot define executable SQL structure:
- Bind data values through parameterized queries, and validate identifiers against trusted allowlists because identifiers generally cannot be handled as ordinary value parameters.
- Prefer structured filter inputs and safe query-building APIs over free-form predicates.
- Apply validation before any query runs, including previews and row-count checks; make confirmation and row-limit controls effective before execution.
- Restrict tool permissions and database accounts to the minimum operations and objects required.
- Disable high-risk database features such as
xp_cmdshellwhen they are not needed, and avoid exposing tools to callers who do not require them.
How teams detect issues like this
- Use static analysis to flag string interpolation or concatenation of caller-controlled values in SQL execution paths.
- Review database tools for dynamic identifiers, free-form predicates, and checks that occur only after preview or count queries.
- Enforce code-review and CI policies requiring parameter binding for values and allowlist validation for identifiers.
- Monitor database audit logs for unexpected DDL, unusual query patterns, or operations inconsistent with a tool's intended function.
- Automated code review tools may help identify risky query construction patterns.

