Repository navigation
fix(ext/node_sqlite): keep attach limit capped under scoped permissions - #35232
Merged
Merged
Conversation
When a node:sqlite process lacks full permissions for the database path, ATTACH DATABASE is disabled by capping SQLITE_LIMIT_ATTACHED at 0, because attached databases can reach files outside the database path. The limits support let that cap be raised again: the constructor limits.attach option was applied after the cap, and the db.limits.attach setter had no guard. apply_initial_limits now skips the attach limit when the cap is in force, and the attach setter refuses to raise it above 0. The allowed (--allow-all) path is unchanged. Adds a spec test covering both surfaces under scoped read/write with explicit deny rules.
The spec test created allowed/ and denied/ directories inside the test source directory, leaving the git working tree dirty and failing the post-test cleanliness check in CI. Run it in a copied temp dir so the fixtures setup.js writes never touch the source tree.
Member
Author
|
Traced the bypass and the closure holds — capping Test coverage
Behavior / consistency
Tiny
|
…dd positive test Make the constructor limits.attach option reject raising the attach cap under scoped permissions with ERR_ACCESS_DENIED, matching the db.limits.attach setter, instead of silently dropping the option. Throw the setter error as a plain Error (not a TypeError) since an access-denied condition is not a TypeError. Add an --allow-all regression test verifying that with full permissions both the option and the setter raise the limit and ATTACH then succeeds, and assert the scoped-permission rejections carry ERR_ACCESS_DENIED.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
node:sqlitedisablesATTACH DATABASEwhen a process does not have fullpermissions for the database path, because an attached database can reach file
paths outside the original database path. It does this by capping
SQLITE_LIMIT_ATTACHEDat 0 for those connections.The
DatabaseSynclimits support could raise that cap back up, which undoes theprotection.
apply_initial_limitsran after the cap was set, so anew DatabaseSync(path, { limits: { attach: 1 } })option re-enabled attach,and the
db.limits.attachsetter wrote the limit directly with no guard. Inboth cases a process with only scoped read/write access to one directory could
then
ATTACH DATABASEa file in a directory it was explicitly denied.This treats the
SQLITE_LIMIT_ATTACHED = 0cap as authoritative for thoseconnections rather than user-tunable. Both surfaces now reject raising the cap
the same way: the
limits.attachconstructor option and thedb.limits.attachsetter throw
ERR_ACCESS_DENIEDwhen asked to raise the limit above 0 while thecap is in force (a value of 0, keeping it disabled, is still accepted). The
setter error is a plain
Error, not aTypeError, since an access-deniedcondition is not a type error. When the process does have full permissions
nothing changes: the constructor option and the setter raise the limit as
before.
Added a spec test that runs with scoped
--allow-read/--allow-writeon onedirectory and explicit
--deny-read/--deny-writeon another, and checks thata direct read, a direct open, a default
ATTACH, thelimits.attachconstructor option, and the
db.limits.attachsetter are all unable to reachthe denied database, with the last two rejected by
ERR_ACCESS_DENIED. Acompanion
--allow-allstep is the positive regression guard: it verifies thatwith full permissions both the option and the setter raise the limit and
ATTACHthen succeeds, so a future change that over-tightens the cap would failCI.