Add port validation to database external ports

Co-authored-by: Siumauricio <[email protected]>
This commit is contained in:
copilot-swe-agent[bot]
2026-02-05 05:52:38 +00:00
co-authored by Siumauricio
parent 999dc7d360
commit 139c06b63d
5 changed files with 75 additions and 0 deletions
@@ -1,5 +1,6 @@
import { import {
addNewService, addNewService,
checkPortInUse,
checkServiceAccess, checkServiceAccess,
createMariadb, createMariadb,
createMount, createMount,
@@ -172,6 +173,20 @@ export const mariadbRouter = createTRPCRouter({
message: "You are not authorized to save this external port", message: "You are not authorized to save this external port",
}); });
} }
if (input.externalPort) {
const portCheck = await checkPortInUse(
input.externalPort,
mongo.serverId || undefined,
);
if (portCheck.isInUse) {
throw new TRPCError({
code: "CONFLICT",
message: `Port ${input.externalPort} is already in use by ${portCheck.conflictingContainer}`,
});
}
}
await updateMariadbById(input.mariadbId, { await updateMariadbById(input.mariadbId, {
externalPort: input.externalPort, externalPort: input.externalPort,
}); });
+15
View File
@@ -1,5 +1,6 @@
import { import {
addNewService, addNewService,
checkPortInUse,
checkServiceAccess, checkServiceAccess,
createMongo, createMongo,
createMount, createMount,
@@ -189,6 +190,20 @@ export const mongoRouter = createTRPCRouter({
message: "You are not authorized to save this external port", message: "You are not authorized to save this external port",
}); });
} }
if (input.externalPort) {
const portCheck = await checkPortInUse(
input.externalPort,
mongo.serverId || undefined,
);
if (portCheck.isInUse) {
throw new TRPCError({
code: "CONFLICT",
message: `Port ${input.externalPort} is already in use by ${portCheck.conflictingContainer}`,
});
}
}
await updateMongoById(input.mongoId, { await updateMongoById(input.mongoId, {
externalPort: input.externalPort, externalPort: input.externalPort,
}); });
+15
View File
@@ -1,5 +1,6 @@
import { import {
addNewService, addNewService,
checkPortInUse,
checkServiceAccess, checkServiceAccess,
createMount, createMount,
createMysql, createMysql,
@@ -187,6 +188,20 @@ export const mysqlRouter = createTRPCRouter({
message: "You are not authorized to save this external port", message: "You are not authorized to save this external port",
}); });
} }
if (input.externalPort) {
const portCheck = await checkPortInUse(
input.externalPort,
mongo.serverId || undefined,
);
if (portCheck.isInUse) {
throw new TRPCError({
code: "CONFLICT",
message: `Port ${input.externalPort} is already in use by ${portCheck.conflictingContainer}`,
});
}
}
await updateMySqlById(input.mysqlId, { await updateMySqlById(input.mysqlId, {
externalPort: input.externalPort, externalPort: input.externalPort,
}); });
@@ -1,5 +1,6 @@
import { import {
addNewService, addNewService,
checkPortInUse,
checkServiceAccess, checkServiceAccess,
createMount, createMount,
createPostgres, createPostgres,
@@ -192,6 +193,20 @@ export const postgresRouter = createTRPCRouter({
message: "You are not authorized to save this external port", message: "You are not authorized to save this external port",
}); });
} }
if (input.externalPort) {
const portCheck = await checkPortInUse(
input.externalPort,
postgres.serverId || undefined,
);
if (portCheck.isInUse) {
throw new TRPCError({
code: "CONFLICT",
message: `Port ${input.externalPort} is already in use by ${portCheck.conflictingContainer}`,
});
}
}
await updatePostgresById(input.postgresId, { await updatePostgresById(input.postgresId, {
externalPort: input.externalPort, externalPort: input.externalPort,
}); });
+15
View File
@@ -1,5 +1,6 @@
import { import {
addNewService, addNewService,
checkPortInUse,
checkServiceAccess, checkServiceAccess,
createMount, createMount,
createRedis, createRedis,
@@ -211,6 +212,20 @@ export const redisRouter = createTRPCRouter({
message: "You are not authorized to save this external port", message: "You are not authorized to save this external port",
}); });
} }
if (input.externalPort) {
const portCheck = await checkPortInUse(
input.externalPort,
mongo.serverId || undefined,
);
if (portCheck.isInUse) {
throw new TRPCError({
code: "CONFLICT",
message: `Port ${input.externalPort} is already in use by ${portCheck.conflictingContainer}`,
});
}
}
await updateRedisById(input.redisId, { await updateRedisById(input.redisId, {
externalPort: input.externalPort, externalPort: input.externalPort,
}); });