/

CVE-2026-40906

Severity:

CRITICAL RISK

(9.9)

SQL Injection in ElectricSQL shape API

CVE-2026-40906

Modified

Vulnerability type

Category:

SQL Injection

CWE:

CWE-89

Impact:

Authentication-bypassing data access and modification via SQL Injection

Severity:

CRITICAL RISK

(9.9)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

Electric, a Postgres sync engine, contains an error-based SQL injection vulnerability in the order_by parameter of the /v1/shape API.

Any authenticated user who can call this endpoint may craft malicious ORDER BY expressions to read, modify, or delete data in the backing PostgreSQL database.

Affected context

The vulnerability exists in Electric deployments running affected versions of the Postgres sync engine where:

  • The /v1/shape API endpoint is exposed to authenticated users, and
  • The order_by request parameter is incorporated into SQL queries for PostgreSQL without strict validation, normalization, or parameterization.

It becomes relevant in multi-tenant or user-facing environments where clients can influence sorting behavior for synced data and where database permissions allow broad access through the application account.

Exploit preconditions

  • Attack surface: HTTP(S) interface for the ElectricSQL /v1/shape API.
  • Required access: Valid authenticated access to the API (e.g., a legitimate Electric client or compromised client credentials).
  • Trigger point: Submission of a crafted order_by parameter that is directly interpolated into the SQL ORDER BY clause.
  • Why exploitation is possible: The application builds SQL statements by concatenating untrusted order_by input into the query text, instead of using parameterized queries or a strict allowlist of sortable columns. This enables attackers to append or alter SQL fragments and cause the database to return detailed error messages (error-based SQL injection), which can be leveraged to enumerate schema and manipulate data.

Why this happens

This issue is a classic SQL Injection (CWE-89) caused by unsafe construction of SQL queries from user-controllable input.

Rather than treating the order_by parameter as untrusted and mapping it to known-safe column identifiers, the implementation allows arbitrary expressions from the client to be embedded into the ORDER BY clause.

ORDER BY segments are often overlooked as "non-data-bearing", but when they are built through string concatenation or templating without proper validation, the database query parser treats the injected tokens as full SQL, enabling attackers to execute additional operations using the database's own privilege context.

The underlying bug class is failure to enforce strict separation between data and code in SQL, especially in secondary query components such as sorting, grouping, and filtering clauses.

Potential impact

  • Attackers may read arbitrary data from any table accessible to the application's database role.
  • Attackers may insert, update, or delete rows, leading to data corruption, destruction, or unauthorized changes.
  • Attackers may exfiltrate sensitive information such as user records, secrets stored in the database, or internal metadata.
  • Attackers may tamper with synchronization state, potentially causing data divergence or propagation of malicious data to clients.
  • Attackers may leverage database-level capabilities (e.g., functions, extensions) to escalate impact, depending on configuration.

General mitigation guidance

Effective mitigation focuses on treating query structure as immutable and input as data only:

  • Replace ad hoc string concatenation with parameterized query builders or ORM methods that do not allow arbitrary SQL fragments from clients.
  • Normalize and strictly validate the order_by parameter using an allowlist of supported columns and fixed sort directions (e.g., asc / desc), mapping user input to predefined tokens rather than passing it through directly.
  • Encapsulate query construction in a small, reviewed layer that exposes only safe sorting options and does not accept raw SQL expressions from callers.
  • Apply least-privilege to the database role used by the sync engine so that even if a query is manipulated, it cannot access or modify unnecessary tables or schemas.
  • Enforce consistent API schemas and reject unexpected or malformed sorting expressions early, before they reach the query layer.

These patterns reduce both the injection surface and the blast radius if a similar issue slips through.

How teams detect issues like this

Detection usually combines code-level analysis and runtime monitoring:

  • Static analysis: Search for dynamic SQL construction where request parameters like order_by, sort, column, or direction are concatenated into query strings or template fragments. Custom rules can flag uses of string interpolation in ORDER BY, GROUP BY, or LIMIT clauses.
  • Code review: Pay special attention to API handlers that translate client-side query options (sorting, filtering, pagination) into SQL. Reviewers should verify that only allowlisted fields and directions are permitted and that ORMs or query builders are used safely.
  • Automated tooling: Integrate SAST tools or linters that understand SQL injection patterns into CI pipelines, particularly for layers that handle query customization.
  • Runtime monitoring: Inspect database logs and application telemetry for anomalous query shapes, such as ORDER BY clauses containing unexpected functions, subqueries, or concatenated literals, and correlate them with client requests for investigation.

Consistent review and policy enforcement around dynamic query construction greatly improve the chance of catching similar vulnerabilities early.

Sources

SourceLink
github.comgithub.com/electric-sql/electric/pull/4081
github.comgithub.com/electric-sql/electric/security/advisories/GHSA-h5rg-pxx7-r2hj
access.redhat.comaccess.redhat.com/security/cve/CVE-2026-40906
bugzilla.redhat.combugzilla.redhat.com/show_bug.cgi?id=2460291
security.access.redhat.comsecurity.access.redhat.com/data/csaf/v2/vex/2026/cve-2026-40906.json

Frequently asked

questions

It is remotely exploitable by any party that can authenticate to the ElectricSQL /v1/shape API over the network. No local server access is required, but the attacker must be able to send crafted HTTP requests as an authenticated client.

The attacker needs valid credentials or a session that allows them to invoke the affected endpoint. Once authenticated, the vulnerable order_by parameter provides a path to issue arbitrary SQL through the application's database connection.

The most robust fix is to eliminate direct use of user-controlled strings in SQL query construction. Instead, use parameterized queries or high-level query builders and strictly map user intent (e.g., "sort by created_at descending") to a predefined set of columns and directions, without ever accepting raw SQL fragments from clients.

Establish a development standard that all query customization must pass through a vetted abstraction layer that enforces allowlists, parameterization, and input normalization. Combine this with static analysis rules for dynamic SQL, security-focused code reviews on API and data access layers, and least-privilege database roles so that even if a flaw exists, its impact is constrained.

Find out what's already
exploitable in your codebase.