ARTEX/server/sharedbrowser_pipe_other.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

39 lines
1.2 KiB
Go

//go:build !unix
package server
import (
"context"
"fmt"
"os"
"os/exec"
"path/filepath"
)
const sharedBrowserUsesPipe = false
// startSharedBrowserCDP starts Chromium on non-Unix platforms (where ExtraFiles
// is unavailable) using an ephemeral loopback port, deletes DevToolsActivePort
// immediately after reading it, and routes MCP clients through ARTEX's
// authenticated CDP proxy.
func (b *sharedBrowser) startSharedBrowserCDP(ctx context.Context, cmd *exec.Cmd, profileDir string) (*cdpConn, <-chan struct{}, error) {
if err := cmd.Start(); err != nil {
return nil, nil, fmt.Errorf("start %s: %w", cmd.Path, err)
}
exited := make(chan struct{})
go func() { _ = cmd.Wait(); close(exited) }()
port, path, err := waitDevToolsPort(ctx, profileDir, exited)
// Remove DevToolsActivePort immediately so it is not left readable on disk.
_ = os.Remove(filepath.Join(profileDir, "DevToolsActivePort"))
if err != nil {
_ = cmd.Process.Kill()
return nil, nil, err
}
conn, err := dialCDP(ctx, "ws://127.0.0.1:"+port+path, b.onEvent)
if err != nil {
_ = cmd.Process.Kill()
return nil, nil, fmt.Errorf("connect to the browser: %w", err)
}
return conn, exited, nil
}