Skip to content

feat: sandboxing - #7758

Open
aecsocket wants to merge 216 commits into
mainfrom
boris/sandbox
Open

aecsocket wants to merge 216 commits into
mainfrom
boris/sandbox

Conversation

@aecsocket

@aecsocket aecsocket commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor
  • Re-enable toggling network in settings UI when possible

@github-actions

Copy link
Copy Markdown
Contributor

Pull request changelog

App

Added

Changed

Deprecated

Removed

Fixed

Security

Website

Added

Changed

Deprecated

Removed

Fixed

Security

Hosting

Added

Changed

Deprecated

Removed

Fixed

Security

Moulberry and others added 18 commits November 25, 2026 20:41
# Conflicts:
#	Cargo.lock
#	Cargo.toml
#	apps/app-frontend/src/locales/de-CH/index.json
#	apps/app-frontend/src/locales/de-DE/index.json
#	apps/app-frontend/src/locales/it-IT/index.json
#	apps/app-frontend/src/locales/ko-KR/index.json
#	apps/app-frontend/src/locales/pt-BR/index.json
#	apps/app-frontend/src/locales/ru-RU/index.json
#	apps/app-frontend/src/locales/sv-SE/index.json
#	apps/app-frontend/src/locales/uk-UA/index.json
#	apps/app-frontend/src/locales/zh-TW/index.json
#	packages/app-lib/Cargo.toml
#	packages/app-lib/src/launcher/args.rs
#	packages/app-lib/src/launcher/mod.rs
#	packages/app-lib/src/state/process.rs
@IMB11
IMB11 marked this pull request as ready for review November 27, 2026 13:09
@mergify

mergify Bot commented Nov 27, 2026

Copy link
Copy Markdown

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request once it meets the queue conditions

@IMB11

IMB11 commented Nov 27, 2026

Copy link
Copy Markdown
Member

@greptileai review

"rejecting dropped-file access because the file is not a readable ZIP archive"
);
return Err(RequestStatus::InternalServerError);
};

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.

P2 security Mods can probe which files exist

Mods can check which host files exist. handle_request_request_access returns InternalServerError (500) when the probed path exists but is not a readable ZIP, returns Unauthorized (401) when the path does not exist, and only sets the disallow_request_access kill switch on the nonexistent case. The handler's own comments say it exists to stop a malicious program from enumerating files, but the distinct status codes leak the answer anyway: a mod inside the sandbox can probe an arbitrary host path outside its grants and tell whether the file exists. For example, a mod requests access to ~/secret.dat; a 500 means the file exists, a 401 means it does not. "Exists" answers never trigger the kill switch, so the mod can enumerate any number of existing files across a session. Return the same error status (and the same logging) for every rejection reason, and trigger the kill switch on any failed probe, not just missing paths.

}
}
}
}

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.

P2 security User-picked executables become writable

User-picked executables get write access. When a mod triggers a file dialog, handle_request_open_file_dialog exposes every path the user picks as ReadWrite, with no downgrade for executable or script extensions. The drag-and-drop path does the opposite: get_drop_permission in drag_intercept.rs forces directories and anything with an executable extension to ReadOnly, explicitly "to prevent the sandboxed process from modifying anything which could later be executed outside of the sandbox". The dialog's title, accept label, filters, and default location are all mod-controlled, so a mod can social-engineer the user into selecting an existing .bat, .ps1, or .jar (e.g. a fake "export your log" save dialog with a *.bat filter). The sandbox then gets write access to that file, the mod overwrites it, and the code runs outside the sandbox the next time the user opens it. Apply the same executable-extension downgrade to paths picked through the dialog.

@greptile-apps

greptile-apps Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

security Security Review

This PR does not appear safe to merge because turning off "Access network" in the new sandbox settings has no effect - a sandboxed mod always keeps full internet access, so it can still exfiltrate data and receive remote commands.

