Summary
NginxPulse's stats API contains an unauthenticated SQL injection vulnerability involving the id and locationType parameters. A remote attacker may be able to read or modify database data and, where PostgreSQL superuser functions are available, access server files.
Affected context
The issue occurs in NginxPulse's /api/stats/:type endpoint when it processes the id and locationType parameters in SQL queries. Risk arises when parameter values are incorporated into SQL, including a quoted table-name identifier, without safe query construction and appropriate validation. The described attack does not require authentication.
Exploit preconditions
- Attack surface: Network-accessible NginxPulse stats API
- Required access: No authentication is required, according to the vulnerability description
- Trigger point: Request handling for
/api/stats/:type, whereidorlocationTypeis used - Why exploitation is possible: User-controlled values can alter the intended SQL query; database-level file operations additionally depend on PostgreSQL privileges and configuration
Why this happens
The underlying issue is unsafe construction of SQL using attacker-controlled parameter values, including a table-name identifier. If input is concatenated or quoted incorrectly rather than handled through safe query-building patterns, it can change the meaning of the query. This is CWE-89: SQL Injection. Error-based query behavior may expose data, while file access depends on the database's available privileges and functions.
Potential impact
- Attackers may read sensitive database contents.
- Attackers may alter or delete database records, depending on query behavior and privileges.
- PostgreSQL superuser functions may allow reading or writing server files where available.
- Database or application availability may be affected by unauthorized queries or changes.
General mitigation guidance
Mitigation generally centers on preventing untrusted values from changing SQL structure.
- Use parameterized queries for data values and safe, allowlisted mappings for identifiers such as table names, which generally cannot be bound as ordinary query parameters.
- Validate inputs against expected types, formats, and permitted values as an additional control.
- Avoid returning detailed database errors to unauthenticated clients.
- Restrict database accounts to the minimum privileges required; avoid granting application connections superuser capabilities or unnecessary file-operation permissions.
- Reduce exposure of sensitive API operations through appropriate access controls and network boundaries.
How teams detect issues like this
- Use static analysis to identify SQL strings assembled from request parameters, especially around identifier quoting and query-building code.
- Review the stats endpoint and its data-access layer for unsafe concatenation, dynamic identifiers, and database error handling.
- Monitor for unusual requests to the endpoint, SQL errors, unexpected database reads or writes, and use of PostgreSQL file-operation functions.
- Apply policies requiring parameterized queries and approved allowlists for dynamic SQL identifiers; automated code review tools may help identify risky patterns.

