openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
74 lines (73 loc) • 2.49 kB
JavaScript
import { l as emitTrustedSecurityEvent } from "./diagnostic-events-BjAH1Kbx.mjs";
import { r as sha256HexPrefixCore } from "./node-crypto-B6yuTjmm.mjs";
import "./crypto-digest-B2m8wIBj.mjs";
//#region src/gateway/server-methods/device-management-authz.ts
function resolveDeviceSessionAuthz(e) {
const t = e?.connect.scopes ?? [];
return {
callerDeviceId: e?.isDeviceTokenAuth ? e.connect.device?.id.trim() || null : null,
callerScopes: t,
isAdminCaller: t.includes("operator.admin")
};
}
function resolveDeviceManagementAuthz(e, t) {
return {
...resolveDeviceSessionAuthz(e),
normalizedTargetDeviceId: t.trim()
};
}
function deniesCrossDeviceManagement(e) {
return Boolean(e.callerDeviceId && e.callerDeviceId !== e.normalizedTargetDeviceId && !e.isAdminCaller);
}
function deniesDeviceTokenRoleManagement(e, t) {
return !e.isAdminCaller && requestsNonOperatorDeviceRole({ role: t });
}
function requestsNonOperatorDeviceRole(e) {
return [e.role, ...e.roles ?? []].some((e) => {
const t = e?.trim();
return Boolean(t && t !== "operator");
});
}
function pairedDeviceHasNonOperatorRole(e) {
return requestsNonOperatorDeviceRole(e) || Object.values(e.tokens ?? {}).some((e) => {
const t = e.role.trim();
return Boolean(t && t !== "operator");
});
}
//#endregion
//#region src/gateway/server-methods/device-management-security.ts
function hashDeviceSecurityId(e) {
const t = e?.trim();
if (!t) return;
return `sha256:${sha256HexPrefixCore(t, 12)}`;
}
function emitDeviceManagementSecurityEvent(e) {
emitTrustedSecurityEvent({
category: "auth",
action: e.action,
outcome: e.outcome,
severity: e.severity,
actor: {
kind: "operator",
...e.authz.callerDeviceId ? { deviceIdHash: hashDeviceSecurityId(e.authz.callerDeviceId) } : {},
role: e.authz.isAdminCaller ? "admin" : "operator"
},
target: {
kind: "device",
...e.targetDeviceId ? { idHash: hashDeviceSecurityId(e.targetDeviceId) } : {}
},
policy: {
id: e.policyId,
decision: e.decision,
...e.reason ? { reason: e.reason } : {}
},
control: {
id: e.controlId,
family: "auth"
},
...e.reason ? { reason: e.reason } : {},
...e.attributes ? { attributes: e.attributes } : {}
});
}
//#endregion
export { requestsNonOperatorDeviceRole as a, pairedDeviceHasNonOperatorRole as i, deniesCrossDeviceManagement as n, resolveDeviceManagementAuthz as o, deniesDeviceTokenRoleManagement as r, resolveDeviceSessionAuthz as s, emitDeviceManagementSecurityEvent as t };