fix(security): prevent command injection in stopContainer and mount path injection
**stopContainer (container-runtime.ts):** - Validate container name against `^[a-zA-Z0-9][a-zA-Z0-9_.-]*$` before passing to shell command. Rejects names with shell metacharacters (`;`, `$()`, backticks, etc.) that could execute arbitrary commands. - Changed return type from string to void — callers no longer build shell commands from the return value. **mount-security.ts:** - Reject container paths containing `:` to prevent Docker `-v` option injection (e.g., `repo:rw` could override readonly flags). - Don't permanently cache "file not found" for mount allowlist — the file may be created later without requiring a service restart. Only parse/structural errors are permanently cached. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -63,7 +63,8 @@ export function loadMountAllowlist(): MountAllowlist | null {
|
||||
|
||||
try {
|
||||
if (!fs.existsSync(MOUNT_ALLOWLIST_PATH)) {
|
||||
allowlistLoadError = `Mount allowlist not found at ${MOUNT_ALLOWLIST_PATH}`;
|
||||
// Do NOT cache this as an error — file may be created later without restart.
|
||||
// Only parse/structural errors are permanently cached.
|
||||
logger.warn(
|
||||
{ path: MOUNT_ALLOWLIST_PATH },
|
||||
'Mount allowlist not found - additional mounts will be BLOCKED. ' +
|
||||
@@ -215,6 +216,11 @@ function isValidContainerPath(containerPath: string): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Must not contain colons — prevents Docker -v option injection (e.g., "repo:rw")
|
||||
if (containerPath.includes(':')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user