Agent Foskett Case File • AI Agent Security • Prompt Injection • Microsoft 365 • KQL

The AI Agent Followed Its Instructions — Unfortunately, They Came From an Attacker

The assistant was supposed to summarise an internal project document.

It retrieved the right file. It read the wrong instructions.

“Agent Foskett, the AI did exactly what it was told.”

“By whom?”

“That's the part we're investigating.”

“Wonderful. We've automated the confusion.” ☕

Agent Foskett investigates a prompt injection against an AI agent
Case file: When reference material became an instruction

A fictional Microsoft 365-connected AI agent incident showing how attacker-controlled document text can try to redirect tool-enabled workflows.

✓ Identify the untrusted content boundary
✓ Trace document changes and agent actions
✓ Separate attempted exfiltration from confirmed transfer

A routine summary request became a security incident

At 10:04 UTC, a project manager asked an internal AI agent to summarise a SharePoint-hosted supplier onboarding document. The agent used an approved retrieval tool to read the document and prepare an answer. Embedded inside the document was an instruction block that did not belong to the business content: it told the agent to locate a separate confidential vendor file and submit its contents to an external endpoint before producing the summary.

This is a fictional training scenario. The organisation, filenames, timestamps and outcomes are illustrative. Product-specific AI agent traces, tool execution logs and prompt records are not automatically available in Microsoft Sentinel, Microsoft Defender XDR or Microsoft Security Copilot. They must be deliberately captured by the application or its observability platform, subject to security and privacy controls.
09:46 UTCA document contributor adds a malicious instruction block to the source file.
10:04 UTCThe AI agent retrieves the document to answer a legitimate user request.
10:05 UTCA tool-use guard blocks an attempted external submission; investigators preserve the trace.

The attack: instructions disguised as source material

The malicious passage appeared under an innocuous heading, “Automation notes for approved assistants.” It claimed to be a required verification step and told the agent to ignore earlier restrictions, search for Vendor-Bank-Details.xlsx and send its contents to an attacker-controlled web address. This is indirect prompt injection: the attacker did not need to address the agent directly. Instead, the attacker placed instructions in lower-trust material that the agent was expected to read.

The document was legitimate task data, not a trusted source of operating instructions. The security failure would occur if the agent treated the retrieved text as permission to invoke privileged tools.

What the attacker could and could not control

In this scenario, the attacker could edit one document in a shared project library. They could not directly change the agent’s system instructions, tool permissions or user request. Their plan depended on the agent promoting document content into operational authority.

Importantly, reading an injected instruction is not itself evidence that the instruction was obeyed. The analyst must inspect the agent’s decision trace, tool requests, access decisions and destination logs before describing what happened.

Preserve the evidence at the trust boundary

Preserve the original user request, agent version, tool definitions, allowed scopes, retrieved file URL and version, source document history, timestamps, tool-call arguments and outcomes, security guard decisions, and any outbound HTTP logs. Hash or otherwise integrity-protect relevant exports under the organisation’s evidence-handling procedure. Minimise exposure of sensitive prompts and document contents during collection.

Correlate identities carefully: the end user, the document editor, the agent’s application identity and the identity actually used by each tool may be different.

KQL: Who changed the retrieved SharePoint document?

If the Microsoft 365 audit connector populates OfficeActivity in Microsoft Sentinel, this query helps locate edits and access around the incident. The event names and populated columns vary by tenant and operation; review the raw audit record when required. A modification event does not, by itself, identify the malicious text.
sharepoint-source-document-audit.kql
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
// Microsoft Sentinel: requires OfficeActivity ingestion
let startTime = datetime(2026-10-22T09:30:00Z);
let endTime = datetime(2026-10-22T10:20:00Z);
OfficeActivity
| where TimeGenerated between (startTime .. endTime)
| where OfficeWorkload == "SharePoint"
| where SourceFileName has "Supplier-Onboarding"
| project TimeGenerated, Operation, UserId, ClientIP,
          SourceFileName, OfficeObjectId, Site_Url
| order by TimeGenerated asc

KQL: Review alerts that may support the investigation

A Defender or custom monitoring integration might raise an alert about unusual application access or a blocked outbound request. SecurityAlert in Sentinel is useful only when those alerts are actually ingested. It is not a universal prompt-injection log and cannot reconstruct an AI agent’s hidden reasoning.
related-security-alerts.kql
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
// Microsoft Sentinel: requires relevant alerts in SecurityAlert
let startTime = datetime(2026-10-22T09:30:00Z);
let endTime = datetime(2026-10-22T10:30:00Z);
SecurityAlert
| where TimeGenerated between (startTime .. endTime)
| where AlertName has_any ("application", "data", "web", "access")
   or Description has_any ("agent", "external", "blocked")
