no-unsafe-query
Prevent SQL injection by disallowing string concatenation or interpolated template literals in TypeORM raw queries.
CWE: CWE-89 OWASP: A03:2021 – Injection
Detects SQL injection in TypeORM raw queries. This rule is part of eslint-plugin-typeorm-security.
💼 This rule is set to error in the recommended config.
Quick Summary
| Aspect | Details |
|---|---|
| CWE Reference | CWE-89 (SQL Injection) |
| Severity | Critical (CVSS 9.8) |
| Auto-Fix | ❌ No auto-fix available |
| Category | Security |
Rule Details
Reports three shapes when they reach a raw-SQL sink:
- String concatenation —
dataSource.query('SELECT ... ' + value) - Template interpolation —
dataSource.query(`SELECT ... ${value}`) - A variable tainted by either, including via
+=, then passed to a sink
Sinks
dataSource.query() / manager.query(). Query-builder string fragments (.where("name = '" + x + "'")) are not covered yet — use :name parameters there.
❌ Incorrect
await dataSource.query(`SELECT * FROM users WHERE id = ${userId}`);
await dataSource.query('SELECT * FROM users WHERE email = ' + email);
let sql = 'SELECT * FROM products WHERE 1=1';
sql += ` AND name = '${name}'`;
await dataSource.query(sql);✅ Correct
await dataSource.query('SELECT * FROM users WHERE id = $1', [userId]);Known limitations
- Only identifier member access is matched, so
dataSource['query'](...)is a false negative. - Taint tracking is single-scope and name-based — it does not follow a query string across function boundaries.
Implementation
The detection is shared across the driver plugins via createSqlInjectionRule
in @interlace/eslint-devkit; this rule supplies TypeORM's sinks and
remediation copy. Install the plugin matching your stack and you get exactly
one finding per line.
Further Reading
Did this rule catch something? Star the repo to get new CWE coverage as we ship it — or follow the AI-code-security benchmarks behind these rules.
no-mass-assignment
Disallow writing an inbound request object straight to the database through TypeORM, which lets the caller set every column the model exposes.
require-tls
Require TLS on TypeORM DataSource connections, so queries and credentials are not sent in cleartext and the server is authenticated.