/

CVE-2026-32950

Severity:

HIGH RISK

(8.8)

SQL Injection leading to OS Command Execution

CVE-2026-32950

Analyzed

Vulnerability type

Category:

SQL Injection leading to OS Command Execution

CWE:

CWE-78, CWE-89

Impact:

Remote Code Execution via SQL Injection

Severity:

HIGH RISK

(8.8)

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

SQLBot versions prior to 1.7.0 contain a critical SQL injection flaw in the /api/v1/datasource/uploadExcel API, where attacker-controlled Excel sheet names are concatenated into PostgreSQL table names and COPY statements without proper sanitization.

Any authenticated user can abuse this to reach remote code execution via PostgreSQL's COPY ... TO PROGRAM feature, leading to full backend compromise and database takeover.

Affected context

This vulnerability arises in SQLBot deployments that:

  • Expose the /api/v1/datasource/uploadExcel endpoint to authenticated users
  • Use PostgreSQL as the backend database
  • Allow uploaded Excel files to drive dynamic table creation and COPY operations

The risk is highest where low-privileged or broadly provisioned accounts can upload Excel files and where the database user has access to COPY ... TO PROGRAM or file-system operations.

Exploit preconditions

  • Attack surface: HTTP API endpoint /api/v1/datasource/uploadExcel
  • Required access: Any authenticated user account, including lowest-privileged roles that can upload Excel datasources
  • Trigger point: Processing of uploaded Excel files where:
  • Sheet names are concatenated into table names (datasource.py#L351)
  • Those table names are interpolated into PostgreSQL COPY statements via f-strings (datasource.py#L385-L388)
  • Why exploitation is possible:
  • Sheet names are not sanitized or identifier-quoted before being used in SQL
  • COPY statements are composed via string interpolation, not parameterized queries
  • PostgreSQL's COPY ... TO PROGRAM can execute shell commands when invoked by a sufficiently privileged database role
  • The 31-character sheet name limit can be bypassed with a two-stage upload flow, enabling construction of a malicious SQL fragment that injects a TO PROGRAM 'sh' clause

Why this happens

The underlying bug is a classic SQL injection pattern (CWE-89) combined with unsafe command construction (CWE-78) at the database level.

Instead of treating Excel metadata as untrusted input, the implementation directly concatenates sheet names into PostgreSQL identifiers and embeds them inside COPY statements using Python f-strings. Because these values are neither validated nor safely quoted, an attacker can break out of the intended identifier context and append arbitrary SQL, including COPY ... TO PROGRAM constructs that execute shell commands. This reflects a broader insecure pattern: dynamically building SQL strings from user-controlled data without rigorous escaping, parameterization, or whitelisting, particularly dangerous when the SQL features being invoked can interact with the underlying OS.

Potential impact

  • Execution of arbitrary shell commands as the postgres user on the database host
  • Reading and exfiltrating sensitive system files (e.g., /etc/passwd, /etc/shadow, configuration secrets)
  • Complete compromise and modification of all PostgreSQL databases managed by the vulnerable instance
  • Planting backdoors or persistence mechanisms within the database or host environment
  • Data corruption, deletion, or unauthorized modification of application data
  • Lateral movement to other services that trust the compromised database or host

General mitigation guidance

Effective mitigation focuses on treating all file-derived metadata as untrusted and eliminating dynamic SQL construction paths that mix logic and data:

  • Use parameterized queries or safe query builders wherever possible, even for identifiers, and avoid string concatenation with f-strings for SQL.
  • If dynamic identifiers are unavoidable, apply strict validation and whitelisting (e.g., regex constraints, length limits, allowed character sets) and use database-specific identifier-quoting utilities.
  • Restrict or avoid dangerous database capabilities such as COPY ... TO PROGRAM, or assign them only to narrowly scoped roles that are never used for handling user-supplied content.
  • Separate application roles: use a minimally privileged database user for upload/ingestion operations that cannot run OS-level commands or access sensitive schemas.
  • Normalize the ingestion pipeline so that uploaded files are parsed into a safe internal model and only then mapped to fixed, pre-defined schema and table names instead of arbitrary names derived from user-controlled sheet labels.
  • Implement robust input validation on uploaded file contents and metadata, rejecting or sanitizing unexpected patterns long before they reach SQL construction.

How teams detect issues like this

To detect this and similar issues, organizations can:

  • Apply static analysis rules that flag:
  • Direct use of f-strings or string concatenation around SQL keywords (SELECT, INSERT, COPY, etc.) combined with user-derived variables
  • Construction of SQL statements using values derived from file metadata (e.g., sheet names, file names) without validation or quoting
  • Use of dangerous SQL features like COPY ... TO PROGRAM in application code paths reachable from user inputs
  • Conduct targeted code reviews of:
  • All endpoints that process file uploads or dynamic query generation
  • Data access layers that mix business logic and raw SQL string building
  • Employ runtime monitoring and database auditing to detect:
  • Unexpected COPY ... TO PROGRAM usage
  • SQL patterns with unusual identifiers or shell-related tokens (e.g., 'sh', '/bin', '>', '>>') near COPY statements
  • Integrate security-focused linters or SAST tools into CI/CD pipelines to enforce policies against unsafe SQL construction and to highlight instances where user input directly influences query text.

Sources

SourceLink
github.comgithub.com/dataease/SQLBot/commit/39f2203cec4bb4b0aa541710733fe7608e3d3c48
github.comgithub.com/dataease/SQLBot/releases/tag/v1.7.0
github.comgithub.com/dataease/SQLBot/security/advisories/GHSA-7hww-8rj5-7rmm

Frequently asked

questions

Yes. Any user who can reach the /api/v1/datasource/uploadExcel endpoint and authenticate can attempt exploitation, assuming the backend is reachable over the network.

Only the lowest level of application authentication is required, as long as that role can upload Excel datasources. No direct database credentials or OS-level access are necessary.

The most robust fix pattern is to eliminate string-based SQL construction for user-derived values by using parameterized queries, rigorous identifier validation and quoting, and by disabling or isolating dangerous database features like COPY ... TO PROGRAM for application-facing roles.

Adopt a defensive design where file metadata and user inputs are always treated as untrusted, enforce secure coding standards around dynamic SQL, integrate automated static analysis into your CI pipeline, and ensure database roles follow least-privilege principles with restricted access to OS-interacting functionality.

Find out what's already
exploitable in your codebase.