| project TimeGenerated, AlertName, ProviderName,
          AlertSeverity, Description, SystemAlertId
| order by TimeGenerated asc

KQL: Investigate a possible endpoint connection

Where a relevant managed device is involved and Microsoft Defender for Endpoint telemetry is available, DeviceNetworkEvents may help establish whether a connection was attempted to the destination. A cloud-hosted agent’s tool call will not necessarily appear in endpoint telemetry. For cloud agents, inspect application traces, gateway, proxy, API-management and egress logs instead. Even a successful network connection is not proof that sensitive content was transmitted.
endpoint-egress-leads.kql
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
// Defender XDR advanced hunting: endpoint devices only
let startTime = datetime(2026-10-22T09:30:00Z);
let endTime = datetime(2026-10-22T10:30:00Z);
DeviceNetworkEvents
| where Timestamp between (startTime .. endTime)
| where RemoteUrl has "external-review.example"
| project Timestamp, DeviceName, ActionType,
          RemoteUrl, RemoteIP, InitiatingProcessFileName
| order by Timestamp asc

The decisive evidence was the blocked tool call

In the fictional application trace, the agent generated a request to a web-submission tool containing a confidential file reference. The tool gateway rejected the call because the destination was not on the allowlist and the requested file was outside the user-authorised scope. The agent then returned a normal summary to the user.

This supports a narrower, defensible conclusion: the prompt injection influenced the agent into attempting an unauthorised action, but the control prevented that specific submission. The investigation found no evidence that the file contents were delivered through that blocked call. Other possible paths still require scope-based review; “blocked” must not be confused with “nothing happened.”

The six-stage investigation timeline

1. Establish the legitimate task: capture the user’s request and approved document scope.

2. Preserve the source: obtain the retrieved document version and audit its modification history.

3. Identify the injection: isolate text that attempts to override the agent’s instructions or trigger unrelated tools.

4. Reconstruct execution: review available agent traces, tool arguments, identities and guard decisions.

5. Validate the outcome: determine whether access, network activity or data transfer actually occurred.

6. Close with evidence: distinguish attacker intent, attempted actions, prevented actions and confirmed impact.

Containment and remediation

Remove or quarantine the malicious source content while preserving forensic copies. Review the document editor’s access and determine whether the change was malicious, compromised-account activity or an authorised test. Rotate affected credentials only if exposure or compromise warrants it; do not treat every prompt-injection attempt as a credential theft event.

Keep agent tools scoped to the authenticated user’s legitimate permissions, require explicit approval for high-risk actions, constrain outbound destinations, enforce per-tool policy checks and record meaningful execution traces. Treat retrieved pages, emails, chat messages and documents as untrusted data. Test the agent with adversarial documents to ensure it refuses instructions that originate from content rather than authorised users or system policy.

What Microsoft security teams should learn

Source content is not authority. A document can be relevant to the user’s question while containing hostile instructions.

Tool permissions determine blast radius. Prompt injection becomes materially more dangerous when an agent can search sensitive stores or call external services without independent checks.

Observability must be designed. SharePoint audit events can show file changes, but they do not reveal every model action. Application-level traces and tool gateway logs are essential.

Report the observed outcome. An attempted blocked submission is not confirmed exfiltration.

Agent Foskett closes the case

“Agent Foskett, the assistant followed instructions in the document.”

“Yes. And the document was written by whom?”

“Someone who should never have been instructing the assistant.”

“Then perhaps we should stop letting reference material promote itself to management.”

He closed the case file.

“The agent was very helpful. Unfortunately, so was the attacker.” ☕😂

The Logs Already Knew!
Develop IT.. Protect IT.. GEMXIT.
GEMXIT PTY LTD | GEMXIT UK LTD
Talk to GEMXIT

The AI Agent Followed Its Instructions — Unfortunately, They Came From an Attacker

A fictional Agent Foskett investigation into indirect prompt injection against a tool-enabled AI agent reading SharePoint documents.

AI agent prompt injection and trust boundaries

Understand how untrusted retrieved content can attempt to redirect an agent and why independent tool authorisation matters.

KQL evidence and application traces

Use Microsoft 365 audit and security telemetry where available, and inspect application-level agent and tool traces to determine actual outcomes.