refactor(sandbox): centralize network mode policy helpers

This commit is contained in:
Peter Steinberger
2026-02-24 23:26:46 +00:00
parent 14b6eea6e3
commit 5552f9073f
7 changed files with 78 additions and 19 deletions

View File

@@ -0,0 +1,28 @@
export type NetworkModeBlockReason = "host" | "container_namespace_join";
export function normalizeNetworkMode(network: string | undefined): string | undefined {
const normalized = network?.trim().toLowerCase();
return normalized || undefined;
}
export function getBlockedNetworkModeReason(params: {
network: string | undefined;
allowContainerNamespaceJoin?: boolean;
}): NetworkModeBlockReason | null {
const normalized = normalizeNetworkMode(params.network);
if (!normalized) {
return null;
}
if (normalized === "host") {
return "host";
}
if (normalized.startsWith("container:") && params.allowContainerNamespaceJoin !== true) {
return "container_namespace_join";
}
return null;
}
export function isDangerousNetworkMode(network: string | undefined): boolean {
const normalized = normalizeNetworkMode(network);
return normalized === "host" || normalized?.startsWith("container:") === true;
}