Skip to content

sqlite: enforce permission model on file access - #62957

Open
mcollina wants to merge 7 commits into
nodejs:mainfrom
mcollina:sqlite-permission-checks
Open

mcollina wants to merge 7 commits into
nodejs:mainfrom
mcollina:sqlite-permission-checks

Conversation

@mcollina

@mcollina mcollina commented Apr 25, 2026 •

Copy link
Copy Markdown
Member

Enforce the permission model for node:sqlite file access.

  • open() checks --allow-fs-read for read-only databases, and read plus write for read-write ones. In-memory databases are exempt.
  • When permissions are enabled, connections use a VFS shim that checks every file SQLite opens: ATTACH targets, backup destinations, and journal, WAL and SHM files. A database grant also covers its own sidecar files.
  • URI vfs= parameters are rejected, so a connection cannot switch to an unchecked VFS.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/security-wg
  • @nodejs/sqlite

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. sqlite Issues and PRs related to the SQLite subsystem. labels Apr 25, 2026
@codecov

codecov Bot commented Apr 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 65.64551% with 157 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.67%. Comparing base (55da353) to head (5a9c7a5).
⚠️ Report is 222 commits behind head on main.

Files with missing lines Patch % Lines
src/node_sqlite_vfs.cc 63.02% 103 Missing and 39 partials ⚠️
src/node_sqlite.cc 78.26% 8 Missing and 7 partials ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main   #62957    +/-   ##
========================================
  Coverage   90.66%   90.67%            
========================================
  Files         799      803     +4     
  Lines      280245   281168   +923     
  Branches    54121    54263   +142     
========================================
+ Hits       254097   254942   +845     
- Misses      16277    16366    +89     
+ Partials     9871     9860    -11     
Files with missing lines Coverage Δ
src/node_sqlite.h 87.93% <100.00%> (+0.21%) ⬆️
src/node_sqlite_vfs.h 100.00% <100.00%> (ø)
src/node_sqlite.cc 82.71% <78.26%> (-0.04%) ⬇️
src/node_sqlite_vfs.cc 63.02% <63.02%> (ø)

... and 113 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mcollina
mcollina force-pushed the sqlite-permission-checks branch from 8ffad93 to 877530d Compare April 25, 2026 19:10

@RafaelGSS RafaelGSS left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as it doesn't open precedence for reports targeting SQLite on permission model, I'm +1.

@louwers louwers left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think this needs to take into account https://sqlite.org/uri.html

  • A database can be opened read-only with mode=ro or immutable=1.
  • Another way to create an in-memory database is with mode=memory.

Doing more string processing on the database path sounds a bit hacky though.

Edit: looks like we have not enabled SQLITE_USE_URI=1, but it would be good to leave a comment here that this needs to be updated when we do at the very least.

As long as it doesn't open precedence for reports targeting SQLite on permission model, I'm +1.

Passing a custom VFS to SQLite that can really prevent reads/writes might be a more comprehensive solution worth considering...

@mcollina

Copy link
Copy Markdown
Member Author

Passing a custom VFS to SQLite that can really prevent reads/writes might be a more comprehensive solution worth considering...

https://sqlite.org/vfs.html sounds really cool! I will take a look.

@mcollina
mcollina marked this pull request as draft April 30, 2026 07:44
@mcollina
mcollina marked this pull request as ready for review July 13, 2026 13:47
@mcollina
mcollina force-pushed the sqlite-permission-checks branch from 2bef788 to b1cfecf Compare July 13, 2026 15:48
@trivikr

trivikr commented Aug 30, 2026

Copy link
Copy Markdown
Member

@mcollina This needs a rebase, and the first commit needs to be signed.

@araujogui
araujogui force-pushed the sqlite-permission-checks branch from b1cfecf to 191231b Compare October 22, 2026 21:20
@araujogui araujogui changed the title sqlite: add permission model checks to DatabaseSync sqlite: enforce permission model on file access Oct 22, 2026
@araujogui
araujogui force-pushed the sqlite-permission-checks branch 2 times, most recently from e630e6b to 24a8650 Compare October 24, 2026 17:38
@araujogui

Copy link
Copy Markdown
Member

@nodejs/sqlite I rebased branch and fixed some edge cases, could you review?

@trivikr
trivikr requested a review from RafaelGSS October 25, 2026 07:01
@trivikr

trivikr commented Oct 25, 2026

Copy link
Copy Markdown
Member

@araujogui Can you rebase to edit the first commit message and body, as that will land on review.

@araujogui
araujogui force-pushed the sqlite-permission-checks branch from 24a8650 to a9c53ba Compare October 26, 2026 14:17
mcollina and others added 5 commits November 15, 2026 15:22
Database opened database files without consulting the permission
model, so code running with --permission could read and write any
database regardless of --allow-fs-read and --allow-fs-write.

