mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 07:21:23 +00:00
fix(security): enforce sandbox bridge auth
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { formatCliCommand } from "../cli/command-format.js";
|
||||
import { loadConfig } from "../config/config.js";
|
||||
import { getBridgeAuthForPort } from "./bridge-auth-registry.js";
|
||||
import { resolveBrowserControlAuth } from "./control-auth.js";
|
||||
import {
|
||||
createBrowserControlContext,
|
||||
@@ -37,13 +38,36 @@ function withLoopbackBrowserAuth(
|
||||
const auth = resolveBrowserControlAuth(cfg);
|
||||
if (auth.token) {
|
||||
headers.set("Authorization", `Bearer ${auth.token}`);
|
||||
} else if (auth.password) {
|
||||
return { ...init, headers };
|
||||
}
|
||||
if (auth.password) {
|
||||
headers.set("x-openclaw-password", auth.password);
|
||||
return { ...init, headers };
|
||||
}
|
||||
} catch {
|
||||
// ignore config/auth lookup failures and continue without auth headers
|
||||
}
|
||||
|
||||
// Sandbox bridge servers can run with per-process ephemeral auth on dynamic ports.
|
||||
// Fall back to the in-memory registry if config auth is not available.
|
||||
try {
|
||||
const parsed = new URL(url);
|
||||
const port =
|
||||
parsed.port && Number.parseInt(parsed.port, 10) > 0
|
||||
? Number.parseInt(parsed.port, 10)
|
||||
: parsed.protocol === "https:"
|
||||
? 443
|
||||
: 80;
|
||||
const bridgeAuth = getBridgeAuthForPort(port);
|
||||
if (bridgeAuth?.token) {
|
||||
headers.set("Authorization", `Bearer ${bridgeAuth.token}`);
|
||||
} else if (bridgeAuth?.password) {
|
||||
headers.set("x-openclaw-password", bridgeAuth.password);
|
||||
}
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
|
||||
return { ...init, headers };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user