fix(security): harden Milady Docker provisioning against env injection#400
fix(security): harden Milady Docker provisioning against env injection#400
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR Review — fix(security): harden Milady Docker provisioning against env injectionThe core security improvement (centralized uppercase-only key validation + control-character rejection) is sound and worthwhile. Several issues should be addressed before merging. Bugs / Correctness1. Duplicate validation in
const containerName = getContainerName(agentId); // already validates internally
const volumePath = getVolumePath(agentId); // already validates internally
validateContainerName(containerName); // duplicate — remove
validateVolumePath(volumePath); // duplicate — remove2.
// Current — hard to diagnose in production:
throw new Error(`Invalid environment variable value: contains control characters.`);
// Better:
throw new Error(`Invalid environment variable value for key "${key}": contains control characters (newlines and PEM-encoded values are not supported).`);3.
Security4.
Design5. Validation inside factory functions breaks the cleanup path
6. Removed comment was architecturally informative The removed comment block (explaining why Test Coverage Gaps
Nits
Summary
Actionable before merge:
|
Code ReviewOverall this is a solid, well-scoped security hardening PR. The security intent is sound and the implementation is clean. A few issues worth addressing before merging: Bug: Container name length cap is inconsistent with
|
Code ReviewOverall this is a solid security hardening PR — the defense-in-depth approach (validate inputs, then validate derived outputs) is the right call, and the test coverage is good. One real bug and a few smaller items below. Bug: JS
|
Code ReviewOverall this is a well-structured security hardening PR with clear intent and good test coverage. A few issues worth addressing before merge. Bugs / Correctness1. // docker-sandbox-utils.ts:107
if (hasControlChars(containerName) || !/^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,127}$/.test(containerName)) {The character class 2. Silent max-length reduction for
3.
However, Security4. // docker-sandbox-provider.ts:334
shellQuote(resolvedImage),Docker image names with 5. Validation placement in The double-validation (calling Test Coverage Gaps6. Missing edge case: empty string env key
7. Missing edge case: root path
test("rejects root path", () => {
expect(() => validateVolumePath("/")).toThrow(/Invalid volume path/);
});8. The PR description lists Nits
SummaryThe core security fix is correct and well-implemented. The centralized helpers, test coverage, and defense-in-depth double-validation are all solid. The two items I'd prioritize before merge:
The redundant |
Summary
This PR hardens the Milady Docker provisioning path against command injection in the remote
docker runflow.Security impact
This addresses a critical authenticated RCE risk in provisioning: user-controlled environment variables were being assembled into a remote shell command for
docker run. While values were shell-quoted, validation was incomplete and the provisioning path still relied on shell interpolation for multiple user-derived fields.Changes
^[A-Z_][A-Z0-9_]*$docker-sandbox-providerwith centralized helpersNotes
Validation
bun test packages/tests/unit/docker-infrastructure.test.tsbun test packages/tests/unit/milady-create-routes.test.tscodex review --uncommitted(flagged the tighter env validation as behavior-changing; retained intentionally for security hardening)Risk
High security value, low code-surface change. Main behavior change is stricter validation of user-supplied env vars during Docker provisioning.