Repository navigation
Conversation
|
Status: ready for a maintainer. The change is a runtime default, so it needs a design sign-off as well as a code review; the PR description makes the case. Reproduced as root (uid 0) with Google Chrome 151 at Verification, head 1b3e0a2 (52def55 rebased onto main after #40165; the only conflict was the harness import line in |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (6)
Included review availability: Your plan provides up to 5 included reviews per hour; 1 remains after this review. WalkthroughChangesWebView Chrome launch flags
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Comment |
There was a problem hiding this comment.
LGTM — test-only fix that conditionally passes --no-sandbox to Chrome when the test runs as root.
What was reviewed:
- Confirmed
extra_argvis appended after core flags inChromeProcess.rs:549, so an emptyargv: []on non-root runs leaves Chrome's argv byte-identical to before. - Checked that
url: false+argvdoes not trip the connect-mode/spawn-option validation (that guard fires only on a stringurl). chromeSourceinterpolation into thebun -esubprocess literals is safe — the object contains only fixed JSON-safe values.process.getuid?.()correctly yieldsundefinedon Windows, leaving the flag off there.
Extended reasoning...
Overview
This PR touches a single test file, test/js/bun/webview/webview-chrome.test.ts. It introduces a chromeArgv array that is ["--no-sandbox"] when process.getuid?.() === 0 and [] otherwise, then threads that array through every Chrome launch site in the file: the shared chrome backend object, the path object-form test, the argv test (spread before --user-agent), and the six bun -e subprocess tests via a new chromeSource = JSON.stringify(chrome) literal. No runtime code is touched.
Security risks
None. This is test-only harness plumbing. --no-sandbox is only added when uid is 0, which is exactly the environment in which Chrome refuses to start without it (crbug.com/638180). Non-root and CI runs keep launching Chrome with the runtime's default flags, sandbox included. The JSON.stringify interpolation into subprocess source contains only fixed string/boolean/array literals — no user-controlled data.
Level of scrutiny
Low. The change is mechanical test infrastructure, mirrors an existing precedent in the sibling webview-chrome-disconnect.test.ts:248, and the PR description verifies (via a BUN_CHROME_PATH argv-dump script) that non-root argv is unchanged. I cross-checked src/runtime/webview/ChromeProcess.rs — extra_argv is null-or-slice, iterated and appended after the fixed flag vector at line 549, so an empty array is a true no-op. The connect-mode validation (url: <string> combined with spawn options) does not apply since url: false selects spawn mode.
Other factors
The argv test still proves what it did before: --user-agent=BunWebViewTest/1.0 must reach Chrome for navigator.userAgent to match, regardless of what precedes it. process.getuid is undefined on Windows, so the optional chain leaves chromeArgv empty there. The bug hunting system found no issues. This is a self-contained improvement to developer ergonomics for root-container testing with zero effect on CI behavior.
6cd6fa1 to
11e821b
Compare
|
Updated 10:54 PM PT - Aug 22nd, 2026
✅ @robobun, your commit 1b3e0a2c9eb2963ea6a135783fad1ff38e7dca0a passed in 🧪 To try this PR locally: bunx bun-pr 39490That installs a local version of the PR into your bun-39490 --bun |
There was a problem hiding this comment.
I reviewed this PR and didn't find any bugs. The change is small and the reasoning is sound, but it changes a user-facing runtime default (auto-adding --no-sandbox for root) and touches packages/bun-types/bun.d.ts which is CODEOWNER-protected, so a maintainer sign-off would be worthwhile.
What was reviewed:
- The
geteuid()predicate matches Chrome's own check and thesafe fndeclaration follows the existinggetuid/getgidpattern insrc/sys/lib.rs. - Flag insertion order:
--no-sandboxlands beforeextra_argv, so a user'sbackend.argvstill overrides (Chrome last-wins), and the#[cfg]gate keeps non-Linux argv byte-identical. - The new pipe test pins the full documented switch list via
process.execArgvon the fake-chrome fixture and correctly branches onprocess.platform === "linux" && geteuid() === 0. - Considered whether disabling the sandbox weakens anything a root user had before — it does not, since Chrome refuses to start at all in that configuration.
Extended reasoning...
Overview
This PR appends --no-sandbox to the Chrome launch argv in src/runtime/webview/ChromeProcess.rs::spawn() when geteuid() == 0 on Linux/Android. Supporting changes: a safe fn geteuid() declaration in src/sys/lib.rs (mirroring the existing getuid), a two-line doc addition in docs/runtime/webview.mdx, a two-line JSDoc addition in packages/bun-types/bun.d.ts, removal of the now-redundant hardcoded --no-sandbox from webview-chrome-disconnect.test.ts, and a new argv-assertion test in webview-chrome-pipe.test.ts.
Security risks
The change disables Chrome's renderer sandbox, but only when the effective uid is 0 — a configuration in which Chrome otherwise hard-exits at startup (crbug.com/638180). So no protection that would have existed is removed; the alternative is no browser at all. Playwright's launcher (which this flag list already follows) defaults chromiumSandbox to false unconditionally, so this is strictly narrower. Non-root users see zero argv change. I don't see an injection, auth, or data-exposure surface here.
Level of scrutiny
Medium. The core logic is 4 lines behind a #[cfg] gate and a uid check, and the geteuid FFI declaration is trivially safe (no args, never fails, same shape as getuid right above it). What raises it above "mechanical" is that it's a runtime default change — the launcher now emits a different argv for a class of users without them asking. The PR argues convincingly that this is the only launchable configuration for that class, and that it also covers the ChromeBackend.cpp fallback-spawn path that user-supplied backend.argv cannot reach. Still, opting the runtime into --no-sandbox by default is the kind of API-surface decision a maintainer should confirm.
Other factors
- CODEOWNERS:
packages/bun-types/bun.d.tsis owned per.github/CODEOWNERS. The change there is JSDoc-only (no type signature changes), but the ownership rule applies. - Tests: The new
webview-chrome-pipe.test.tstest asserts the exact argv list against the fake-chrome fixture (runs everywhere, no browser needed) and correctly conditions--no-sandboxonprocess.platform === 'linux' && process.geteuid?.() === 0. Thewebview-chrome-disconnect.test.tschange turns an existing real-Chrome test into a second regression guard (as root, it now fails without the runtime fix). The PR description reportsrust:check-allpassing across 12 targets and the fulltest/js/bun/webview/suite passing as root. - Comment-cop feedback: Both bot comments were addressed (comment shortened to two lines in 7777501) and the threads are resolved.
- No prior review from me on this PR.
There was a problem hiding this comment.
I reviewed this PR and didn't find any bugs (the earlier isLinux nit was addressed in 21617ab). Because it changes a security-relevant runtime default — passing --no-sandbox to Chrome automatically when Bun runs as root — a maintainer should confirm the design decision.
What was reviewed:
- The argv change in
ChromeProcess.rs:--no-sandboxis gated on Linux/Android +getuid()==0 || geteuid()==0, inserted before userargvso users can still override; non-root users only gain--disable-dev-shm-usage. src/sys/lib.rs:geteuiddeclared exactly like the existinggetuid(safe fn,#[cfg(unix)]).- The new
webview-chrome-pipe.test.tsassertions match the documented flag list and therootOnLinuxpredicate mirrors the Rust condition; theseteuid(65534)test correctly runs only when the harness process is real-root on Linux. - Docs (
webview.mdx) andbun.d.tsJSDoc list match the argv vector inspawn().
Extended reasoning...
Overview
The PR appends two switches to the argv ChromeProcess.rs::spawn() builds for the Chrome subprocess: --disable-dev-shm-usage unconditionally, and --no-sandbox on Linux/Android when either the real or effective uid is 0. src/sys/lib.rs adds a safe fn geteuid() declaration next to the existing getuid(). Docs and the Backend JSDoc are updated to list the full flag set, a hardcoded argv: ["--no-sandbox"] is removed from webview-chrome-disconnect.test.ts, and two new tests in webview-chrome-pipe.test.ts assert the exact argv the runtime hands to the (fake) browser.
Security risks
The change disables Chrome's renderer sandbox when Bun runs as root. The reasoning is well-argued: Chrome hard-exits as root with the sandbox on (crbug.com/638180), so root users get nothing today, and Playwright's chromiumSandbox defaults to false for everyone. Non-root users are unaffected — they only pick up --disable-dev-shm-usage, which is inert outside containers with a small /dev/shm. Still, "the runtime silently turns off a browser sandbox based on uid" is exactly the kind of default a maintainer should sign off on rather than have auto-approved.
Level of scrutiny
The Rust diff is ~15 lines and mechanically simple: a c"..." literal pushed into an existing Vec<*const c_char>, and a #[cfg]-gated if that reads two libc functions already declared as safe fn. No memory-safety concerns (all string literals are 'static). The #[cfg(any(target_os = "linux", target_os = "android"))] on both the use bun_core::ZStr import and the uid check keeps other platforms compiling cleanly (the author reports rust:check-all passes 12 targets). What warrants human review is not the implementation but the product decision to change a default.
Other factors
The PR description is unusually thorough — it documents why both uids are checked (bash launcher scripts reset euid to ruid), why the fix belongs in the launcher rather than per-test (the auto-detect fallback spawn ignores backend.argv), and cites Playwright/puppeteer precedent plus two in-repo puppeteer harnesses that already pass --disable-dev-shm-usage. The new tests use the fake-chrome fixture so the argv assertion runs on every CI lane without a real browser, and the author verified fail-before/pass-after both as root and as uid 1500. The comment-cop bot fired on the inline comments; the author shortened them and the remaining ones follow the file's existing per-switch comment pattern. My only prior finding (the local isLinux redefinition) was fixed in 21617ab.
There was a problem hiding this comment.
I reviewed this PR and didn't find any bugs (the earlier isLinux nit was addressed in 21617ab). Because it changes a security-relevant default — auto-passing --no-sandbox to Chrome based on the process's uid/gid state — a human should confirm the policy choice before merge.
What was reviewed: the three-term uid/gid condition against Chrome's ZygoteHostImpl::Init/GetRESIds semantics; that --no-sandbox is appended before user argv so users can still override; that the new geteuid/getegid decls sit under #[cfg(unix)] alongside the existing getuid/getgid; that sandboxRefused() and asRoot short-circuit on hasZygoteCheck so process.getuid!() never runs on Windows/macOS; and that isAndroid exists in the harness.
Extended reasoning...
Overview
This PR changes the default Chrome launch flags in Bun.WebView's Chrome backend so it works out of the box when Bun runs as root (the common container case) and in Docker's default 64 MB /dev/shm. It touches:
src/runtime/webview/ChromeProcess.rs— appends--disable-dev-shm-usageunconditionally and--no-sandboxon Linux/Android whengeteuid()==0 || getuid()!=geteuid() || getgid()!=getegid().src/sys/lib.rs— addsgeteuid/getegidsafe fndeclarations next to the existinggetuid/getgidunder#[cfg(unix)].docs/runtime/webview.mdxandpackages/bun-types/bun.d.ts— document the new defaults.test/js/bun/webview/webview-chrome-pipe.test.ts— three new tests asserting the exact argv against a fake-Chrome fixture, one per term of the condition.test/js/bun/webview/webview-chrome-disconnect.test.ts— removes the now-redundant hardcodedargv: ["--no-sandbox"].
Security risks
The core change disables Chrome's renderer sandbox when Bun is root or has mixed real/effective ids. The PR's reasoning is sound — Chrome hard-exits in exactly those states without the flag, so no security is lost relative to "doesn't launch at all", and Playwright ships --no-sandbox for every user by default. Non-root users keep the sandbox; the only argv change they see is --disable-dev-shm-usage. Still, this is a change to the default security posture of a user-facing API, and there's a defensible alternative position (fail loudly and require explicit opt-in via backend.argv). That policy call belongs to a maintainer.
Level of scrutiny
Medium-high. The Rust change is small and mechanical (two hunks in spawn(), two new safe FFI decls), and the condition is derived directly from Chrome's own ZygoteHostImpl::Init check with an empirical matrix in the PR description. But "automatically disable the browser sandbox" is the kind of default a human should sign off on.
Other factors
- My prior review left one nit (
isLinuxredefined locally instead of imported from harness); it was fixed in 21617ab and the import now includesisAndroidandisLinuxfrom harness. - The comment-cop bot repeatedly flagged the two-line comments above the new flags; the author's responses (each switch in that vector already carries a short why-comment, and the three-term condition needs the
ZygoteHostImplpointer to be verifiable) are consistent with the file's existing style and were resolved. - Test coverage is thorough: the fake-Chrome fixture asserts the exact argv on every platform, plus two root-only Linux tests that isolate each remaining term of the condition, plus the real-Chrome disconnect test now depending on the runtime-supplied flag.
- I checked that
sandboxRefused()and theasRootgate both short-circuit onhasZygoteCheck = isLinux || isAndroidbefore touchingprocess.getuid!(), so the test file loads on Windows/macOS where those functions are undefined.
6a5184b to
52def55
Compare
There was a problem hiding this comment.
LGTM — the earlier nit (import isLinux from harness) was addressed.
What was reviewed:
- The two-flag addition in
ChromeProcess.rs:--disable-dev-shm-usageunconditionally,--no-sandboxonly on Linux/Android whengeteuid() == 0— placed before userargvso last-wins override still works. geteuiddeclaration insrc/sys/lib.rsfollows the existinggetuid/getgidpattern under#[cfg(unix)].- New pipe tests:
process.geteuid!()is guarded byhasRootCheckshort-circuit so it's never called on Windows;isAndroid/isLinuxboth exist in harness;userNamespaceWorks()probe wrapsspawnSyncin try/catch for missingunshare. - The two removed
argv: ["--no-sandbox"]test workarounds are now covered by the runtime default.
Extended reasoning...
Overview
This PR makes Bun.WebView({ backend: "chrome" }) work in root containers by appending two Chrome launch flags in src/runtime/webview/ChromeProcess.rs::spawn(): --disable-dev-shm-usage always (Docker's 64 MB /dev/shm otherwise kills Chrome after a few tabs), and --no-sandbox on Linux/Android when geteuid() == 0 (Chrome hard-exits as root otherwise, per crbug.com/638180). src/sys/lib.rs gains a one-line geteuid safe FFI declaration next to the existing getuid. Docs (webview.mdx) and JSDoc (bun.d.ts) are updated to list the new defaults. Two tests that hardcoded --no-sandbox drop it, and webview-chrome-pipe.test.ts gains two new assertions that verify the argv via the existing fake-chrome fixture (one always, one under unshare -U -r to cover the root path on non-root CI).
Security risks
--no-sandbox disables Chrome's renderer sandbox, which is a security-relevant flag. The mitigation is that the condition is narrowly scoped: it only fires when geteuid() == 0 on Linux/Android, and in that state Chrome refuses to start at all without the flag — so no working sandbox is being removed. Non-root users keep the sandbox; the only argv change they see is --disable-dev-shm-usage, which redirects shared-memory files to tmpdir and is the default in both Playwright and puppeteer. The flag is inserted before user-supplied argv, so Chrome's last-wins duplicate-switch resolution lets users override either default.
Level of scrutiny
Medium-low. The native change is ~10 lines and follows the file's established pattern (every flag in the vector has a short justifying comment). The geteuid addition is a mechanical mirror of the neighboring getuid declaration under the same #[cfg(unix)] gate. The behavior matches what Playwright ships to every user by default. The PR description is unusually thorough (includes a table of Chrome's uid/gid check states verified against Chrome 151, and records why earlier wider conditions were narrowed back to euid-only).
Other factors
- CI is green (build 100673, 179/179).
- My prior review left one nit (locally redefined
isLinux), which was fixed in 21617ab — verified in the current diff. - The one unresolved thread is the automated comment-cop bot's fifth identical "paragraph-long comment" flag on the two-line
--no-sandboxcomment; the author has rebutted this same heuristic four times with sound reasoning (the comment matches the file's per-flag convention and cites the upstream bug), and the current text is indeed two short lines. Not a substantive blocker. - Test design is solid: the fake-chrome fixture lets argv be asserted exactly on every platform without a browser; the
unshare -U -rprobe correctly falls back totest.skipwhen user namespaces are unavailable;process.geteuid!()is only reached after thehasRootCheckshort-circuit so Windows never evaluates it.
…dev-shm-usage always Chrome exits at startup when it runs as root with its sandbox on (crbug.com/638180), so the chrome backend never worked as root, which is how Bun usually runs inside a container. backend.argv can add the flag for an explicit spawn, but not for the spawn ChromeBackend.cpp falls back to when a stale DevToolsActivePort file fails to connect, which passes no argv. spawn() in ChromeProcess.rs now appends --no-sandbox when geteuid() is 0, on Linux only. Docker gives /dev/shm 64MB, which Chrome fills after two 1280x720 tabs and then dies. --disable-dev-shm-usage joins the fixed flags, as in Playwright and puppeteer. The docs and the Backend JSDoc list both. webview-chrome-pipe.test.ts asserts the switches the fake browser is started with: the documented list, plus --no-sandbox when the test itself runs as root, and a second test that runs the scenario under unshare -U -r so the flag is also asserted on CI lanes that allow unprivileged user namespaces. The two tests that hardcoded the flag now rely on the runtime; with this, test/js/bun/webview/ passes as root with a real Chrome installed (48 failures in webview-chrome.test.ts before).
52def55 to
1b3e0a2
Compare
There was a problem hiding this comment.
I reviewed this PR and didn't find any bugs. Since it changes a user-facing runtime default and conditionally disables Chrome's sandbox, a maintainer sign-off on the design is still warranted (as the author already noted).
What was reviewed:
- The
geteuid()addition insrc/sys/lib.rsfollows the existinggetuid/getgidpattern and is correctly#[cfg(unix)]-gated for the Linux/Android call site. - Flag placement in
spawn()—--no-sandboxlands after the fixed switches and before userargv, so a user can still override it;--disable-dev-shm-usagematches what Playwright/puppeteer and this repo's own puppeteer harnesses already pass. - The new pipe tests:
process.geteuid!()is guarded byhasRootCheckso it never runs on Windows/macOS, and theunshare -U -rprobe skips cleanly where user namespaces are unavailable. - The two removed hardcoded
argv: ["--no-sandbox"]sites are now covered by the runtime default when root; non-root runs of those tests were already unaffected.
Extended reasoning...
Overview
This PR changes the default Chrome launch flags in Bun.WebView's Chrome backend (src/runtime/webview/ChromeProcess.rs): it always passes --disable-dev-shm-usage, and on Linux/Android it additionally passes --no-sandbox when Bun's effective uid is 0. Supporting changes: a safe geteuid() declaration in src/sys/lib.rs, updated docs (docs/runtime/webview.mdx) and JSDoc (packages/bun-types/bun.d.ts), two new tests in webview-chrome-pipe.test.ts that assert the exact argv via the fake-Chrome fixture, and removal of two now-redundant hardcoded --no-sandbox copies from existing tests.
Security risks
The change disables Chrome's renderer sandbox — but only when Bun is already root, where Chrome refuses to start with the sandbox enabled anyway (crbug.com/638180). So the flag turns a guaranteed launch failure into the same configuration Playwright ships by default; it does not remove a sandbox any root user could have had. Non-root users keep the sandbox and only gain --disable-dev-shm-usage, which redirects shared-memory files to the temp dir with no security implication. There is no injection or auth surface here — argv construction uses C string literals and the existing user-argv append path is unchanged.
Level of scrutiny
Medium-high. The code change is small and mechanically simple (one flag pushed unconditionally, one behind a two-line cfg-gated uid check), but it is a runtime default change to user-facing API behavior, and it touches a security-adjacent knob (browser sandboxing). The PR author explicitly flagged that this needs design sign-off from a maintainer, and REVIEW.md's API-design guidance applies. This is exactly the kind of decision — "is auto-disabling the sandbox for root the right default for Bun" — that a human maintainer should weigh in on, even though the implementation itself is sound.
Other factors
- All prior review threads are resolved: the comment-cop bot's repeated "paragraph-long comment" flags were addressed/rebutted, and my earlier nit about importing
isLinuxfrom harness was fixed in 21617ab. - Test coverage is thorough: the new "documented switches" test asserts the exact argv on every lane (fails on unfixed builds for the missing
--disable-dev-shm-usage), and theunshare-based test covers the root path on lanes that support user namespaces. CI build 101118 confirms the namespace test ran on Debian 13 and skipped on Ubuntu 25.04 as designed. - The PR description is unusually detailed about alternatives considered (wider uid rules, mixed-uid handling via bash launcher scripts) and why they were dropped — this is exactly the record a maintainer needs to evaluate the design choice.
|
Closing as stale: this PR conflicts with main, and its last commit is from 2026-08-23. The branch stays, so the work is not lost. To pick it up again, rebase the branch on main and reopen this PR. |
Problem
new Bun.WebView({ backend: "chrome" })never works when Bun runs as root, which is how most containers run it. Chrome exits during startup and the constructor or the firstnavigate()fails witherror: Chrome exited. Chrome's own message is only visible withbackend.stderr: "inherit":zygote_host_impl_linux.cc: Running as root without --no-sandbox is not supported. See https://crbug.com/638180.src/runtime/webview/ChromeProcess.rs, theargvvector inspawn()) has no--no-sandbox. A user can add it throughbackend.argv, except on one path: when auto-detect finds a staleDevToolsActivePortfile and the WebSocket connect fails,ChromeBackend.cpprespawns with an empty argv, so that spawn cannot be fixed from JS./dev/shm64 MB, Chrome puts its shared memory there, and in this container the third 1280x720 view (the size of the docs example) dies withChrome killed by signal 5. Playwright and puppeteer both pass--disable-dev-shm-usageby default, as do both puppeteer harnesses in this repo (test/scripts/browser.js,test/integration/next-pages/test/dev-server-puppeteer.ts).test/js/bun/webview/webview-chrome.test.tsfails 48 of 57 tests, and the workaround is being copied per test instead: two tests on main hardcodeargv: ["--no-sandbox"](webview-chrome-disconnect.test.ts, and the test webview: close the views orphaned by a browser death #39097 added towebview-chrome.test.ts), and webview: make Chrome evaluate() results follow the documented JSON round trip #39085, webview: size the Chrome page viewport with a device metrics override instead of the window #39090 and webview: decode JSON escapes in the Chrome backend's title, url and error messages #39091 each carry a further variant. CI does not see any of this because its agents are not root.Fix
ChromeProcess.rs::spawn()appends--no-sandboxafter the fixed flags, beforebackend.argv, when the target is Linux andgeteuid()is 0.--disable-dev-shm-usagejoins the fixed flags on every platform (Chrome ignores it where there is no/dev/shm), as in Playwright and puppeteer. These two hunks are the fix;src/sys/lib.rsonly addsgeteuidnext to the existinggetuidsafe declaration.chromiumSandboxoption defaults to false, and this flag set already follows Playwright's, see the comments inspawn()). Every non-root user keeps the sandbox, and the argv they get gains only--disable-dev-shm-usage. A user who already passes either flag gets a duplicate switch, which Chrome accepts.google-chromelauncher script is bash, which makes the ids uniform again), so no fixed rule for that case is right on both paths, and nobody has reported it. Details in the notes. A non-root container that blocks Chrome's sandbox is a separate case the runtime cannot detect; the docs now say to passargv: ["--no-sandbox"]there.--no-sandbox(target_os = "linux"or"android"): the refusal comes from Chrome's Linux-only zygote host (zygote_host_impl_linux.cc, the file named in the error), so there is nothing to add on macOS, and Windows has no uid.docs/runtime/webview.mdx) and theBackendJSDoc inbun.d.tsstate the new defaults (the JSDoc list was already missing half of the flags, so it now carries the full list). The two hardcoded--no-sandboxcopies in the tests are removed, since the runtime now supplies the flag.test/js/bun/webview/webview-chrome-pipe.test.ts. The fake browser there is bun runningfake-chrome-fixture.ts, so the switches the runtime passes show up in itsprocess.execArgvand no browser is needed:--no-sandboxexactly when the test process itself is root. Runs on every lane. On the unfixed build it fails everywhere (no--disable-dev-shm-usage); as root it also fails for the missing--no-sandbox.unshare -U -r, which makes the unprivileged CI user root inside a user namespace, and asserts the flag literally. It probes first (bun spawning bun inside the namespace) and skips where user namespaces are unavailable. In CI build 101118 it ran and passed on the Debian 13 lanes (the file reports 9 pass, 2 skip there, the 2 being the Windows-only tests) and skipped on Ubuntu 25.04 (8 pass, 3 skip), which restricts unprivileged user namespaces. It also skips in the container used for the work here.webview-chrome.test.ts, are verified by hand as root:bun bd test test/js/bun/webview/with Google Chrome 151 installed passes in full (48 failures inwebview-chrome.test.tsbefore).BUN_CHROME_PATHpointed at a script that dumps"$@": as uid 1500 it is the unfixed list plus--disable-dev-shm-usage, as root it additionally ends in--no-sandbox./dev/shm): Chrome dies at the third view without--disable-dev-shm-usageand survives all six with it.bun run rust:check-all: 12 targets ok.test/integration/bun-types/bun-types.test.tspasses.Background
Bun.WebView's Chrome backend spawns one Chrome per process with a fixed flag list and talks to it over--remote-debugging-pipe.backend.argvis appended after that list, and only the firstnew Bun.WebView()in a process decides the flags, because later views reuse the running Chrome.--no-sandboxis passed. Chrome made this a hard exit on purpose (crbug.com/638180), so there is no other flag or environment setting that makes Chrome start as root./dev/shmis the tmpfs Chrome uses by default for the shared memory that carries rendered tiles between its processes. Docker mounts it with a 64 MB limit unless--shm-sizeis given.--disable-dev-shm-usagemakes Chrome create those files in the temporary directory instead.backend: "chrome", Bun first looks for a running Chrome'sDevToolsActivePortfile and connects to it. If the file is stale, the connection fails and Bun falls back to spawning its own Chrome. That fallback spawn does not carry the options from the constructor call, which is why the flag has to live in the runtime's own list to cover it.unshare -U -r) lets an unprivileged process see itself as uid 0 inside the namespace without gaining any privilege outside it. The runtime'sgeteuid()returns 0 there, which is what the second test relies on.Notes
Chrome's full check.
ZygoteHostImpl::Initcallssandbox::Credentials::GetRESIds(), which fails when the real, effective and saved uids are not all equal or the gids are not all equal, and exits with the "Running as root" message when that call fails or the uid is 0. Confirmed against Chrome 151 by starting/opt/google/chrome/chromedirectly aftersetresuid/setresgid(with--disable-crash-reporter, because in this container the crash handler otherwise dies first in every non-root state):Every refused row starts with
--no-sandboxadded.Why the mixed-id rows are not handled. The rows only describe a directly executed binary. The first candidates
find_chrome()looks for (google-chrome-stable,google-chrome, most distrochromiumentries) are shell scripts, and a shell started with differing ids resets the effective ids to the real ones, so through them Chrome sees uniform ids: a process with real uid 0 and a dropped effective uid launches a root Chrome (flag needed), while the mixed non-root rows launch a uniform non-root Chrome that the sandbox check accepts (flag harmful). Passing the flag for mixed ids therefore fixes the direct-binary path and removes a working sandbox on the default path, and not passing it does the reverse. Earlier versions of this PR triedgetuid() == 0 || geteuid() == 0and then Chrome's full rule; with no report of either situation, the PR keeps the rule to the case that is reproduced, andbackend.argvremains the way to handle the others.Earlier versions. The first version changed only
webview-chrome.test.ts, threading a root-conditional argv through its launch sites. Self-review pointed out that this was another copy of the per-test workaround and could never cover the argv-less fallback spawn, so the fix moved into the launcher. Later rounds added--disable-dev-shm-usage(the container the docs describe still killed Chrome after two views), widened the uid rule as described above, and then narrowed it back.no test proof · iteration 1 · platform-specific test(s) that do not run on this machine, deferring to CI, which covers all platforms: test/js/bun/webview/webview-chrome.test.ts, test/js/bun/webview/webview-chrome-pipe.test.ts, test/js/bun/webview/webview-chrome-disconnect.test.ts