Skip to content

sqlite: enforce permission model on file access - #62957

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

mcollina wants to merge 4 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 63.20908% with 227 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.51%. Comparing base (a7e06d9) to head (cd118bd).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
src/node_sqlite_vfs.cc 60.83% 146 Missing and 60 partials ⚠️
src/node_sqlite.cc 84.12% 3 Missing and 7 partials ⚠️
src/permission/fs_permission.cc 60.00% 3 Missing and 3 partials ⚠️
src/permission/permission.cc 57.14% 0 Missing and 3 partials ⚠️
src/permission/permission_base.h 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #62957      +/-   ##
==========================================
- Coverage   90.58%   90.51%   -0.07%     
==========================================
  Files         797      799       +2     
  Lines      278480   279089     +609     
  Branches    53532    53671     +139     
==========================================
+ Hits       252268   252629     +361     
- Misses      16541    16727     +186     
- Partials     9671     9733      +62     
Files with missing lines Coverage Δ
src/node_sqlite.h 87.50% <100.00%> (+0.22%) ⬆️
src/node_sqlite_vfs.h 100.00% <100.00%> (ø)
src/permission/fs_permission.h 92.55% <ø> (ø)
src/permission/permission.h 100.00% <ø> (ø)
src/permission/permission_base.h 33.33% <0.00%> (-66.67%) ⬇️
src/permission/permission.cc 74.50% <57.14%> (-0.50%) ⬇️
src/permission/fs_permission.cc 75.11% <60.00%> (-1.08%) ⬇️
src/node_sqlite.cc 81.92% <84.12%> (-0.01%) ⬇️
src/node_sqlite_vfs.cc 60.83% <60.83%> (ø)

... and 26 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.

mcollina and others added 3 commits October 22, 2026 17:54
Add permission model enforcement to DatabaseSync::Open().
File-backed databases now check kFileSystemRead (readOnly) or
kFileSystemWrite (read-write) before calling sqlite3_open_v2.
In-memory databases (:memory:) are exempt.

Refs: https://hackerone.com/reports/3686625
Signed-off-by: Matteo Collina <matteo.collina@gmail.com>
Signed-off-by: Matteo Collina <matteo.collina@gmail.com>
@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
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
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++. 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.

6 participants