/

CVE-2026-41167

Severity:

CRITICAL RISK

(9.1)

SQL Injection in Jellystat API Endpoints Leading to

CVE-2026-41167

Deferred

Vulnerability type

Category:

SQL Injection

CWE:

CWE-89

Impact:

Remote Code Execution via Database (PostgreSQL Host Compromise)

Severity:

CRITICAL RISK

(9.1)

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

Jellystat, a statistics app for Jellyfin, contains SQL injection flaws where unsanitized request-body fields are directly interpolated into raw SQL queries for multiple API endpoints.

An authenticated user can inject arbitrary SQL to read sensitive tables and, due to the use of node-postgres' simple query protocol and a highly privileged database role, escalate the attack to arbitrary command execution on the PostgreSQL host.

Affected context

This vulnerability affects Jellystat deployments that:

  • Expose the vulnerable API endpoints, including:
  • POST /api/getUserDetails
  • POST /api/getLibrary
  • Construct SQL queries by concatenating or interpolating request-body fields directly into query strings.
  • Use node-postgres' simple query protocol without parameter arrays, allowing stacked SQL statements.
  • Run PostgreSQL with a role that has powerful privileges (e.g., superuser as provided in the default docker-compose.yml).

In these environments, any authenticated Jellystat user with access to the affected endpoints may be able to issue arbitrary SQL queries and potentially reach a command execution primitive on the database host.

Exploit preconditions

  • Attack surface: Jellystat HTTP API endpoints that accept JSON bodies and translate fields into SQL queries.
  • Required access: Valid authenticated Jellystat account capable of calling POST /api/getUserDetails or POST /api/getLibrary (no special role needed under typical configurations).
  • Trigger point: Submission of crafted request-body parameters that are interpolated into raw SQL without sanitization or parameter binding.
  • Why exploitation is possible:
  • Application code embeds user-controlled values directly into SQL strings (query concatenation).
  • node-postgres' simple query protocol is used without parameter arrays, enabling stacked queries.
  • The PostgreSQL role commonly used in default deployments has superuser privileges, allowing use of features like COPY ... TO PROGRAM to execute OS commands on the database host.

Why this happens

The root cause is unsafe construction of SQL statements from user-controlled input, mapping directly to CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').

Instead of using parameterized queries or query builders that keep SQL structure separate from data, the affected Jellystat code interpolates request-body fields into raw SQL strings. This pattern treats user input as part of the SQL syntax, allowing attackers to:

  • Break out of the intended query structure.
  • Append additional SQL clauses or entirely new statements (stacked queries).

The use of node-postgres' simple query protocol without parameter arrays further broadens the attack surface, as it does not enforce separation between query text and parameters. Combined with a highly privileged PostgreSQL role, the injection flaw escalates from data exposure to full database and underlying host compromise.

Potential impact

  • Full read access to any database table, including:
  • app_config containing:
  • Jellystat admin credentials
  • Jellyfin API key
  • Jellyfin host URL
  • Other potentially sensitive application or user data tables
  • Modification or deletion of application data and configuration.
  • Creation of new database users or escalation of privileges within PostgreSQL.
  • Execution of arbitrary SQL statements, including stacked queries.
  • Remote command execution on the PostgreSQL host using COPY ... TO PROGRAM or similar features under superuser-like roles.
  • Complete compromise of the Jellystat instance and possible pivoting into the broader infrastructure where PostgreSQL runs.

General mitigation guidance

Effective mitigation focuses on eliminating dynamic SQL construction from untrusted input and reducing database privileges:

  • Use parameterized queries everywhere:
  • Replace string interpolation or concatenation with prepared statements and parameter arrays offered by node-postgres.
  • Ensure that all user-controlled values (filters, IDs, search terms) are passed as parameters, not embedded directly into query text.
  • Adopt safe query-building patterns:
  • Use query builders or ORM layers that separate SQL structure from data and provide automatic escaping.
  • For dynamic filters or sorting, whitelist allowed columns and directions and map them to static SQL fragments, never trusting raw field names from the client.
  • Enforce least privilege for database roles:
  • Avoid using PostgreSQL superuser roles for application connections.
  • Grant only the minimal permissions needed (SELECT/INSERT/UPDATE/DELETE on specific schemas and tables).
  • Restrict access to dangerous capabilities such as COPY ... TO PROGRAM, CREATE EXTENSION, and superuser-only functions.
  • Harden configuration and secrets storage:
  • Store admin credentials, API keys, and connection details in a secrets store or environment configuration, not in broadly accessible tables.
  • Limit which roles can read configuration tables.
  • Input and behavior validation:
  • Validate request-body fields for type, format, and length at the API layer before any interaction with the database.
  • Reject unexpected fields or values that do not match defined schemas.
  • Secure-by-default deployment templates:
  • Ship container and docker-compose configurations that use non-superuser accounts by default.
  • Make secure database privileges and parameterized access the standard deployment pattern rather than an optional hardening step.

How teams detect issues like this

Detection typically combines static review of source code with runtime monitoring of database activity:

  • Static analysis and code scanning:
  • Configure static analysis rules to flag:
  • Direct string concatenation or template literals used to build SQL queries.
  • Calls to node-postgres where user-supplied data is interpolated into query text instead of passed as parameters.
  • Use automated code review tools to search for SELECT ... ${variable}-style constructs and non-parameterized client.query() usage.
  • Secure code review practices:
  • During reviews, explicitly check all database-accessing functions for:
  • Parameterized query usage.
  • Whitelisting of column names and operations for dynamic queries.
  • Absence of any user-controlled content in raw SQL fragments beyond validated mappings.
  • Require reviewers to confirm that database credentials and connection roles adhere to least privilege.
  • Database-level monitoring and policies:
  • Enable logging of all queries or at least:
  • Use of COPY ... TO PROGRAM.
  • Unusual DDL statements from application roles.
  • Stacked queries or multi-statement executions.
  • Use database audit extensions or external monitoring to alert on suspicious patterns coming from application-connected roles.
  • Runtime application monitoring:
  • Track abnormal API usage patterns such as:
  • Large or unexpected payloads to endpoints that trigger database lookups.
  • Requests that cause significantly longer or more complex queries than normal.

Sources

SourceLink
github.comgithub.com/CyferShepard/Jellystat/commit/735fe7c6eb0e3e34e92a8a82fd21914d76693665
github.comgithub.com/CyferShepard/Jellystat/security/advisories/GHSA-fj7c-2p5q-g56m

Frequently asked

questions

In many default-style deployments where Jellystat is reachable by multiple users and uses the superuser-like PostgreSQL role from the provided docker-compose.yml, this vulnerability can be highly exploitable. Any authenticated user capable of calling the affected endpoints could potentially run arbitrary SQL and escalate to command execution on the database host.

Only HTTP access to Jellystat is required. The attacker sends crafted POST requests to vulnerable API endpoints, and Jellystat forwards the injected SQL to PostgreSQL over its existing database connection. No separate database credentials or network access are required.

The safest approach is to adopt parameterized queries consistently and prohibit raw SQL concatenation from user input. All variables must be passed through node-postgres parameter arrays or a safe query builder/ORM, while the database role used by the app must be reduced to the minimal privileges necessary for normal operations.

Prevention relies on process and tooling: mandate parameterized queries in coding standards, enforce them with static analysis and code review checklists, use least-privileged database roles in all environments, and design APIs so that user input is validated and mapped to pre-defined, whitelisted query structures rather than being used directly in SQL text.

Find out what's already
exploitable in your codebase.