Summary
An SQL injection issue in the metrics-service retention policy management of Amazon mcp-gateway-registry allows crafted table_name values to be interpolated directly into SQL statements.
When an authenticated remote user can control this identifier position, they may execute arbitrary SQL queries against the backing database.
Affected context
This vulnerability occurs in deployments of Amazon mcp-gateway-registry that expose the metrics-service retention policy management component to authenticated users.
It is relevant where user-controlled or API-supplied table_name values are used to construct SQL statements dynamically, and those identifiers are not rigorously validated, normalized, or parameterized.
Environments with shared database instances or multi-tenant metrics schemas are more exposed, as misuse of identifier interpolation can affect other tables or logical data domains.
Exploit preconditions
- Attack surface: The retention policy management functionality in the metrics-service API.
- Required access: Authenticated remote access capable of supplying or influencing the table_name parameter.
- Trigger point: Invocation of operations that build SQL statements using the table_name value in identifier position (e.g., retention updates, purges, or table-specific maintenance).
- Why exploitation is possible: The implementation interpolates table_name directly into SQL text without enforcing strict identifier validation or safe parameterization, enabling crafted values to alter the intended query structure.
Why this happens
The underlying bug is a classic instance of CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').
The metrics-service constructs SQL statements by concatenating or interpolating a table_name value into the query in identifier position, but does not enforce strict constraints on allowed characters, expected formats, or known table names.
Because the application treats this externally supplied value as trusted, special SQL characters and additional fragments can be injected, transforming the original query into one that performs unintended operations.
Abstractly, this pattern arises whenever untrusted data is used to build dynamic SQL rather than being constrained to a safe, pre-defined identifier set or handled by mechanisms that prevent control over query structure.
Potential impact
- Authenticated users may execute arbitrary SQL queries against the metrics-service database.
- Data in metrics-related tables could be read, modified, or deleted beyond intended retention operations.
- Retention policies and historical telemetry may be corrupted or wiped, impacting observability and compliance reporting.
- Attackers could pivot to broader data exposure if the same database hosts additional application schemas.
- Database integrity and availability may be affected by destructive or resource-intensive queries.
General mitigation guidance
Effective mitigation centers on eliminating direct string interpolation of untrusted values into SQL and enforcing strong trust boundaries around identifiers.
Recommended secure patterns include:
- Constrain table_name and similar identifier inputs to a fixed, application-controlled list or a rigorously validated whitelist, rather than accepting arbitrary strings.
- Avoid dynamic SQL where possible; when dynamic behavior is required, use database features that separate logic from data, such as prepared statements, and ensure identifiers cannot alter query structure.
- Apply strict input validation on any field used as an identifier, limiting allowed characters to a minimal safe subset and rejecting or normalizing unexpected formats.
- Design the metrics-service to operate under least-privilege database roles, with only the minimal permissions required for retention operations to limit blast radius.
- Implement separation of concerns so that user-facing APIs do not directly construct SQL, but route through well-reviewed data-access layers that encapsulate safe query construction patterns.
How teams detect issues like this
Organizations can detect and manage this class of vulnerability by:
- Using static analysis or linters configured to flag dynamic SQL construction, particularly concatenation or interpolation of user-controlled values into queries.
- Incorporating secure coding guidelines and code review checklists that call out any use of table_name or other identifiers in SQL without validation or constrained selection.
- Applying centralized data-access layers where queries are built via parameterization and vetted helper functions, allowing audits of query-building APIs rather than scattered ad hoc SQL construction.
- Monitoring database activity for anomalous statements originating from application accounts, such as unexpected DDL operations, cross-schema access, or unusually broad SELECTs.
- Leveraging automated application security testing tools (SAST/DAST) configured to probe APIs for SQL injection behavior, especially where identifier-like inputs are present.

