[grade=pending] QA sprint: commit 103 at-risk files from multi-agent sprint work

Committed by Hermes autonomous QA sprint 2026-08-13.
These files were modified during the Aug 12 sprint but never committed.
This commit is contained in:
Krystie
2026-08-12 17:34:10 -07:00
parent 0bf4406253
commit 503de258b8
105 changed files with 14057 additions and 2632 deletions
+46 -1
View File
@@ -1,9 +1,49 @@
const express = require('express');
const { DOCKER } = require('../src/utilities/constants');
const { paginate, parsePaginationParams } = require('../src/utilities/pagination');
const { NotFoundError } = require('../src/utilities/errors');
const { NotFoundError, ValidationError } = require('../src/utilities/errors');
const { success } = require('../src/utils/responses');
/**
* Validate a Docker container identifier (ID or name).
* Allows hex container IDs and Docker-compliant names.
* Blocks path traversal and shell metacharacters.
* @param {string} id - Container ID or name from route param
* @throws {ValidationError} if the ID is malformed
*/
function validateContainerId(id) {
if (!id || typeof id !== 'string') {
throw new ValidationError('Container ID is required');
}
// Docker names: [a-zA-Z0-9][a-zA-Z0-9_.-]*
// Docker IDs: 64-char hex — also matches the above pattern
// Max 128 chars covers IDs and names
if (!/^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,127}$/.test(id)) {
throw new ValidationError('Invalid container ID format');
}
}
/**
* Validate numeric resource limits for container update.
* @param {*} memory - Memory in MB (optional)
* @param {*} cpus - CPU count (optional)
* @throws {ValidationError} if values are out of range
*/
function validateResourceLimits(memory, cpus) {
if (memory !== undefined) {
const memNum = Number(memory);
if (isNaN(memNum) || memNum < 0 || memNum > 1048576) {
throw new ValidationError('Memory must be a number between 0 and 1048576 MB');
}
}
if (cpus !== undefined) {
const cpuNum = Number(cpus);
if (isNaN(cpuNum) || cpuNum < 0 || cpuNum > 1024) {
throw new ValidationError('CPUs must be a number between 0 and 1024');
}
}
}
/**
* Containers route factory
* @param {Object} deps - Explicit dependencies
@@ -18,6 +58,7 @@ module.exports = function({ docker, log, asyncHandler, workflowEngine }) {
// Helper: verify container exists before operating on it
async function getVerifiedContainer(id) {
validateContainerId(id);
const container = docker.client.getContainer(id);
try {
await container.inspect();
@@ -205,6 +246,10 @@ module.exports = function({ docker, log, asyncHandler, workflowEngine }) {
router.put('/:id/resources', asyncHandler(async (req, res) => {
const container = await getVerifiedContainer(req.params.id);
const { memory, cpus } = req.body;
// Validate resource limits before applying to Docker
validateResourceLimits(memory, cpus);
const updateConfig = {};
if (memory !== undefined) {