From b72c9f066ea4ad2af2ecdd5316e9cb2a02932d1f Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Mon, 30 Nov 2026 12:56:04 -0300 Subject: [PATCH 1/2] sqlite: allow enabling extensions in permission audit mode Signed-off-by: RafaelGSS --- doc/api/permissions.md | 4 ++- src/node_sqlite.cc | 3 ++- .../test-permission-sqlite-load-extension.js | 25 +++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/doc/api/permissions.md b/doc/api/permissions.md index 45e2c7679ae5..5f533b320a0d 100644 --- a/doc/api/permissions.md +++ b/doc/api/permissions.md @@ -516,7 +516,9 @@ There are constraints you need to know before using this system: chosen by the operator, gaps like this are treated as regular bugs rather than vulnerabilities. Please report them through the regular issue tracker. * Run-Time Loadable Extensions cannot be loaded when the Permission Model is - enabled, affecting the sqlite module. + enabled, affecting the sqlite module. In [audit mode](#audit-mode) they can + be enabled and loaded, and `database.loadExtension()` publishes a message + when the extension path is not covered by `--allow-fs-read`. * SQLite [URI filenames][] are disabled when the Permission Model is enabled. The `node:sqlite` module rejects {URL} objects and paths starting with `file:`, and `ATTACH DATABASE` treats such names as plain file paths. diff --git a/src/node_sqlite.cc b/src/node_sqlite.cc index 001718d853e0..01da8ba0e036 100644 --- a/src/node_sqlite.cc +++ b/src/node_sqlite.cc @@ -1760,7 +1760,8 @@ bool Database::Open() { } if (enable_load_extension_) { - if (env()->permission()->enabled()) [[unlikely]] { + if (env()->permission()->enabled() && + !env()->permission()->warning_only()) [[unlikely]] { THROW_ERR_LOAD_SQLITE_EXTENSION(env(), "Cannot load SQLite extensions when the " "permission model is enabled."); diff --git a/test/parallel/test-permission-sqlite-load-extension.js b/test/parallel/test-permission-sqlite-load-extension.js index e87849ffb2de..48ffcd6a8466 100644 --- a/test/parallel/test-permission-sqlite-load-extension.js +++ b/test/parallel/test-permission-sqlite-load-extension.js @@ -15,3 +15,28 @@ common.spawnPromisified( assert.match(stderr, /code: 'ERR_LOAD_SQLITE_EXTENSION'/); assert.strictEqual(code, 1); })); + +// In audit mode extensions can be enabled, and loading reaches SQLite after +// the file system read is published to the diagnostics channel. +const auditCode = `const dc = require('node:diagnostics_channel'); +const sqlite = require('node:sqlite'); +const msgs = []; +dc.subscribe('node:permission-model:fs', (m) => msgs.push(m.permission)); +const db = new sqlite.Database(':memory:', { allowExtension: true }); +try { + db.loadExtension('nonexistent'); +} catch (e) { + console.log('CODE ' + e.code); + console.log('MESSAGE ' + e.message); +} +console.log('AUDIT ' + JSON.stringify(msgs));`.replace(/\n/g, ' '); + +common.spawnPromisified( + process.execPath, + ['--permission-audit', '--eval', auditCode], +).then(common.mustCall(({ code, stdout, stderr }) => { + assert.strictEqual(code, 0, stderr); + assert.match(stdout, /CODE ERR_LOAD_SQLITE_EXTENSION/); + assert.doesNotMatch(stdout, /permission model is enabled/); + assert.match(stdout, /AUDIT \["FileSystemRead"\]/); +})); From 537cc0b1adbf9265aba33492fefae6a0dcb7a596 Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Wed, 2 Dec 2026 14:40:54 -0300 Subject: [PATCH 2/2] fixup! sqlite: allow enabling extensions in permission audit mode --- src/node_sqlite.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/node_sqlite.cc b/src/node_sqlite.cc index 01da8ba0e036..375e7ad8701f 100644 --- a/src/node_sqlite.cc +++ b/src/node_sqlite.cc @@ -1760,8 +1760,8 @@ bool Database::Open() { } if (enable_load_extension_) { - if (env()->permission()->enabled() && - !env()->permission()->warning_only()) [[unlikely]] { + if (env()->permission()->enabled() && !env()->permission()->warning_only()) + [[unlikely]] { THROW_ERR_LOAD_SQLITE_EXTENSION(env(), "Cannot load SQLite extensions when the " "permission model is enabled.");