mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 20:28:29 +00:00
fix(security): enforce sandbox bridge auth
This commit is contained in:
34
src/browser/bridge-auth-registry.ts
Normal file
34
src/browser/bridge-auth-registry.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
type BridgeAuth = {
|
||||
token?: string;
|
||||
password?: string;
|
||||
};
|
||||
|
||||
// In-process registry for loopback-only bridge servers that require auth, but
|
||||
// are addressed via dynamic ephemeral ports (e.g. sandbox browser bridge).
|
||||
const authByPort = new Map<number, BridgeAuth>();
|
||||
|
||||
export function setBridgeAuthForPort(port: number, auth: BridgeAuth): void {
|
||||
if (!Number.isFinite(port) || port <= 0) {
|
||||
return;
|
||||
}
|
||||
const token = typeof auth.token === "string" ? auth.token.trim() : "";
|
||||
const password = typeof auth.password === "string" ? auth.password.trim() : "";
|
||||
authByPort.set(port, {
|
||||
token: token || undefined,
|
||||
password: password || undefined,
|
||||
});
|
||||
}
|
||||
|
||||
export function getBridgeAuthForPort(port: number): BridgeAuth | undefined {
|
||||
if (!Number.isFinite(port) || port <= 0) {
|
||||
return undefined;
|
||||
}
|
||||
return authByPort.get(port);
|
||||
}
|
||||
|
||||
export function deleteBridgeAuthForPort(port: number): void {
|
||||
if (!Number.isFinite(port) || port <= 0) {
|
||||
return;
|
||||
}
|
||||
authByPort.delete(port);
|
||||
}
|
||||
Reference in New Issue
Block a user