What was checked
  • The localhost sandbox API on port 28881 requires a per-child bearer secret for /sandboxapi/* routes; the open /sandboxauth/* routes only proxy to fixed Mojang hosts.
  • The real Minecraft session token never reaches the sandboxed game - the game gets a dummy token and the launcher swaps in the real one only when forwarding to Mojang.
  • Sandbox path rules are enforced consistently for drag-dropped files, risky paths, and the launcher log (opened without following symlinks the game could plant).
  • All 71 SCA hits in Cargo.lock are pre-existing versions; this PR only adds new crates (fuser, libseccomp, ashpd, async_zip, etc.) with no advisories against them.
  • The bubblewrap, AppContainer, and Seatbelt backends honor the sandbox's allow_network flag, but the Minecraft command never sets it from user settings.

Findings

  • P1 Network toggle does nothing ▶
  • P2 Mods can probe which files exist ▶
  • P2 User-picked executables become writable ▶

@greptile-apps

greptile-apps Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 0/5 · The PR needs fixes before merging, especially for the sandbox install action and game-launch regressions.RetriggerView in GreptileConfidence Score: 0/5 Tier: plus

[High impact] The PR changes how Minecraft processes run and how several app settings are edited.

The PR needs fixes before merging, especially for the sandbox install action and game-launch regressions.

Summary

Adds a cross-platform Minecraft sandbox, a Java agent, sandbox settings, and installation prompts. It also switches several settings pages to automatic saving.

  • Minecraft launches can run inside a platform-specific sandbox.
  • Users can choose when Minecraft instances use the sandbox.
  • Install warnings can offer to sandbox unknown files.
  • Settings screens save changes directly or in smaller edits.
  • The game-settings editor saves changes as users make them.

Review used source inspection only; no builds or runtime checks were run.

Acknowledgments: aecsocket deferred re-enabling the network toggle. aecsocket’s added Windows grant documentation explicitly keeps a union of shared-container permissions to avoid breaking existing games.

Reviews (1) · Last reviewed commit: "refactor: remove unsaved changes popup i..." · Reviewed by Greptile

Comment on lines +194 to +198
JVM_ARGUMENTS.contains(&argument_name)
|| LAUNCHER_MANAGED_JVM_ARGUMENTS.contains(&argument_name)
|| argument.contains("${classpath}")
|| argument.contains("${natives_directory}")
|| argument.contains("${library_directory}")

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.

P1 Required loader arguments disappear

Filtering every argument containing ${library_directory} or ${classpath} removes loader-specific arguments too. Forge and NeoForge use these placeholders for their module path and properties such as legacyClassPath. Removing a module-path value leaves its preceding option in place, so Java reads the next option as its value and the game fails to start—even with sandboxing off.

Substitute these placeholders and remove only the options the new command actually rebuilds.

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/app-lib/src/launcher/args.rs
Line: 194-198

Comment:
**Required loader arguments disappear**

Filtering every argument containing `${library_directory}` or `${classpath}` removes loader-specific arguments too. Forge and NeoForge use these placeholders for their module path and properties such as `legacyClassPath`. Removing a module-path value leaves its preceding option in place, so Java reads the next option as its value and the game fails to start—even with sandboxing off.

Substitute these placeholders and remove only the options the new command actually rebuilds.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Comment on lines +185 to +187
#[inline]
pub fn instance_data_dir(&self) -> PathBuf {
self.config_dir.join(INSTANCE_DATA_FOLDER_NAME)

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.

P1 Persistent game data stays behind

The new instance-data folder is missing from MOVED_APP_DIRECTORIES. After the user moves the app directory, instance_data_dir() points under the new root, but the move copies only its existing six folders. Minecraft gets a fresh home and cannot find the mod data saved in the old location.

Include this folder in the copy and path-mapping work.

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/app-lib/src/state/dirs.rs
Line: 185-187

Comment:
**Persistent game data stays behind**

The new `instance-data` folder is missing from `MOVED_APP_DIRECTORIES`. After the user moves the app directory, `instance_data_dir()` points under the new root, but the move copies only its existing six folders. Minecraft gets a fresh home and cannot find the mod data saved in the old location.

Include this folder in the copy and path-mapping work.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Comment on lines +33 to +36
let rt = tokio::runtime::Builder::new_current_thread()
.build()
.context("creating tokio runtime")?;
let env = rt.block_on(SandboxEnv::new())?;

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.

P1 C sandbox startup aborts

modrinth_sandbox_create_env builds a Tokio runtime without enabling its I/O or time drivers. In Flatpak, SandboxEnv::new() immediately connects to the session bus through Tokio, so this function panics instead of creating the environment. A panic crossing extern "C" aborts the caller.

Use .enable_all(), as the no-op constructor already does.

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/modrinth-sandbox/src/ffi/env.rs
Line: 33-36

Comment:
**C sandbox startup aborts**

`modrinth_sandbox_create_env` builds a Tokio runtime without enabling its I/O or time drivers. In Flatpak, `SandboxEnv::new()` immediately connects to the session bus through Tokio, so this function panics instead of creating the environment. A panic crossing `extern "C"` aborts the caller.

Use `.enable_all()`, as the no-op constructor already does.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Comment on lines +2180 to +2185
if let Err(errno) = rustix::fs::linkat(
old_dirfd,
&*old_path,
new_dirfd,
newname,
AtFlags::SYMLINK_NOFOLLOW,

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.

P2 Shared-folder hard links fail

Linux linkat does not accept AT_SYMLINK_NOFOLLOW; not following the source link is already its default. Passing AtFlags::SYMLINK_NOFOLLOW makes every hard-link request through this file-sharing filesystem fail with EINVAL.

Pass empty flags so mods can create hard links in shared folders.

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/modrinth-sandbox/src/backend/linux/file_sharing.rs
Line: 2180-2185

Comment:
**Shared-folder hard links fail**

Linux `linkat` does not accept `AT_SYMLINK_NOFOLLOW`; not following the source link is already its default. Passing `AtFlags::SYMLINK_NOFOLLOW` makes every hard-link request through this file-sharing filesystem fail with `EINVAL`.

Pass empty flags so mods can create hard links in shared folders.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

This branch has not been deployed

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

Development

Successfully merging this pull request may close these issues.

4 participants