Check read access, and write access unless the database is read-only,
before opening a file-backed database. In-memory databases are exempt.
SQLite also opens journal, WAL and temporary files, and ATTACH and
backup() open further databases, so route every connection through a
VFS shim that checks each path SQLite opens, deletes or probes.

Reject URI filenames that select a VFS, since that would bypass the
shim, and deny ATTACH when SQLite does not pass the filename to the
authorizer.

Refs: https://hackerone.com/reports/3686625
Co-authored-by: Guilherme Araújo <arauujogui@gmail.com>
Assisted-by: Claude Code
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
Signed-off-by: Matteo Collina <matteo.collina@gmail.com>
Signed-off-by: Matteo Collina <matteo.collina@gmail.com>
Deny ATTACH under the permission model when SQLite does not pass the
filename to the authorizer. SQLite only does so for string literals,
so a bound or computed filename could select a URI VFS and bypass the
permission VFS.

Resolve VFS paths lexically, as the permission model does, instead of
following symbolic links, and match SQLite's exact super-journal name
format.

Share one permission VFS per Environment, release it when open()
fails, skip the authorizer guards when no JavaScript callback is set,
check each path once, and reuse FSPermission::is_granted() for
side-effect-free checks.

Assisted-by: Claude Code
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
Assisted-by: Claude Code
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
@araujogui
araujogui force-pushed the sqlite-permission-checks branch from 8da255e to 5ca8342 Compare November 15, 2026 18:25
A URI could select another VFS or access mode, bypassing the
permission VFS. Reject URLs and "file:" paths until URIs are supported.

Drop the URI parsing and ATTACH authorizer check this replaces, and
reuse Permission::is_granted_quiet() in the VFS.

Assisted-by: Claude Code
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
@araujogui

Copy link
Copy Markdown
Member

@nodejs/sqlite @nodejs/security-wg I'm taking care of this PR. Could I get a round of reviews?

I dropped support for URI filenames when permissions are enabled. This significantly reduces needed number of workarounds and attack surface, making it easier and safer to land the first iteration. We can add URI filename support in a follow-up ofc

Backup and ATTACH denials surfaced as generic SQLite errors and were
invisible to --permission-audit. Throw ERR_ACCESS_DENIED and publish
them to the permission diagnostics channel instead.

Assisted-by: Claude Code
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
@araujogui
araujogui force-pushed the sqlite-permission-checks branch from 3258fd5 to 5a9c7a5 Compare November 18, 2026 19:37
@trivikr trivikr added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 20, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 20, 2026
@mcollina mcollina added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 20, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 20, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@araujogui araujogui added the resume-ci Add this label to resume the latest eligible Jenkins CI run on a PR with an approving review. label Nov 22, 2026
@github-actions github-actions Bot removed the resume-ci Add this label to resume the latest eligible Jenkins CI run on a PR with an approving review. label Nov 22, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@mcollina mcollina added the commit-queue PRs queued for automated landing through the Commit Queue. label Nov 23, 2026
@nodejs-github-bot nodejs-github-bot added commit-queue-failed PRs whose Commit Queue landing failed and need manual intervention before retrying. and removed commit-queue PRs queued for automated landing through the Commit Queue. labels Nov 23, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Commit Queue failed

This pull request has multiple commits, but no landing policy was selected.

Add commit-queue-squash PRs the Commit Queue should land as one squashed commit. to land it as one commit, or commit-queue-rebase PRs the Commit Queue should land as multiple self-contained commits. to land the commits separately.

The pull request was removed from the Commit Queue and labeled commit-queue-failed PRs whose Commit Queue landing failed and need manual intervention before retrying. . After resolving the failure, remove that label and add commit-queue PRs queued for automated landing through the Commit Queue. to retry.

