Microsoft has formally shifted the conversation on AI security from theoretical risk to operational reality. In a newly published security framework, the company urges organizations to treat AI agents — autonomous software entities that reason, plan, and act on behalf of users and systems — as insider threats. Not potential future risks. Not edge cases. Insider threats, today, requiring the same rigor we apply to privileged human accounts.
This framing matters. AI agents are being deployed across enterprise environments at a pace that far exceeds the maturity of the controls governing them. Agents authenticate, hold credentials or tokens, call APIs, read and write data, execute code, and increasingly chain actions across SaaS platforms with little or no human-in-the-loop approval. Unlike traditional service accounts, they are non-deterministic: the same agent with the same permissions can behave differently depending on its inputs, its model version, or a prompt injection it ingested from a poisoned document or web page.
From where I sit — having led IR engagements where over-privileged service principals and unmanaged non-human identities were the pivot point into production — Microsoft's guidance lands on something practitioners have known for a while: the fastest-growing population of privileged identities in your environment is not human, and almost nobody is watching it. This post breaks down the framework, what it means operationally, and how to build detection and containment capability around AI agents in a Microsoft-centric environment.
Technical Analysis
What Microsoft Is Actually Saying
The framework, published on Microsoft's official security blog, is built on three pillars:
- Dynamic permissions — Move away from standing, static privileges for agents. Access should be granted just-in-time, scoped to the specific task, and automatically revoked when the task completes. This mirrors Just Enough Administration (JEA) and Privileged Identity Management (PIM) concepts that mature organizations already apply to human admins.
- Continuous risk monitoring — Agents must be evaluated continuously, not at provisioning time. Behavior that deviates from baseline — unusual API call patterns, access to data outside the agent's functional scope, execution at odd hours, novel tool invocation — should drive risk scoring and automated response.
- Automated containment — When an agent's risk score crosses a threshold, response cannot wait for a human analyst to review a queue. Containment — token revocation, session termination, workload isolation — must be automatic.
Microsoft's position is that AI agents are not dangerous by nature, but their combination of autonomy, privilege, and non-determinism makes them structurally similar to an insider with broad access and unpredictable judgment. The defensive model that applies is the same one we use for insider risk: least privilege, behavioral analytics, and rapid containment.
Why This Is a Real Threat, Not a Thought Experiment
There is no CVE here, and no single exploit. The risk surface is architectural. In our incident response work over the past 18 months, the recurring patterns around AI/agent-style automation identities look like this:
- Over-provisioned agent identities. Developers register an application in Microsoft Entra ID, grant it
Mail.Read,Files.ReadWrite.All, orSites.FullControl.Allon Microsoft Graph "just to make it work," and nobody ever scopes it down. That identity is now a standing credential with tenant-wide data access. - Prompt injection as a privilege escalation primitive. An agent with read access to email or documents and write/execute capability elsewhere can be manipulated via crafted content — a malicious email, a poisoned SharePoint page, a weaponized web result — into taking attacker-directed actions using its legitimate permissions. No malware, no exploit, no EDR alert. This is why the insider-threat framing is apt: the attack abuses trust and authorization, not software flaws.
- Orphaned and shadow agents. Business units deploy copilots and automation without security review. These identities accumulate OAuth grants, persist for months after the project ends, and never appear in access reviews because reviewers don't recognize them.
- Token theft and replay. Agent credentials (client secrets, certificates, refresh tokens) stored in configuration files, environment variables, or code repositories are harvested and replayed from attacker infrastructure — often from IP space the SOC has never seen authenticate before.
Affected Platforms and Scope
This guidance applies to any organization running:
- Microsoft 365 Copilot and Copilot Studio agents (custom agents with connectors and actions)
- Azure AI Foundry / Azure OpenAI-based agent workloads
- Microsoft Entra-registered applications and service principals backing agentic automation
- Third-party or open-source agent frameworks (LangChain, AutoGen, Semantic Kernel, CrewAI) that authenticate to Microsoft or other SaaS APIs using app registrations
Exploitation status: there is no single vulnerability to patch. Prompt injection and excessive agent privilege are actively abused techniques in the wild, and security researchers have repeatedly demonstrated data exfiltration via indirect prompt injection against production copilot-style deployments. Treat this as a current, architectural exposure — not a theoretical one.
Detection & Response
The detections below target the observable behaviors that matter: creation or modification of high-privilege agent identities, anomalous agent execution patterns on endpoints, and OAuth grant abuse. They are written for environments where agents authenticate through Entra ID and run on managed endpoints.
Sigma Rules
---
title: AI Agent or Automation Spawning Interactive Shell
description: Detects known AI agent runtimes and automation hosts spawning interactive command shells — a common post-prompt-injection or token-abuse behavior when an agent is manipulated into executing attacker commands.
references:
- https://attack.mitre.org/techniques/T1059/
author: Security Arsenal
date: 2026/04/10
tags:
- attack.execution
- attack.t1059
logsource:
category: process_creation
product: windows
detection:
selection_parent:
ParentImage|endswith:
- '\python.exe'
- '\pythonw.exe'
- '\node.exe'
- '\pwsh.exe'
selection_child:
Image|endswith:
- '\cmd.exe'
- '\powershell.exe'
- '\whoami.exe'
- '\net.exe'
- '\nltest.exe'
filter_known_agent_paths:
ParentCommandLine|contains:
- 'site-packages\\langchain'
- 'site-packages\\autogen'
- 'site-packages\\semantic_kernel'
- 'node_modules\\langchain'
condition: selection_parent and selection_child and not filter_known_agent_paths
falsepositives:
- Developer workstations running local agent prototypes
- Legitimate automation frameworks invoking system utilities
level: medium
---
title: Suspicious Credential or Secret File Access by Agent Runtime
description: Detects agent runtimes or script interpreters accessing credential stores, token caches, or secret files — consistent with token theft from agent workloads.
references:
- https://attack.mitre.org/techniques/T1552/
author: Security Arsenal
date: 2026/04/10
tags:
- attack.credential_access
- attack.t1552.001
logsource:
category: file_event
product: windows
detection:
selection:
TargetFilename|contains:
- '\.env'
- 'credentials.json'
- 'client_secret'
- '\.azure\'
- 'msal_token_cache'
- 'accessTokens.json'
selection_image:
Image|endswith:
- '\python.exe'
- '\node.exe'
- '\pwsh.exe'
filter_msal_legit:
TargetFilename|contains: 'AppData\\Local\\.IdentityService'
condition: selection and selection_image and not filter_msal_legit
falsepositives:
- Applications legitimately reading their own configuration
- MSAL-based apps accessing the Microsoft Identity token cache
level: high
KQL — Microsoft Sentinel / Defender
Hunt for newly created or modified service principals and app registrations granted high-impact Microsoft Graph permissions — the classic over-privileged agent identity pattern. Correlate with anomalous sign-in behavior from those identities.
// Part 1: New app registrations / service principals granted high-risk Graph permissions (last 14 days)
let HighRiskScopes = dynamic(["Mail.Read", "Mail.ReadWrite", "Files.ReadWrite.All", "Sites.FullControl.All", "Directory.ReadWrite.All", "RoleManagement.ReadWrite.Directory", "Application.ReadWrite.All", "full_access_as_app"]);
AuditLogs
| where TimeGenerated > ago(14d)
| where OperationName in ("Add service principal", "Add app role assignment to service principal", "Consent to application", "Add delegated permission grant")
| mv-expand TargetResources
| mv-expand TargetResources.modifiedProperties
| where tostring(TargetResources_modifiedProperties.displayName) has "Permission"
| extend NewValue = tostring(TargetResources_modifiedProperties.newValue)
| where NewValue has_any (HighRiskScopes)
| extend AppId = tostring(TargetResources.id)
| extend Actor = tostring(InitiatedBy.user.userPrincipalName)
| project TimeGenerated, OperationName, Actor, AppId, NewValue, CorrelationId, IPAddress = tostring(InitiatedBy.user.ipAddress)
| order by TimeGenerated desc;
// Part 2: Service principal sign-ins from infrastructure never seen for that identity (token replay indicator)
let Lookback = 30d;
let History = AADServicePrincipalSignInLogs
| where TimeGenerated > ago(Lookback) and TimeGenerated < ago(1d)
| summarize HistoricalIPs = make_set(IPAddress) by AppId;
AADServicePrincipalSignInLogs
| where TimeGenerated > ago(1d)
| summarize RecentIPs = make_set(IPAddress), Requests = count() by AppId, AppDisplayName
| join kind=inner History on AppId
| mv-expand RecentIP = RecentIPs to typeof(string)
| where HistoricalIPs !has RecentIP
| project AppDisplayName, AppId, RecentIP, Requests
| order by Requests desc
Velociraptor VQL
Hunt endpoints for agent runtimes holding active outbound network connections to AI API endpoints or unusual destinations — useful for identifying shadow agent deployments and unexpected egress from agent processes.
-- Hunt: agent runtimes with active network connections
SELECT Pid,
Name,
Exe,
CommandLine,
Username,
netstat().RemoteIP AS RemoteIP,
netstat().RemotePort AS RemotePort,
netstat().Status AS ConnStatus
FROM pslist()
WHERE Name =~ '(?i)python|node|pwsh'
AND CommandLine =~ '(?i)agent|copilot|langchain|autogen|semantic|openai'
AND netstat().Status =~ 'ESTAB'
Remediation Script — Audit High-Privilege Agent Identities in Entra ID
Run this against your tenant to inventory service principals holding high-risk Microsoft Graph app roles — the population Microsoft's framework tells you to bring under dynamic permission and continuous monitoring controls. Requires the Microsoft Graph PowerShell SDK with Application.Read.All and Directory.Read.All consent.
# Audit Entra ID service principals for high-risk Graph permissions (agent identity inventory)
Connect-MgGraph -Scopes "Application.Read.All","Directory.Read.All" -NoWelcome
$HighRiskRoles = @(
'Mail.Read','Mail.ReadWrite','Mail.Send',
'Files.ReadWrite.All','Sites.FullControl.All',
'Directory.ReadWrite.All','RoleManagement.ReadWrite.Directory',
'Application.ReadWrite.All','User.ReadWrite.All'
)
# Resolve Graph resource service principal for role display names
$graphSp = Get-MgServicePrincipal -Filter "appId eq '00000003-0000-0000-c000-000000000000'"
$roleMap = @{}
$graphSp.AppRoles | ForEach-Object { $roleMap[$_.Id] = $_.Value }
$report = foreach ($sp in (Get-MgServicePrincipal -All)) {
$assignments = Get-MgServicePrincipalAppRoleAssignment -ServicePrincipalId $sp.Id -All -ErrorAction SilentlyContinue
$hits = $assignments | Where-Object { $roleMap[$_.AppRoleId] -in $HighRiskRoles }
if ($hits) {
[PSCustomObject]@{
ServicePrincipal = $sp.DisplayName
AppId = $sp.AppId
ObjectId = $sp.Id
HighRiskRoles = ($hits | ForEach-Object { $roleMap[$_.AppRoleId] }) -join '; '
CreatedDate = $sp.AdditionalProperties['createdDateTime']
}
}
}
$report | Sort-Object ServicePrincipal | Format-Table -AutoSize
$report | Export-Csv -Path ".\HighRiskAgentIdentities_$(Get-Date -Format 'yyyyMMdd').csv" -NoTypeInformation
Write-Host "`n[+] $($report.Count) service principals hold high-risk Graph permissions. Review each for: business justification, scope reduction, PIM eligibility, and credential rotation." -ForegroundColor Yellow
Remediation
There is no patch for this — remediation is architectural. Prioritize in this order:
- Inventory every non-human identity. You cannot protect what you haven't cataloged. Use the script above, plus Entra ID's Workload Identities blade and Copilot Studio's admin analytics, to build a complete registry of agents, their owning teams, and their permissions. Flag anything without a named human owner.
- Eliminate standing privilege. Replace broad, permanent Graph scopes with the minimum required. Where the platform supports it, use just-in-time elevation (PIM for workload identities where available, or short-lived federated credentials instead of long-lived client secrets). Kill client secrets older than 90 days; prefer managed identities and workload identity federation so there are no secrets to steal at all.
- Enforce Conditional Access for workload identities. Scope agent service principals to known IP ranges / compliant egress points. A token replayed from foreign infrastructure should fail closed, not succeed.
- Stand up behavioral baselining. Feed
AADServicePrincipalSignInLogsandAuditLogsinto Sentinel (or your SIEM of choice) and alert on deviation: new source IPs, new API patterns, new data volumes, off-hours execution. Microsoft's continuous risk monitoring pillar only works if the telemetry is actually flowing. - Implement automated containment playbooks. Pre-stage Logic App / Sentinel automation rules that, on high-confidence agent anomaly, revoke refresh tokens, disable the service principal, and isolate the hosting workload — with a break-glass approval path. Mean time to containment for a compromised non-human identity should be measured in minutes, not ticket SLAs.
- Treat prompt injection as a first-class threat. Constrain what agents can read (untrusted content isolation), what tools they can invoke (allow-lists, human approval for destructive actions), and what they can output (egress filtering on agent-triggered API calls). Test your agents adversarially — this is now a standard scope item in mature penetration testing engagements.
- Govern the lifecycle. Every agent gets an owner, an expiry date, and a quarterly access review. Orphaned agent identities are deprovisioned automatically.
Reference Microsoft's official security blog publication on securing AI agents for the full framework detail: https://www.microsoft.com/security/blog/ — and the source reporting at SecurityAffairs: https://securityaffairs.com/201336/ai/microsoft-treats-ai-agents-as-insider-threats-in-new-security-framework.html
Related Resources
Security Arsenal Penetration Testing Services AlertMonitor Platform Book a SOC Assessment vulnerability-management Intel Hub
Is your security operations ready?
Get a free SOC assessment or see how AlertMonitor cuts through alert noise with automated triage.