Skip to content

fix: prevent command injection in init container shell commands#172

Merged
Defilan merged 1 commit intomainfrom
fix/init-command-injection
Feb 22, 2026
Merged

fix: prevent command injection in init container shell commands#172
Defilan merged 1 commit intomainfrom
fix/init-command-injection

Conversation

@Defilan
Copy link
Member

@Defilan Defilan commented Feb 22, 2026

Summary

Relates to #91

  • Refactored buildModelInitCommand to eliminate fmt.Sprintf interpolation of user-controlled values (model source, cache dir, model path) into shell commands
  • User-controlled values are now passed as container environment variables (MODEL_SOURCE, CACHE_DIR, MODEL_PATH) and referenced via $VAR in the shell script
  • Added modelInitEnvVars helper to build the env var list for init containers
  • Updated buildCachedStorageConfig and buildEmptyDirStorageConfig to set Env on the init container

This prevents shell metacharacter injection from CRD inputs like https://evil.com/$(cmd).gguf — the source value never appears in the shell command string, only in Kubernetes env vars which are set literally by the kubelet.

Test plan

  • Updated buildModelInitCommand tests for new (isLocal, useCache bool) signature
  • Added command injection safety test verifying malicious source doesn't appear in shell command
  • Updated buildCachedStorageConfig / buildEmptyDirStorageConfig tests to assert Env vars on init containers
  • go build ./... — compiles cleanly
  • go vet ./internal/controller/... — no issues
  • go test ./internal/controller/... -count=1 — all 128 tests pass

Signed-off-by: Christopher Maher chris@mahercode.io

Replace fmt.Sprintf interpolation of user-controlled values (model source,
cache dir, model path) in buildModelInitCommand with container environment
variables. The shell script now references $MODEL_SOURCE, $CACHE_DIR, and
$MODEL_PATH instead of embedding raw values, eliminating shell metacharacter
injection risk from CRD inputs.

Signed-off-by: Christopher Maher <chris@mahercode.io>
@Defilan Defilan merged commit 3aa9cc3 into main Feb 22, 2026
15 checks passed
@Defilan Defilan deleted the fix/init-command-injection branch February 22, 2026 09:12
@github-actions github-actions bot mentioned this pull request Feb 22, 2026
@github-actions github-actions bot mentioned this pull request Mar 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant