mirror of
https://github.com/Studio-Saelix/sencho.git
synced 2026-08-12 11:47:11 +00:00
fix: harden docker api validation, handle sftp errors, and fix node manager ui
This commit is contained in:
@@ -29,6 +29,14 @@ class DockerController {
|
||||
return this.docker;
|
||||
}
|
||||
|
||||
private validateApiData<T>(data: any): T {
|
||||
// If the daemon port points to a web server (like Sencho UI), Dockerode receives HTML
|
||||
if (typeof data === 'string') {
|
||||
throw new Error("Invalid response from Docker API. Did you provide a web port instead of the Docker daemon port?");
|
||||
}
|
||||
return data as T;
|
||||
}
|
||||
|
||||
public async getDiskUsage() {
|
||||
const df = await this.docker.df();
|
||||
|
||||
@@ -89,16 +97,19 @@ class DockerController {
|
||||
}
|
||||
|
||||
public async getImages() {
|
||||
return await this.docker.listImages({ all: false });
|
||||
const data = await this.docker.listImages({ all: false });
|
||||
return this.validateApiData<any[]>(data);
|
||||
}
|
||||
|
||||
public async getVolumes() {
|
||||
const data = await this.docker.listVolumes();
|
||||
return data.Volumes || [];
|
||||
const validated = this.validateApiData<any>(data);
|
||||
return validated.Volumes || [];
|
||||
}
|
||||
|
||||
public async getNetworks() {
|
||||
return await this.docker.listNetworks();
|
||||
const data = await this.docker.listNetworks();
|
||||
return this.validateApiData<any[]>(data);
|
||||
}
|
||||
|
||||
public async removeImage(id: string) {
|
||||
@@ -118,12 +129,12 @@ class DockerController {
|
||||
|
||||
public async getRunningContainers() {
|
||||
const containers = await this.docker.listContainers({ all: false });
|
||||
return containers;
|
||||
return this.validateApiData<any[]>(containers);
|
||||
}
|
||||
|
||||
public async getAllContainers() {
|
||||
const containers = await this.docker.listContainers({ all: true });
|
||||
return containers;
|
||||
return this.validateApiData<any[]>(containers);
|
||||
}
|
||||
|
||||
public async getContainersByStack(stackName: string) {
|
||||
|
||||
@@ -86,8 +86,9 @@ export class FileSystemService {
|
||||
}
|
||||
|
||||
return stackNames;
|
||||
} catch (error) {
|
||||
console.error('Error reading stacks:', error);
|
||||
} catch (error: any) {
|
||||
const nodeName = NodeRegistry.getInstance().getNode(this.nodeId)?.name || 'Unknown';
|
||||
console.warn(`[SFTP] Failed to fetch stacks for Node ${nodeName}: ${error.message || error}`);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,6 +112,12 @@ export class NodeRegistry {
|
||||
try {
|
||||
const docker = this.createDockerClient(node);
|
||||
const info = await docker.info();
|
||||
|
||||
// Validate the payload contains actual Docker daemon info, not arbitrary HTML
|
||||
if (!info || !info.OperatingSystem || typeof info.Containers !== 'number') {
|
||||
throw new Error("Invalid response from Docker API. Did you provide a web port instead of the Docker daemon port?");
|
||||
}
|
||||
|
||||
db.updateNodeStatus(nodeId, 'online');
|
||||
return {
|
||||
success: true,
|
||||
|
||||
Reference in New Issue
Block a user