Reapply "feat(security): enforce service-level access on docker WebSocket handlers"

This reverts commit 56169f3278.
This commit is contained in:
Mauricio Siu
2026-07-20 00:35:40 -06:00
parent 56169f3278
commit 1bc76e9e5b
14 changed files with 51 additions and 4 deletions

View File

@@ -1,5 +1,6 @@
import { getAccessibleServerIds } from "@dokploy/server";
import {
checkServiceAccess,
findMemberByUserId,
hasPermission,
} from "@dokploy/server/services/permission";
@@ -22,6 +23,7 @@ export const canAccessDockerOverWss = async (
user: WssUser,
session: WssSession,
serverId?: string | null,
serviceId?: string | null,
): Promise<boolean> => {
if (!user || !session?.activeOrganizationId) return false;
@@ -36,6 +38,18 @@ export const canAccessDockerOverWss = async (
if (!accessible.has(serverId)) return false;
}
// When the container belongs to a known Dokploy service (opened from a
// service page), enforce service-level access too. Container terminals
// opened from the generic Docker overview have no serviceId and fall back to
// the docker-permission + server checks above.
if (serviceId) {
try {
await checkServiceAccess(ctx, serviceId, "read");
} catch {
return false;
}
}
return true;
};