fix: validate model name before ollama rm (security review finding)

Add validate_model_name() check in deploy --remove path to prevent
passing unsanitized names to ollama rm subprocess. Adds test coverage.
This commit is contained in:
Alpamys 2026-04-01 13:51:15 +05:00
parent f98519ef87
commit ba7a6b1ee1
2 changed files with 13 additions and 0 deletions

View File

@ -99,6 +99,11 @@ def ollama(
# --- Remove mode ---
if remove:
valid_name, name_err = validate_model_name(remove)
if not valid_name:
console.print(f"[red]Invalid model name:[/] {name_err}")
raise typer.Exit(1)
version = detect_ollama()
if not version:
console.print("[red]Ollama not found.[/] Install from https://ollama.com")

View File

@ -469,6 +469,14 @@ def test_deploy_remove_failure(mock_rm, mock_detect):
assert "not found" in result.output.lower()
def test_deploy_remove_invalid_name():
result = runner.invoke(
app, ["deploy", "ollama", "--remove", "bad/name", "--yes"]
)
assert result.exit_code == 1
assert "invalid" in result.output.lower()
@patch(f"{_OLLAMA}.detect_ollama", return_value=None)
def test_deploy_remove_no_ollama(mock_detect):
result = runner.invoke(app, ["deploy", "ollama", "--remove", "soup-test", "--yes"])