From 8c6c66c91e7c855ee55bf17bf3d70508c6d674b6 Mon Sep 17 00:00:00 2001 From: Mert Can Altin Date: Tue, 6 Jan 2026 21:31:23 +0300 Subject: [PATCH 01/22] sqlite: add limits property to DatabaseSync --- doc/api/sqlite.md | 41 +++++ src/env_properties.h | 2 + src/node_sqlite.cc | 270 ++++++++++++++++++++++++++++ src/node_sqlite.h | 45 +++++ test/parallel/test-sqlite-limits.js | 161 +++++++++++++++++ 5 files changed, 519 insertions(+) create mode 100644 test/parallel/test-sqlite-limits.js diff --git a/doc/api/sqlite.md b/doc/api/sqlite.md index 186e70784b94d0..d6959cf9eec7e0 100644 --- a/doc/api/sqlite.md +++ b/doc/api/sqlite.md @@ -155,6 +155,21 @@ 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:** `false`. + * `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][] in the SQLite + documentation for details. 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. @@ -443,6 +458,31 @@ 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; +``` + +Available properties: `length`, `sqlLength`, `column`, `exprDepth`, +`compoundSelect`, `vdbeOp`, `functionArg`, `attach`, `likePatternLength`, +`variableNumber`, `triggerDepth`. + ### `database.open()`