Full Commit Queue output
�[36m⠋�[39m Loading data for nodejs/node/pull/62957
�[36m⠋�[39m Loading data for nodejs/node/pull/62957
�[36m⠋�[39m Getting collaborator contacts from README of nodejs/node
�[36m⠋�[39m Getting PR from nodejs/node/pull/62957
�[36m⠋�[39m Getting reviews from nodejs/node/pull/62957
�[36m⠋�[39m Getting comments from nodejs/node/pull/62957
�[36m⠋�[39m Getting commits from nodejs/node/pull/62957
✔  Done loading data for nodejs/node/pull/62957
----------------------------------- PR info ------------------------------------
Title      sqlite: enforce permission model on file access (#62957)
Author     Matteo Collina <matteo.collina@gmail.com> (@mcollina)
Branch     mcollina:sqlite-permission-checks -> nodejs:main
Labels     c++, needs-ci, commit-queue, sqlite
Commits    7
 - sqlite: enforce permission model in Database
 - sqlite: enforce permissions through a VFS shim
 - sqlite: fix permission VFS edge cases
 - fixup! sqlite: fix permission VFS edge cases
 - fixup! sqlite: fix permission VFS edge cases
 - sqlite: disable URI filenames under permission
 - sqlite: report permission VFS denials
Committers 1
 - Guilherme Araújo <arauujogui@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/62957
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/62957
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
--------------------------------------------------------------------------------
   ℹ  This PR was created on Sat, 25 Apr 2026 17:35:37 GMT
   ✔  Approvals: 2
   ✔  - Rafael Gonzaga (@RafaelGSS) (TSC): https://github.com/nodejs/node/pull/62957#pullrequestreview-4177154770
   ✔  - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/62957#pullrequestreview-5964251803
   ✔  Last GitHub CI successful
   ℹ  Last Full PR CI on 2026-11-22T16:15:06Z: https://ci.nodejs.org/job/node-test-pull-request/79405/
�[36m⠙�[39m Querying data for job/node-test-pull-request/79405/
�[36m⠙�[39m Querying data for job/node-test-pull-request/79405/
�[36m⠙�[39m Querying API for job/node-test-pull-request/79405/
   ✔  Last Jenkins CI successful
--------------------------------------------------------------------------------
�[36m⠹�[39m Querying API for job/node-test-pull-request/79405/
   ✔  No git cherry-pick in progress
   ✔  No git am in progress
   ✔  No git rebase in progress
--------------------------------------------------------------------------------
�[36m⠹�[39m Querying API for job/node-test-pull-request/79405/
�[36m⠹�[39m Bringing origin/main up to date...
From https://github.com/nodejs/node
 * branch                  main       -> FETCH_HEAD
   45d1554464..1ef44440a9  main       -> origin/main
✔  origin/main is now up-to-date
main is out of sync with origin/main. Mismatched commits:
 - e1e867c152 src: skip the async id stack when nobody sees it
 - 1ef44440a9 src: skip the async id stack when nobody sees it
--------------------------------------------------------------------------------
HEAD is now at 1ef44440a9 src: skip the async id stack when nobody sees it
   ✔  Reset to origin/main
�[36m⠸�[39m Downloading patch for 62957
�[36m⠸�[39m Downloading patch for 62957
From https://github.com/nodejs/node
 * branch                  refs/pull/62957/merge -> FETCH_HEAD
✔  Fetched commits as a16ff8bb447f..5a9c7a5749a6
--------------------------------------------------------------------------------
Auto-merging src/node_sqlite.cc
[main 6ec0e203e1] sqlite: enforce permission model in Database
 Author: Matteo Collina <hello@matteocollina.com>
 Date: Thu Apr 23 20:07:23 2026 +0000
 3 files changed, 159 insertions(+)
 create mode 100644 test/fixtures/permission/sqlite.db
 create mode 100644 test/parallel/test-permission-sqlite.js
Auto-merging node.gyp
Auto-merging src/node_sqlite.cc
Auto-merging src/node_sqlite.h
Auto-merging src/permission/fs_permission.cc
[main 14e50f147f] sqlite: enforce permissions through a VFS shim
 Author: Matteo Collina <matteo.collina@gmail.com>
 Date: Sun Jul 12 14:48:19 2026 +0000
 11 files changed, 1206 insertions(+), 108 deletions(-)
 create mode 100644 src/node_sqlite_vfs.cc
 create mode 100644 src/node_sqlite_vfs.h
Auto-merging src/node_sqlite.cc
[main 06fbbac6ea] sqlite: fix permission VFS edge cases
 Author: Matteo Collina <matteo.collina@gmail.com>
 Date: Sun Jul 12 17:44:09 2026 +0000
 4 files changed, 251 insertions(+), 33 deletions(-)
Auto-merging src/node_sqlite.cc
Auto-merging src/node_sqlite.h
Auto-merging src/permission/fs_permission.cc
[main 57f7f0c701] fixup! sqlite: fix permission VFS edge cases
 Author: Guilherme Araújo <arauujogui@gmail.com>
 Date: Fri Oct 23 14:58:12 2026 -0300
 6 files changed, 185 insertions(+), 171 deletions(-)
[main 631cc7b93f] fixup! sqlite: fix permission VFS edge cases
 Author: Guilherme Araújo <arauujogui@gmail.com>
 Date: Sat Oct 24 14:36:33 2026 -0300
 2 files changed, 3 insertions(+), 3 deletions(-)
Auto-merging doc/api/permissions.md
Auto-merging doc/api/sqlite.md
Auto-merging src/node_sqlite.cc
Auto-merging src/permission/fs_permission.cc
[main a0ba56a531] sqlite: disable URI filenames under permission
 Author: Guilherme Araújo <arauujogui@gmail.com>
 Date: Mon Nov 16 11:39:23 2026 -0300
 11 files changed, 204 insertions(+), 660 deletions(-)
Auto-merging src/node_sqlite.cc
Auto-merging src/node_sqlite.h
[main 39d20bbc80] sqlite: report permission VFS denials
 Author: Guilherme Araújo <arauujogui@gmail.com>
 Date: Mon Nov 16 11:48:55 2026 -0300
 5 files changed, 134 insertions(+), 19 deletions(-)
   ✔  Patches applied
There are 7 commits in the PR. Attempting autorebase.
(node:917) [DEP0190] DeprecationWarning: Passing args to a child process with shell option true can lead to security vulnerabilities, as the arguments are not escaped, only concatenated.
(Use `node --trace-deprecation ...` to show where the warning was created)
Rebasing (2/12)
Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
sqlite: enforce permission model in Database

Database opened database files without consulting the permission
model, so code running with --permission could read and write any
database regardless of --allow-fs-read and --allow-fs-write.

Check read access, and write access unless the database is read-only,
before opening a file-backed database. In-memory databases are exempt.
SQLite also opens journal, WAL and temporary files, and ATTACH and
backup() open further databases, so route every connection through a
VFS shim that checks each path SQLite opens, deletes or probes.

Reject URI filenames that select a VFS, since that would bypass the
shim, and deny ATTACH when SQLite does not pass the filename to the
authorizer.

Refs: https://hackerone.com/reports/3686625
Co-authored-by: Guilherme Araújo <arauujogui@gmail.com>
Assisted-by: Claude Code
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/62957
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
--------------------------------------------------------------------------------
[detached HEAD 5772d5a817] sqlite: enforce permission model in Database
 Author: Matteo Collina <hello@matteocollina.com>
 Date: Thu Apr 23 20:07:23 2026 +0000
 3 files changed, 159 insertions(+)
 create mode 100644 test/fixtures/permission/sqlite.db
 create mode 100644 test/parallel/test-permission-sqlite.js
Rebasing (3/12)
Rebasing (4/12)
Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
sqlite: enforce permissions through a VFS shim

Signed-off-by: Matteo Collina <matteo.collina@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/62957
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
--------------------------------------------------------------------------------
[detached HEAD 1738a62b7d] sqlite: enforce permissions through a VFS shim
 Author: Matteo Collina <matteo.collina@gmail.com>
 Date: Sun Jul 12 14:48:19 2026 +0000
 11 files changed, 1206 insertions(+), 108 deletions(-)
 create mode 100644 src/node_sqlite_vfs.cc
 create mode 100644 src/node_sqlite_vfs.h
Rebasing (5/12)
Rebasing (6/12)
Rebasing (7/12)
Rebasing (8/12)
Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
sqlite: fix permission VFS edge cases

Signed-off-by: Matteo Collina <matteo.collina@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/62957
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
--------------------------------------------------------------------------------
[detached HEAD 822a46d154] sqlite: fix permission VFS edge cases
 Author: Matteo Collina <matteo.collina@gmail.com>
 Date: Sun Jul 12 17:44:09 2026 +0000
 6 files changed, 425 insertions(+), 193 deletions(-)
Rebasing (9/12)
Rebasing (10/12)
Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
sqlite: disable URI filenames under permission

A URI could select another VFS or access mode, bypassing the
permission VFS. Reject URLs and "file:" paths until URIs are supported.

Drop the URI parsing and ATTACH authorizer check this replaces, and
reuse Permission::is_granted_quiet() in the VFS.

Assisted-by: Claude Code
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/62957
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
--------------------------------------------------------------------------------
[detached HEAD c0aca54ec4] sqlite: disable URI filenames under permission
 Author: Guilherme Araújo <arauujogui@gmail.com>
 Date: Mon Nov 16 11:39:23 2026 -0300
 11 files changed, 204 insertions(+), 660 deletions(-)
Rebasing (11/12)
Rebasing (12/12)
Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
sqlite: report permission VFS denials

Backup and ATTACH denials surfaced as generic SQLite errors and were
invisible to --permission-audit. Throw ERR_ACCESS_DENIED and publish
them to the permission diagnostics channel instead.

Assisted-by: Claude Code
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/62957
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
--------------------------------------------------------------------------------
[detached HEAD 2646a1f101] sqlite: report permission VFS denials
 Author: Guilherme Araújo <arauujogui@gmail.com>
 Date: Mon Nov 16 11:48:55 2026 -0300
 5 files changed, 134 insertions(+), 19 deletions(-)
Successfully rebased and updated refs/heads/main.
--------------------------------------------------------------------------------
   ℹ  Add `commit-queue-squash` label to land the PR as one commit, or `commit-queue-rebase` to land as separate commits.

View workflow run

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

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. commit-queue-failed PRs whose Commit Queue landing failed and need manual intervention before retrying. needs-ci PRs that need a full CI run. sqlite Issues and PRs related to the SQLite subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants