DEV Community

Cover image for Prompt injection is an authorization bug

Prompt injection is an authorization bug

Shubham on November 22, 2026

Summary Prompt injection is usually described as a model believing malicious text. That framing leads to input filters. The filters miss...
Collapse
 
paul_irolla_6b5ae261d0224 profile image
Paul Irolla •

A rule in a system prompt is one the model can be talked out of. Put the check on the write path, in code, so the answer is allow or deny before anything leaves, whatever the page or the tool result said.

Collapse
 
shubham399 profile image
Shubham •

Agreed, and the ordering matters. The check has to run after argument validation and before the side effect, so a malformed call cannot skip it and a retry cannot slip past it. A prompt rule is a suggestion. The write path is the boundary. I also log the deny, because a blocked call is the signal that someone is trying.

Collapse
 
zahurul profile image
Zahurul Islam •

The confused-deputy framing is the right one. A practical consequence for multi-agent setups is that the principal has to travel with the task. When an orchestrator hands work to a sub-agent, the tool call that sub-agent makes should still carry "on behalf of user X, approved scope Y". Otherwise the sub-agent's token becomes the authority. Enforcing that at the tool boundary, as you say, also makes the audit log readable: every side effect traces back to a person and an approval, not just to "the agent".

Collapse
 
shubham399 profile image
Shubham •

Agreed. The token should carry both actor and subject. The actor is the agent instance, the subject is the person it serves. Policy checks the subject, and the log records both. If the sub-agent only carries its own token, the sub-agent becomes the authority, which is the same confused-deputy bug one layer down. The audit line you describe is the payoff. Every side effect traces to a person and an approval, not to 'the agent'.

Collapse
 
zahurul profile image
Zahurul Islam •

Actor plus subject is the cleaner way to put it, thanks. One thing I'd add: the subject's approved scope should only ever shrink as the task is handed down. A sub-agent can narrow 'on behalf of X, scope Y' but never widen it, so a prompt-injected sub-agent can't promote itself. And logging both is what makes the audit question answerable later: who asked, which agent acted, under which approval.

Thread Thread
 
shubham399 profile image
Shubham •

The subject's scope should only shrink as the task passes down. A sub-agent can narrow the scope but never widen it, so a prompt-injected sub-agent cannot promote itself. Log who asked, which agent acted, and under which approval. That keeps the audit question answerable later.

Collapse
 
anna_p_s profile image
Anna •

Hi @shubham399! I agree with @zahurul that the principal has to travel with the task, and 1 thing I’d add:

At the tool, the check has 2 sets of rights to look at, the agent’s own scope and the current rights of the person it’s acting for, and the action goes through only if both allow it. A sub-agent that only drafts replies shouldn’t be able to send one just because its user can.

On the send_refund example, the approval lookup and the amount cap sit inside the tool handler. That’s fine for 1 tool, but with many tools and agents the same rules get copied and drift apart. Pull them into 1 place every tool calls, a shared function or a policy service (I work at Cerbos, we’re an authorization platform, and that per-call check is what we do). Then “no refund above the approved amount” is written once and tested as the table of cases you describe. The approval record itself still lives in your app, the policy holds the rule for what it allows.

Thanks for the write-up, the sheriff and deputy line is going straight into how I explain this :)

Collapse
 
shubham399 profile image
Shubham •

The intersection is the right default. Both the agent's scope and the person's current rights have to allow the call. The part I would keep in the app is the approval record and the amount cap tied to it, because that is state, not policy. The policy service answers whether this principal may do this action now. The app answers whether a human approved this exact amount, and the answer lives in a row with an expiry.

Collapse
 
robertpaschal profile image
Odinaka Robert Nnamani •

The run_report line is the one I would steal. A friendly tool name does not shrink the capability underneath it.

Collapse
 
shubham399 profile image
Shubham •

Right, and the hat is the problem. A report tool should take a report id and typed parameters, not SQL. The server owns the query, the model picks from a fixed list, and an injection can at most ask for a report the principal is allowed to see. If it accepts SQL, rename it to execute_sql and treat it like a shell.

Collapse
 
aiwhatson profile image
AI What's On •

Treating each tool call as a privileged action with scoped credentials is a useful frame. Do you see human approval being needed for every call, or only for destructive ones?

Collapse
 
shubham399 profile image
Shubham •

Only where the action is hard to undo or moves money. Reads and reversible writes can run without a human if the scope is narrow. The test I use is whether a wrong call can be undone by another call. If it cannot, it needs approval. If it can, the schema and the scope should carry the safety instead of a person.

Collapse
 
parasraju profile image
Paras •

The run_shell line really landed for me.

Collapse
 
shubham399 profile image
Shubham •

Glad it landed. That line is the cheapest test I know. If the tool name is a verb like run_shell or execute_sql, the injected text does not need to be clever. It only needs to reach the arguments. The fix is to replace the capability with a task, so the tool can do one thing and the model cannot ask it for a general shell.