fix(scripting-node): allow opt-in absolute-path filesystem reads#3981
Open
Osheun wants to merge 1 commit into
Open
fix(scripting-node): allow opt-in absolute-path filesystem reads#3981Osheun wants to merge 1 commit into
Osheun wants to merge 1 commit into
Conversation
Mongoose, mongodb and other Node libraries probe a small set of absolute system paths during driver init (`/.dockerenv`, `/proc/self/cgroup`, `/etc/os-release`, ...) to detect their runtime environment. Today these probes are blocked unconditionally by `NodePermissionCallback` because the path is not inside any VFS device, which surfaces as "Access to this API has been restricted" and crashes the resource. This change introduces an admin-opt-in allow-list: - New `fx::ScriptingFilesystemAllowAbsoluteRead(absolutePath, resource)` helper, mirroring the shape of `AllowWrite` / `WorkerAllowSpawn`. - New `add_unsafe_filesystem_absolute_read_permission <resource> <path>` console command, gated by the same `g_permissionModifyAllowed` flag as the other permission commands, so it can only be set during startup. The path must be absolute; matching is exact-or-directory- prefix (no glob, no traversal). - `NodePermissionCallback` consults the allow-list only for `kFileSystemRead`, only when no VFS device matches the path, and only after the existing `..` traversal guard. Writes are unchanged. Default behaviour is unchanged: without an explicit `add_unsafe_filesystem_absolute_read_permission` entry the sandbox behaves exactly as before. Refs: citizenfx#3978
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.
Goal of this PR
Fix #3978.
The Node.js scripting sandbox blocks every
fs.readon an absolute path that is not inside a registered VFS device. This is the correct default, but it makes the MongoDB Node driver (and Mongoose) crash at construction time, because its internalgetContainerMetadata()probes paths like/.dockerenv,/proc/self/cgroup,/etc/os-releaseto detect its runtime environment. Right now any resource usingmongodbormongoosethrowsError: Access to this API has been restrictedand dies before it can connect.How is this PR achieving the goal
Adds an admin opt-in allow-list for absolute reads, mirroring the existing
add_unsafe_worker_permission/add_unsafe_child_process_permissionpattern:fx::ScriptingFilesystemAllowAbsoluteRead(absolutePath, resource)helper incitizen-scripting-core.add_unsafe_filesystem_absolute_read_permission <resource> <absolute-path>, gated by the sameg_permissionModifyAllowedstartup-only flag as the other_unsafe_*commands. Path must be absolute, exact-or-directory-prefix match (no glob, no traversal).NodePermissionCallbackconsults the allow-list only forkFileSystemRead, only when no VFS device matches, and only after the existing..traversal guard. Writes are untouched.add_unsafe_filesystem_absolute_read_permissionentry, the sandbox blocks as before.Admins write in
server.cfg:This PR applies to the following area(s)
FXServer, ScRT: JS
Successfully tested on
Game builds: N/A (server-only change)
Platforms: Windows
Built FXServer locally and reproduced #3978 end-to-end with
mongodb@6andmongoose@8.Before:
After (with matching
add_unsafe_filesystem_absolute_read_permission):Driver gets past
getContainerMetadata()and continues normally.Checklist