Baja

@saltcorn/data vulnerable to SQL Injection via jsexprToSQL Literal Handler

  • Publicada: 10.04.2026
  • Actualizado: 11.10.2026 10:22

Summary

The jsexprToSQL() function in Saltcorn converts JavaScript expressions to SQL for use in database constraints. The Literal handler wraps string values in single quotes without escaping embedded single quotes, allowing SQL injection when creating Formula-type table constraints.

Vulnerable Component

File: packages/saltcorn-data/models/expression.ts, lines 117-118

ts
Literal({ value }: { value: ExtendedNode }) {
  if (typeof value == "string") return `'${value}'`;  // NO ESCAPING!
  return `${value}`;
},

Call chain: Formula constraint creation → table_constraints.ts:127 → jsexprToSQL() → Literal() → db.query() executes unsanitized SQL.

Proof of Concept

Injection via Formula Constraint

When an admin creates a Formula-type table constraint with the expression:

js
name === "test' OR '1'='1"

The jsexprToSQL() function generates:

sql
(name)=('test' OR '1'='1')

This is then executed as:

sql
ALTER TABLE "tablename" ADD CONSTRAINT "tablename_fml_1" CHECK ((name)=('test' OR '1'='1'));

The single quote in the string literal is not escaped, breaking out of the SQL string context.

More Dangerous Payload

js
name === "'; DROP TABLE users; --"

Generates:

sql
(name)=(''; DROP TABLE users; --')

Verified on Saltcorn v1.5.0 (Docker)

Direct invocation of jsexprToSQL() inside the running container confirms the vulnerability:

Input:  name === "hello"
Output: (name)=('hello')                          ← Normal

Input:  name === "test' OR '1'='1"
Output: (name)=('test' OR '1'='1')                ← Single quote NOT escaped, OR injected

Input:  name === "'; DROP TABLE users; --"
Output: (name)=(''; DROP TABLE users; --')         ← DROP TABLE injected

The test was performed on a completely fresh Saltcorn installation (zero user-created tables, default Docker setup).

PoC Screenshot

  1. Create a table after moving to the table menu
<img width="1194" height="559" alt="SCR-20260307-edqn" src="https://github.com/user-attachments/assets/a2d11102-f49b-4b2b-88ff-fced37476b6f" />
  1. Go to the table and then to Constraits
<img width="1180" height="600" alt="SCR-20260307-edsg" src="https://github.com/user-attachments/assets/b55ddace-01be-4a53-8f62-cbec98172cd7" />
  1. Go to Formula
<img width="1130" height="518" alt="SCR-20260307-edud" src="https://github.com/user-attachments/assets/8a5addc6-e681-401b-91ea-bce3b0eece54" />
  1. Create a test table for verification
<img width="857" height="294" alt="SCR-20260307-eetw" src="https://github.com/user-attachments/assets/debc8581-8145-44cb-a684-2bc3eb7adbcf" />
  1. Input the payload and save
<img width="763" height="383" alt="SCR-20260307-ehcz" src="https://github.com/user-attachments/assets/f7a3aa34-7b0b-48ea-b1df-f852f137c37f" />
  1. Check the table for testing
<img width="549" height="256" alt="SCR-20260307-ehuh" src="https://github.com/user-attachments/assets/8f6da842-0275-4729-93bf-96575f3fe963" />

Impact

  • Arbitrary SQL execution via crafted CHECK constraints
  • Data exfiltration through error-based or time-based SQL injection
  • Database schema manipulation (DROP TABLE, ALTER TABLE)
  • Potential privilege escalation via direct users table modification

Suggested Remediation

Escape single quotes in the Literal handler:

ts
Literal({ value }: { value: ExtendedNode }) {
  if (typeof value == "string") return `'${value.replace(/'/g, "''")}'`;
  return `${value}`;
},

Alternatively, use parameterized queries for constraint creation instead of string interpolation.

Software afectado

Haz clic en una tecnología para ver todas sus vulnerabilidades.

PlataformaPaqueteVersiones vulnerablesCorregida en
Paquete de npm @saltcorn/data < 1.4.5, >= 1.5.0, < 1.5.5, >= 1.6.0-alpha.0, < 1.6.0-beta.4 1.4.5, 1.5.5, 1.6.0-beta.4

Referencias

Puntuación CVSS 0
Vector CVSS
CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:U/C:N/I:N/A:N
Debilidad (CWE)
CWE-89
Plataforma
npm
Paquete
@saltcorn/data
Publicada
10.04.2026
Actualizado
11.10.2026 10:22

Fuentes y licencias

OSV / GitHub Advisory Database - GHSA-59xv-588h-2vmm - CC BY 4.0

Historial de vulnerabilidades: @saltcorn/data

Todas las vulnerabilidades publicadas de este paquete (Paquete de npm), de la más reciente a la más antigua. Muestra si es un fallo aislado o un paquete que hay que vigilar.

Entradas en total
2
Primera → última
04.2026 04.2026
Sin corrección
0
Explotada en ataques
0

Distribución por gravedad

  • Alta 1
  • Baja 1

Divulgaciones por año

  1. 2026: 2
  1. Alta ghsa-9237-rg5p-rhfw < 1.4.4, >= 1.5.0-beta.0, < 1.5.2, >= 1.6.0-alpha.0, < 1.6.0-beta.2 1.4.4, 1.5.2, 1.6.0-beta.2
  2. @saltcorn/data vulnerable to SQL Injection via jsexprToSQL Literal Handler esta entrada
    Baja · 0.0 ghsa-59xv-588h-2vmm < 1.4.5, >= 1.5.0, < 1.5.5, >= 1.6.0-alpha.0, < 1.6.0-beta.4 1.4.5, 1.5.5, 1.6.0-beta.4

Identifica las vulnerabilidades de tu aplicación

Con la integración de DockRay y el inventario de software activado, DockRay compara las versiones notificadas de los componentes con las vulnerabilidades conocidas y avisa de las coincidencias confirmadas. La cobertura depende de la tecnología compatible y de los avisos disponibles.

Conectar tu aplicación
Newsletter DockRay

La seguridad de tus aplicaciones en tu correo

Vulnerabilidades importantes, recomendaciones concretas y consejos prácticos para tus aplicaciones. Elige tus tecnologías y sigue lo que importa para tu proyecto.

  • Un resumen diario de nuevas vulnerabilidades, también las críticas.
  • Avisos sobre actualizaciones importantes.
  • Consejos prácticos sobre seguridad y monitorización de aplicaciones.

Déjalo vacío para recibir avisos de todas las tecnologías.

Suscripción gratuita. Date de baja con un clic en cualquier correo.