mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-04 12:11:36 +00:00
* fix(gateway): consume structured scope errors * docs(gateway): clarify tools error boundary * refactor(gateway): unify node admin policy
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce";
|
|
|
|
function normalizeBrowserProxyPath(value: string): string {
|
|
const trimmed = value.trim();
|
|
if (!trimmed) {
|
|
return trimmed;
|
|
}
|
|
const withLeadingSlash = trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
if (withLeadingSlash.length <= 1) {
|
|
return withLeadingSlash;
|
|
}
|
|
return withLeadingSlash.replace(/\/+$/, "");
|
|
}
|
|
|
|
function isPersistentBrowserProxyMutation(method: string, path: string): boolean {
|
|
const normalizedPath = normalizeBrowserProxyPath(path);
|
|
if (
|
|
method === "POST" &&
|
|
(normalizedPath === "/profiles/create" || normalizedPath === "/reset-profile")
|
|
) {
|
|
return true;
|
|
}
|
|
return method === "DELETE" && /^\/profiles\/[^/]+$/.test(normalizedPath);
|
|
}
|
|
|
|
export function isForbiddenBrowserProxyMutation(params: unknown): boolean {
|
|
if (!params || typeof params !== "object") {
|
|
return false;
|
|
}
|
|
const candidate = params as { method?: unknown; path?: unknown };
|
|
const method = (normalizeOptionalString(candidate.method) ?? "").toUpperCase();
|
|
const path = normalizeOptionalString(candidate.path) ?? "";
|
|
return Boolean(method && path && isPersistentBrowserProxyMutation(method, path));
|
|
}
|