mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 14:38:25 +00:00
fix: harden control ui framing + ws origin
This commit is contained in:
@@ -66,6 +66,12 @@ type ControlUiAvatarMeta = {
|
||||
avatarUrl: string | null;
|
||||
};
|
||||
|
||||
function applyControlUiSecurityHeaders(res: ServerResponse) {
|
||||
res.setHeader("X-Frame-Options", "DENY");
|
||||
res.setHeader("Content-Security-Policy", "frame-ancestors 'none'");
|
||||
res.setHeader("X-Content-Type-Options", "nosniff");
|
||||
}
|
||||
|
||||
function sendJson(res: ServerResponse, status: number, body: unknown) {
|
||||
res.statusCode = status;
|
||||
res.setHeader("Content-Type", "application/json; charset=utf-8");
|
||||
@@ -100,6 +106,8 @@ export function handleControlUiAvatarRequest(
|
||||
return false;
|
||||
}
|
||||
|
||||
applyControlUiSecurityHeaders(res);
|
||||
|
||||
const agentIdParts = pathname.slice(pathWithBase.length).split("/").filter(Boolean);
|
||||
const agentId = agentIdParts[0] ?? "";
|
||||
if (agentIdParts.length !== 1 || !agentId || !isValidAgentId(agentId)) {
|
||||
@@ -250,6 +258,7 @@ export function handleControlUiHttpRequest(
|
||||
|
||||
if (!basePath) {
|
||||
if (pathname === "/ui" || pathname.startsWith("/ui/")) {
|
||||
applyControlUiSecurityHeaders(res);
|
||||
respondNotFound(res);
|
||||
return true;
|
||||
}
|
||||
@@ -257,6 +266,7 @@ export function handleControlUiHttpRequest(
|
||||
|
||||
if (basePath) {
|
||||
if (pathname === basePath) {
|
||||
applyControlUiSecurityHeaders(res);
|
||||
res.statusCode = 302;
|
||||
res.setHeader("Location", `${basePath}/${url.search}`);
|
||||
res.end();
|
||||
@@ -267,6 +277,8 @@ export function handleControlUiHttpRequest(
|
||||
}
|
||||
}
|
||||
|
||||
applyControlUiSecurityHeaders(res);
|
||||
|
||||
const rootState = opts?.root;
|
||||
if (rootState?.kind === "invalid") {
|
||||
res.statusCode = 503;
|
||||
|
||||
Reference in New Issue
Block a user