Skip to content

Commit 1d42b9a

Browse files
feat(routes): add ObjectId validation for application routes
1 parent 0c478bc commit 1d42b9a

2 files changed

Lines changed: 24 additions & 17 deletions

File tree

TODO

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,4 @@
22
[x] Architecture validation
33
[] Show environment
44
[] Live Status
5-
[] Node set for volumes
6-
[] API Server Uptime Graph
75
[] Plans page fixes
Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Application routes for managing user applications, deployments, logs, and metrics
2-
import { Router } from "express";
2+
import { Router, Request, Response, NextFunction } from "express";
33
import ensureAuthenticated from "../utils/auth/ensureAuthenticated";
44
import asyncHandler from "../utils/handlers/asyncHandler";
55

@@ -19,6 +19,16 @@ import scaleDeploymentZero from "../controllers/application/scaleDeploymentZero.
1919
import rolloutRestartDeployment from "../controllers/application/rolloutRestartDeployment.controller";
2020
import testImageAvailabilityController from "../controllers/application/testImageAvailability.controller";
2121

22+
const validateObjectId = (req: Request, res: Response, next: NextFunction) => {
23+
const id = req.params.id;
24+
25+
if (!/^[0-9a-fA-F]{24}$/.test(id)) {
26+
res.status(400).json({ message: "Invalid application ID format" });
27+
return;
28+
}
29+
next();
30+
};
31+
2232
const router = Router();
2333

2434
// All routes require authentication
@@ -28,32 +38,31 @@ router.use(ensureAuthenticated);
2838
router.post("/", createApplication);
2939
// Get all applications for the user
3040
router.get("/", getApplications);
31-
// Get a specific application by ID
32-
router.get("/:id", getApplication);
41+
// Get live status for all applications - must be before /:id route
42+
router.get("/status", getApplicationsStatus);
43+
// Get a specific application by ID (with ObjectId validation)
44+
router.get("/:id", validateObjectId, getApplication);
3345
// Update an application by ID
34-
router.put("/:id", updateApplication);
46+
router.put("/:id", validateObjectId, updateApplication);
3547
// Delete an application by ID
36-
router.delete("/:id", deleteApplication);
48+
router.delete("/:id", validateObjectId, deleteApplication);
3749
// Apply (deploy) an application
38-
router.post("/:id/apply", applyApplication);
50+
router.post("/:id/apply", validateObjectId, applyApplication);
3951
// Remove a deployment for an application
40-
router.post("/:id/remove-deployment", removeDeployment);
52+
router.post("/:id/remove-deployment", validateObjectId, removeDeployment);
4153
// Scale deployment to 0 replicas
42-
router.post("/:id/scale-zero", scaleDeploymentZero);
54+
router.post("/:id/scale-zero", validateObjectId, scaleDeploymentZero);
4355
// Rollout restart deployment
44-
router.post("/:id/rollout-restart", rolloutRestartDeployment);
56+
router.post("/:id/rollout-restart", validateObjectId, rolloutRestartDeployment);
4557
// Remove a namespace for an application
46-
router.post("/:id/remove-namespace", removeNamespace);
58+
router.post("/:id/remove-namespace", validateObjectId, removeNamespace);
4759
// Stream logs for an application
48-
router.get("/:id/logs", streamApplicationLogs);
60+
router.get("/:id/logs", validateObjectId, streamApplicationLogs);
4961
// Get metrics for an application
50-
router.get("/:id/metrics", getApplicationMetrics);
62+
router.get("/:id/metrics", validateObjectId, getApplicationMetrics);
5163
// Test Docker image availability
5264
router.post("/test-image", testImageAvailabilityController);
5365
// Run a Docker handler (async)
5466
router.post("/run-docker", asyncHandler(runDockerHandler));
5567

56-
// Get live status for all applications
57-
router.get("/status", getApplicationsStatus);
58-
5968
export default router;

0 commit comments

Comments
 (0)