/

CVE-2026-24908

Severity:

CRITICAL RISK

(9.9)

SQL Injection in OpenEMR Patient REST API

CVE-2026-24908

Analyzed

Vulnerability type

Category:

SQL Injection

CWE:

CWE-89

Impact:

Authenticated SQL Injection leading to PHI exposure and database compromise

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

An SQL injection vulnerability in OpenEMR's Patient REST API allows authenticated API users to inject arbitrary SQL expressions through the _sort parameter, which is used directly in an ORDER BY clause.

When exploited, this flaw can expose protected health information (PHI), disclose or modify database contents, and potentially compromise credentials stored in the database.

Affected context

The vulnerability occurs in OpenEMR deployments that:

  • Expose the Patient REST API endpoint
  • Grant API access tokens or credentials to users or integrations
  • Allow clients to pass a _sort parameter that is reflected into SQL ORDER BY clauses

It manifests when user-controlled sort field names are concatenated into SQL statements without validation or proper identifier escaping. The risk is present in environments where the database contains PHI or other sensitive operational data, which is typical for electronic health record systems.

Exploit preconditions

  • Attack surface: Patient REST API endpoint that supports sorting via a _sort parameter.
  • Required access: Valid, authenticated API access (e.g., API key, bearer token, or equivalent credentials).
  • Trigger point: Sending crafted _sort values that are incorporated into the SQL query's ORDER BY clause.
  • Why exploitation is possible: The application treats _sort as a trusted identifier and injects it into SQL without:
  • Strict allowlisting of sortable columns, or
  • Proper identifier quoting/escaping, or
  • Use of parameterized constructs for dynamic ordering.

As a result, attacker-controlled input can alter the structure of the SQL query.

Why this happens

This vulnerability stems from dynamic SQL construction where user input is directly interpolated into an ORDER BY clause.

Instead of mapping the _sort parameter to a predefined set of allowed column names, the code appears to:

  • Accept arbitrary field names from the client, and
  • Embed them into the query string without robust validation or escaping.

This behavior corresponds to CWE-89: Improper Neutralization of Special Elements used in an SQL Command, where attacker-supplied data influences SQL syntax rather than being treated as inert values. Even though the context is an ORDER BY clause, unvalidated identifiers and expressions can still be abused to inject additional SQL fragments or manipulate query semantics.

Potential impact

  • Exposure of Protected Health Information (PHI) via unauthorized reads of patient or related tables.
  • Unauthorized access to or enumeration of other sensitive database records.
  • Extraction of password hashes or authentication tokens stored in the database.
  • Tampering with clinical data, billing records, or configuration tables, leading to data integrity issues.
  • Escalation of privileges if sensitive configuration or access control data can be modified.
  • Potential pivoting to underlying infrastructure if database-level features or stored procedures can be abused.

General mitigation guidance

Addressing this class of vulnerability usually focuses on removing direct trust in client-supplied identifiers and expressions:

  • Apply strict allowlists for sortable fields: Map _sort values to a fixed, hard-coded set of column names and directions (e.g., name, dob, with optional asc/desc flags). Reject or default on unknown values.
  • Avoid concatenating raw sort parameters into SQL: Use query builder abstractions or ORM facilities that separate SQL structure from user input, even for ORDER BY clauses.
  • Normalize and validate direction flags: If clients can specify ascending/descending ordering, restrict input to known tokens (asc, desc) and map them to safe constants.
  • Enforce least privilege on database accounts: Configure the application's database user with the minimal privileges required to operate, reducing the blast radius of a successful injection.
  • Centralize query construction patterns: Implement shared helper functions or services for building paginated/sorted queries to ensure consistent, secure handling of filter and sort parameters across endpoints.

How teams detect issues like this

Detection often combines code-centric and behavior-centric approaches:

  • Static analysis: Configure SAST tools to flag string-based SQL construction, especially where HTTP parameters (e.g., _sort) are concatenated into queries or passed into ORDER BY clauses.
  • Code review checklists: During manual reviews, scrutinize:
  • Any dynamic query building around filtering, searching, and sorting.
  • Places where field names or directions come directly from API parameters.
  • Runtime monitoring: Enable database query logging or application-level telemetry to detect anomalous queries, such as unexpected syntax in ORDER BY statements or repeated query errors.
  • Security testing: Incorporate automated and manual injection tests covering query parameters, headers, and sorting/filtering options in API penetration tests and CI security pipelines.

Sources

SourceLink
github.comgithub.com/openemr/openemr/commit/943e23cad6e979f87cdf168807fce2a7b32dd194
github.comgithub.com/openemr/openemr/security/advisories/GHSA-rcc2-45v3-qmqm

Frequently asked

questions

Yes, if the Patient REST API is exposed over the network and reachable by clients with valid API credentials. The attack is carried out by sending crafted _sort values in API requests, but it remains constrained to authenticated callers with API access.

No. The vulnerability can typically be exploited by any user or integration that holds valid API credentials capable of invoking the Patient REST API endpoint. Elevated application roles are not strictly required, although broader privileges may increase the attacker's visibility and impact.

The most robust pattern is to stop using raw client input to construct SQL and instead:

  • Map _sort to a predefined set of allowed columns and directions, and
  • Use structured query-building utilities or ORMs that handle identifiers and ordering safely.

This approach removes the ability for arbitrary expressions to influence the SQL syntax.

Establish and enforce secure coding guidelines that:

  • Prohibit concatenating HTTP parameters directly into SQL strings.
  • Require parameterization or safe query-building mechanisms for filters, searches, and sorting.
  • Mandate security review of new and modified API endpoints, especially where dynamic query behavior is introduced.

Complement these practices with automated static analysis and routine security testing of API endpoints.

Find out what's already
exploitable in your codebase.