From d18cb97b5e802a70ffe57fc933e3d367193fda86 Mon Sep 17 00:00:00 2001 From: Mert Can Altin Date: Tue, 20 Jan 2026 21:23:34 +0300 Subject: [PATCH 01/14] sqlite: add limits property to DatabaseSync --- doc/api/sqlite.md | 49 +++++ src/env_properties.h | 2 + src/node_sqlite.cc | 276 ++++++++++++++++++++++++++++ src/node_sqlite.h | 68 +++++++ test/parallel/test-sqlite-limits.js | 226 +++++++++++++++++++++++ 5 files changed, 621 insertions(+) create mode 100644 test/parallel/test-sqlite-limits.js diff --git a/doc/api/sqlite.md b/doc/api/sqlite.md index bc834483c057a6..83a74d26eebd64 100644 --- a/doc/api/sqlite.md +++ b/doc/api/sqlite.md @@ -158,6 +158,23 @@ changes: language features that allow ordinary SQL to deliberately corrupt the database file are disabled. The defensive flag can also be set using `enableDefensive()`. **Default:** `true`. + * `limits` {Object} Configuration for various SQLite limits. These limits + can be used to prevent excessive resource consumption when handling + potentially malicious input. See [Run-Time Limits][] and [Limit Constants][] + in the SQLite documentation for details. Default values are determined by + SQLite's compile-time defaults and may vary depending on how SQLite was + built. The following properties are supported: + * `length` {number} Maximum length of a string or BLOB. + * `sqlLength` {number} Maximum length of an SQL statement. + * `column` {number} Maximum number of columns. + * `exprDepth` {number} Maximum depth of expression tree. + * `compoundSelect` {number} Maximum number of terms in compound SELECT. + * `vdbeOp` {number} Maximum number of VDBE instructions. + * `functionArg` {number} Maximum number of function arguments. + * `attach` {number} Maximum number of attached databases. + * `likePatternLength` {number} Maximum length of LIKE pattern. + * `variableNumber` {number} Maximum number of SQL variables. + * `triggerDepth` {number} Maximum trigger recursion depth. Constructs a new `DatabaseSync` instance. @@ -446,6 +463,36 @@ added: * Type: {boolean} Whether the database is currently within a transaction. This method is a wrapper around [`sqlite3_get_autocommit()`][]. +### `database.limits` + + + +* Type: {Object} + +An object for getting and setting SQLite database limits at runtime. +Each property corresponds to an SQLite limit and can be read or written. + +```js +const db = new DatabaseSync(':memory:'); + +// Read current limit +console.log(db.limits.length); + +// Set a new limit +db.limits.sqlLength = 100000; + +// Reset a limit to its compile-time maximum +db.limits.sqlLength = Infinity; +``` + +Available properties: `length`, `sqlLength`, `column`, `exprDepth`, +`compoundSelect`, `vdbeOp`, `functionArg`, `attach`, `likePatternLength`, +`variableNumber`, `triggerDepth`. + +Setting a property to `Infinity` resets the limit to its compile-time maximum value. + ### `database.open()`