mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 02:31:22 +00:00
fix(security): enforce sandbox bridge auth
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import crypto from "node:crypto";
|
||||
import type { SandboxBrowserContext, SandboxConfig } from "./types.js";
|
||||
import { startBrowserBridgeServer, stopBrowserBridgeServer } from "../../browser/bridge-server.js";
|
||||
import { type ResolvedBrowserConfig, resolveProfile } from "../../browser/config.js";
|
||||
@@ -149,13 +150,24 @@ export async function ensureSandboxBrowser(params: {
|
||||
? await readDockerPort(containerName, params.cfg.browser.noVncPort)
|
||||
: null;
|
||||
|
||||
const desiredAuthToken = params.bridgeAuth?.token?.trim() || undefined;
|
||||
const desiredAuthPassword = params.bridgeAuth?.password?.trim() || undefined;
|
||||
|
||||
const existing = BROWSER_BRIDGES.get(params.scopeKey);
|
||||
const existingProfile = existing
|
||||
? resolveProfile(existing.bridge.state.resolved, DEFAULT_OPENCLAW_BROWSER_PROFILE_NAME)
|
||||
: null;
|
||||
|
||||
let desiredAuthToken = params.bridgeAuth?.token?.trim() || undefined;
|
||||
let desiredAuthPassword = params.bridgeAuth?.password?.trim() || undefined;
|
||||
if (!desiredAuthToken && !desiredAuthPassword) {
|
||||
// Always require auth for the sandbox bridge server, even if gateway auth
|
||||
// mode doesn't produce a shared secret (e.g. trusted-proxy).
|
||||
// Keep it stable across calls by reusing the existing bridge auth.
|
||||
desiredAuthToken = existing?.authToken;
|
||||
desiredAuthPassword = existing?.authPassword;
|
||||
if (!desiredAuthToken && !desiredAuthPassword) {
|
||||
desiredAuthToken = crypto.randomBytes(24).toString("hex");
|
||||
}
|
||||
}
|
||||
|
||||
const shouldReuse =
|
||||
existing && existing.containerName === containerName && existingProfile?.cdpPort === mappedCdp;
|
||||
const authMatches =
|
||||
|
||||
Reference in New Issue
Block a user