Summary
Magistrala before 1.0.0 contains a SQL injection vulnerability in its timescale-reader and postgres-reader HTTP API services. An authenticated attacker, including one with a self-registered account where registration is enabled, may manipulate the format query parameter to execute unintended SQL and access or alter data beyond the intended tenant boundary.
Affected context
The vulnerability occurs in deployments using Magistrala's timescale-reader or postgres-reader HTTP APIs when the format query parameter is incorporated into a SQL FROM clause without parameterization or identifier quoting. Risk is higher when attackers can create accounts, the database role has superuser-level privileges, and the affected services can reach sensitive database files or loadable components.
Exploit preconditions
- Attack surface: HTTP API endpoints exposed by the timescale-reader or postgres-reader services
- Required access: An authenticated account; self-registration may make account creation possible where enabled
- Trigger point: Processing a request containing the format query parameter
- Why exploitation is possible: User-controlled input is inserted into a SQL FROM clause without safe parameterization or identifier validation
- Privilege condition: The impact may be amplified when the application connects using a PostgreSQL superuser or an equivalently privileged role
Why this happens
The underlying bug is SQL injection caused by constructing a SQL statement with untrusted input in a structural database position. A format parameter intended to identify a relation or query source is interpolated directly into the FROM clause rather than being constrained to approved identifiers or represented through a safe query-building mechanism. This behavior maps to CWE-89 because attacker-controlled input can alter the intended SQL command and its execution semantics.
Potential impact
- Attackers may read data belonging to other tenants
- Attackers could access sensitive PostgreSQL system information, including password hashes
- Attackers may modify or delete database records
- The database process may read from or write to arbitrary files, subject to operating-system permissions
- Attackers could execute code as the PostgreSQL operating-system user if database and host conditions permit
- The broader service or platform may be compromised
General mitigation guidance
Mitigation generally focuses on removing user-controlled SQL structure and
reducing the privileges available to the affected services.
Common defensive patterns include:
- Use parameterized queries for values and allowlisted, safely quoted identifiers for structural database elements
- Replace free-form format expressions with a finite set of application-defined options
- Validate input against an explicit schema before query construction
- Use dedicated database roles with only the permissions required by each reader service
- Avoid database superuser credentials for application connections
- Restrict database file access, extension loading, and operating-system capabilities
- Limit account self-registration and API exposure according to deployment needs
- Apply tenant-isolation checks independently of client-supplied query parameters
How teams detect issues like this
Detection approaches may include:
- Static analysis rules for string interpolation, concatenation, or formatting
used to build SQL statements
- Code review checks for request parameters appearing in SQL identifiers,
table names, clauses, or other query structure
- Testing that verifies unexpected format values are rejected and that tenant
boundaries remain enforced
- Database audit logging for unusual query structures, system catalog access,
file functions, privilege changes, or extension-loading activity
- API monitoring for repeated requests containing anomalous format values or
cross-tenant access patterns
- Policy enforcement requiring parameterized queries, approved query builders,
and least-privilege database roles
Automated code-review and application-security tools may help identify
injection-prone query construction, but should be supplemented with runtime
authorization and database-privilege checks.

