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.
File: packages/saltcorn-data/models/expression.ts, lines 117-118
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.
When an admin creates a Formula-type table constraint with the expression:
name === "test' OR '1'='1"
The jsexprToSQL() function generates:
(name)=('test' OR '1'='1')
This is then executed as:
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.
name === "'; DROP TABLE users; --"
Generates:
(name)=(''; DROP TABLE users; --')
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).
ConstraitsFormulausers table modificationEscape single quotes in the Literal handler:
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.
{
"cwe_ids": [
"CWE-89"
],
"github_reviewed": true,
"github_reviewed_at": "2026-04-10T19:30:32Z",
"nvd_published_at": null,
"severity": "LOW"
}