ARTEX/server/sharedbrowser_pipe_unix.go
BaaRai 716e484e74 feat(server,web): opt-in shared browser with isolated CDP, per-task profiles, and configurable lock (#621)
Rebased onto main (5f5ec32) and hardened per security review:
- Opt-in only (-shared-browser / ARTEX_SHARED_BROWSER=true; default false); README and CHANGELOG accurately describe hardened behavior and document the residual risk of same-UID argv token visibility alongside per-message operator-hold/lease enforcement and immediate revocation.
- Isolates CDP via --remote-debugging-pipe on Unix (no Chromium DevTools TCP port or DevToolsActivePort) fronted by a per-run 256-bit token-authenticated server CDP proxy enforcing operator hold and active lease on every HTTP request and WebSocket message.
- Removes --ignore-certificate-errors from the capture path; trusts only ARTEX's capture CA SPKI pin (--ignore-certificate-errors-spki-list) and fails closed if unreadable.
- Removes --disable-blink-features=AutomationControlled and the HeadlessChrome user-agent rewrite (policy: hand challenges off via ask_operator).
- Isolates browser profiles per task or chat session under <data>/browser-profiles/<scope> using descriptor-relative openat(O_NOFOLLOW|O_DIRECTORY) + fchown + unlinkat with root-owned parent (no filepath.Walk over executor-owned trees), tested against root/scope/child symlinks.
- Makes operator lock / ask_operator hold timeout configurable via -shared-browser-lock-timeout / ARTEX_SHARED_BROWSER_LOCK_TIMEOUT (default 15m), auto-expiring idle locks.
Co-authored-by: Pranil Acharya <Pro-Nil@users.noreply.github.com>
2026-11-28 10:00:56 +01:00

49 lines
1.5 KiB
Go

//go:build unix
package server
import (
"context"
"fmt"
"os"
"os/exec"
)
// sharedBrowserUsesPipe reports whether this platform launches Chromium with
// --remote-debugging-pipe so no unauthenticated DevTools TCP port is opened.
const sharedBrowserUsesPipe = true
// startSharedBrowserCDP launches Chromium using --remote-debugging-pipe (FD 3
// for incoming commands, FD 4 for outgoing responses/events). Because Chromium
// binds no TCP port and writes no DevToolsActivePort file, an agent Bash
// subprocess cannot connect directly to Chromium.
func (b *sharedBrowser) startSharedBrowserCDP(_ context.Context, cmd *exec.Cmd, _ string) (*cdpConn, <-chan struct{}, error) {
// FD 3: parent writes -> Chromium reads.
inR, inW, err := os.Pipe()
if err != nil {
return nil, nil, fmt.Errorf("cdp pipe in: %w", err)
}
// FD 4: Chromium writes -> parent reads.
outR, outW, err := os.Pipe()
if err != nil {
_ = inR.Close()
_ = inW.Close()
return nil, nil, fmt.Errorf("cdp pipe out: %w", err)
}
cmd.ExtraFiles = []*os.File{inR, outW}
if err := cmd.Start(); err != nil {
_ = inR.Close()
_ = inW.Close()
_ = outR.Close()
_ = outW.Close()
return nil, nil, fmt.Errorf("start %s: %w", cmd.Path, err)
}
// Close the child ends in the parent so EOF propagates cleanly on exit.
_ = inR.Close()
_ = outW.Close()
exited := make(chan struct{})
go func() { _ = cmd.Wait(); close(exited) }()
conn := newPipeCDP(inW, outR, b.onEvent)
return conn, exited, nil
}