All right class.

Somebody shared a file this week by picking the option at the top of the list. The one that says Anyone with the link. It was the fastest way to get the file to a supplier, and it worked first time. That's exactly why people pick it.

That link still works. It'll keep working until somebody deliberately removes it, and nobody's going to.

Having the URL is the access. No account, no password, no second factor, no device check. The identity stack you spent years building doesn't get a vote. Conditional Access never evaluates it. Your MFA policy is irrelevant. There's nothing in SigninLogs either, because nobody signed in.

Two things follow from that. The second is why this is a security post and not a governance one.

The link outlives the person. Offboarding disables the account, revokes the sessions and hands the mailbox to a manager. It does nothing to the anonymous links that account created, because those links hang off the file, not the account. A leaver who spends twenty minutes making links to the client list walks out with working access. The checklist reports success. Quest complete.

The link also survives incident response. When you contain a compromised mailbox, you reset the password, revoke the refresh tokens and force reauthentication. If the attacker made anonymous links to whatever they found, none of that matters. The links keep serving the data. It's exfiltration done in advance and collected later, so it belongs in your post-compromise checklist, right next to mail forwarding rules.

What Exists, and Who Is Gone

Start with the inventory, sorted by the thing that matters.

// Anonymous links created in the window: deliberate shares first, orphans at the top of each group
let Lookback = 30d;                  // sweep window
let IdentityLookback = 14d;          // one full UEBA resync cycle
// Portable across the Log Analytics, advanced hunting and unified IdentityInfo schemas
let Directory = IdentityInfo
    | where TimeGenerated > ago(IdentityLookback)
    | extend Upn = tolower(coalesce(column_ifexists("AccountUPN", ""), column_ifexists("AccountUpn", "")))
    | where isnotempty(Upn)
    | summarize arg_max(TimeGenerated, IsAccountEnabled, Department, JobTitle, Manager) by Upn
    // lookup consumes the right-hand key, so Upn does not survive the join.
    // This marker does, and it is what tells you the creator was not found.
    | extend DirectoryHit = "Found"
    | project-away TimeGenerated;
// Links explicitly taken down inside the window
let Revoked = OfficeActivity
    | where TimeGenerated > ago(Lookback)
    | where Operation == "AnonymousLinkRemoved"
    | where isnotempty(UniqueSharingId)
    | distinct UniqueSharingId;
OfficeActivity
| where TimeGenerated > ago(Lookback)
| where RecordType == "SharePointSharingOperation"
| where Operation == "AnonymousLinkCreated"
| where UserId !~ "app@sharepoint"
| extend Creator = tolower(UserId)
| lookup kind=leftouter Directory on $left.Creator == $right.Upn
| extend OwnerGone = isempty(DirectoryHit) or IsAccountEnabled == false
| extend OwnerStatus = case(isempty(DirectoryHit), "Not in directory", IsAccountEnabled == false, "Disabled", "Active")
| extend StillLive = isempty(UniqueSharingId) or UniqueSharingId !in (Revoked)
| extend Estate = iff(Site_Url has "/personal/", "OneDrive", "SharePoint")
// With Anyone as the default, most anonymous links are created by Teams on the
// user's behalf, not by a person choosing to share. Separate the two or the
// output is all screenshots.
| extend ClientApp = tostring(column_ifexists("ClientAppName", ""))
| extend LinkPermission = extract(@"<Type>(\w+)</Type>", 1, tostring(Event_Data))
| extend LinkOrigin = case(
      SourceRelativeUrl has "Microsoft Teams Chat Files", "Teams chat attachment (automatic)",
      ClientApp has "Teams", "Teams, file already in OneDrive",
      "Deliberate share")
| project TimeGenerated, LinkOrigin, LinkPermission, OwnerStatus, Creator, Department, JobTitle, Manager,
          SourceFileName, SourceFileExtension, Estate, StillLive,
          Site_Url, SourceRelativeUrl, ClientIP, ClientApp, UserAgent, UniqueSharingId, OwnerGone
| sort by LinkOrigin asc, OwnerGone desc, StillLive desc, TimeGenerated desc

Your First Run Will Be Screenshots

Run query one in a tenant where the default link is Anyone and most of the output will be files called something like "Screenshot 2026-07-30 204221.png". They arrive in bursts of fourteen in six seconds. They all live in a folder called Microsoft Teams Chat Files.

Every OneDrive grows one eventually. It's where screenshots go to live forever.

Nobody deliberately shared anything. Somebody dropped a batch of screenshots into a chat with a colleague. Teams uploaded each one to their OneDrive and made a sharing link for it, using your default link type. Default is Anyone, so every screenshot got an anonymous link of its own. Pasting a screenshot straight from the clipboard doesn't do this, because that copy stays inside Teams. Attaching it as a file does.

That's why LinkOrigin exists. Deliberate shares sort first and Teams' handiwork goes underneath, so the screenshots can't bury the links somebody chose to make. Don't filter them away, though. They're a finding in their own right. They're telling you what your default link type is, and you didn't even have to ask.

Within each group, OwnerGone sorts to the top, and it's the whole point of the query. A live anonymous link created by a disabled account is access to your data, set up by somebody who no longer works for you. No expiry, and nobody left to ask what it was for.

StillLive is honest rather than accurate. It only knows about links that were explicitly removed. A link that expired, a file that was deleted, a site where Anyone has been switched off: all of those still read as live. Treat the column as a lead, not a verdict.

Sharing operations on files named like credentials were covered in the password file post. This query sticks to the sharing mechanism rather than scoring the file name twice.

You'll Never Know Who Used It

Here's the part that changes how you should think about the risk.

When somebody opens an anonymous link, SharePoint records it under a generated identifier: urn:spo:anon# followed by a long hash. That isn't an identity. It's a placeholder so the user field isn't empty, and it can't be resolved back to a person. The same hash turns up across different addresses and sites over weeks, so as a correlation handle it's weak at best.

Your complete forensic picture of an anonymous access is an IP address, a user agent and a hash. If leadership asks who took the file, that's the answer. They'll ask again, slower. It'll still be the answer. Better to know that now than to find out on an incident call.

What you can measure is spread.

// Anonymous links being pulled, most widely circulated first
let Lookback = 30d;
OfficeActivity
| where TimeGenerated > ago(Lookback)
| where Operation == "AnonymousLinkUsed"
| where isnotempty(ClientIP)
| extend Country = tostring(geo_info_from_ip_address(ClientIP).country)
| extend Estate = iff(Site_Url has "/personal/", "OneDrive", "SharePoint")
| summarize Accesses = count(),
            FirstUse = min(TimeGenerated),
            LastUse = max(TimeGenerated),
            DistinctIPs = dcount(ClientIP),
            AnonSessions = dcount(UserId),
            IPs = make_set(ClientIP, 20),
            Countries = make_set(Country, 15),
            Agents = make_set(UserAgent, 10)
  by SourceFileName, SourceFileExtension, Estate, Site_Url, SourceRelativeUrl
| extend Circulation = case(DistinctIPs >= 10, "Widely circulated",
                            DistinctIPs >= 3, "Forwarded beyond the first recipient",
                            "Single source")
| project FirstUse, LastUse, Circulation, SourceFileName, SourceFileExtension, Estate,
          Accesses, DistinctIPs, AnonSessions, Countries, IPs, Agents, Site_Url, SourceRelativeUrl
| sort by DistinctIPs desc, Accesses desc

DistinctIPs is the number to read. A link sent to one supplier and opened from one office address is doing exactly what it was made for. The same link opened from fourteen addresses across four countries was forwarded, pasted into a ticket, or posted somewhere it shouldn't have been.

Check Agents before you call it, though. Mail gateways that scan links open them too, and so do apps that fetch a preview when a link gets pasted. They tend to do it from a cloud address in a country you've never been to. A couple of those is background noise. Fourteen that look like people isn't.

geo_info_from_ip_address resolves the country inside the query, because OfficeActivity gives you the address and nothing else.

The Shape That Looks Like Theft

One link is normal. Thirty links in twenty minutes is somebody packing.

// Bulk anonymous link creation, cross-referenced against what was then pulled
let Lookback = 14d;                  // detection window
let BurstWindow = 1h;                // creation must cluster this tightly to count
let BurstThreshold = 10;             // links per window before this reads as collection
let IdentityLookback = 14d;
let Directory = IdentityInfo
    | where TimeGenerated > ago(IdentityLookback)
    | extend Upn = tolower(coalesce(column_ifexists("AccountUPN", ""), column_ifexists("AccountUpn", "")))
    | where isnotempty(Upn)
    | summarize arg_max(TimeGenerated, IsAccountEnabled, Department, JobTitle, Manager) by Upn
    // lookup consumes the right-hand key, so carry a marker that survives it
    | extend DirectoryHit = "Found"
    | project-away TimeGenerated;
// Anything that was actually pulled through an anonymous link in the window
let AnonUse = OfficeActivity
    | where TimeGenerated > ago(Lookback)
    | where Operation == "AnonymousLinkUsed"
    | summarize UseCount = count(), UseIPs = dcount(ClientIP), LastPull = max(TimeGenerated)
      by SourceFileName;
OfficeActivity
| where TimeGenerated > ago(Lookback)
| where Operation == "AnonymousLinkCreated"
| where UserId !~ "app@sharepoint"
// Teams creates one of these per chat attachment, automatically. Fourteen
// screenshots dropped into a chat is not collection. Query one still inventories them.
| where not(SourceRelativeUrl has "Microsoft Teams Chat Files")
| extend Creator = tolower(UserId)
| extend Folder = replace_string(SourceRelativeUrl, SourceFileName, "")
| lookup kind=leftouter AnonUse on SourceFileName
| summarize LinkCount = count(),
            FilesPulled = dcountif(SourceFileName, isnotempty(LastPull)),
            TotalPulls = sum(UseCount),
            PullIPs = max(UseIPs),
            Sites = dcount(Site_Url),
            Folders = dcount(Folder),
            Files = make_set(SourceFileName, 30),
            CreatorIPs = make_set(ClientIP, 5),
            WindowStart = min(TimeGenerated), WindowEnd = max(TimeGenerated)
  by Creator, Burst = bin(TimeGenerated, BurstWindow)
| where LinkCount >= BurstThreshold
// A person clicking Share fourteen times takes minutes. An app doing it takes seconds.
// Fast single-folder bursts are dropped as automation, unless the files were then pulled.
| extend BurstSeconds = max_of(datetime_diff("second", WindowEnd, WindowStart), 1)
| extend LinksPerMinute = round(LinkCount * 60.0 / BurstSeconds, 1)
| where LinksPerMinute < 30 or Folders > 1 or FilesPulled > 0
| lookup kind=leftouter Directory on $left.Creator == $right.Upn
| extend Ind_1 = iff(isempty(DirectoryHit) or IsAccountEnabled == false, "Creator disabled or gone from directory", "")
| extend Ind_2 = iff(FilesPulled > 0, strcat(FilesPulled, " of these files were pulled anonymously"), "")
| extend Ind_3 = iff(Folders >= 3, strcat("Links created across ", Folders, " folders"), "")
| extend RiskIndicators = trim(@"\s\|\s*$", strcat(
      iff(isnotempty(Ind_1), strcat(Ind_1, " | "), ""),
      iff(isnotempty(Ind_2), strcat(Ind_2, " | "), ""),
      iff(isnotempty(Ind_3), strcat(Ind_3, " | "), "")))
| project WindowStart, WindowEnd, Creator, Department, JobTitle, Manager, IsAccountEnabled,
          LinkCount, LinksPerMinute, Folders, Sites, FilesPulled, TotalPulls, PullIPs,
          RiskIndicators, Files, CreatorIPs
| sort by FilesPulled desc, Folders desc, LinkCount desc

The combination to chase is a burst where FilesPulled is above zero. Creating thirty links is careless. Creating thirty links that then get pulled through is a completed exfiltration, and the timestamps tell you which order it happened in.

Folders and LinksPerMinute are what separate a person from an app. Somebody clicking Share, picking Anyone and copying the URL fourteen times takes minutes, and they wander between folders while they do it. A script, a flow or a migration tool does it in seconds from one place. So anything faster than thirty links a minute from a single folder gets dropped as automation, unless those files were then pulled anonymously. Speed on its own is usually automation. Speed followed by downloads is a speedrun.

Migration tools and bulk publishing will still trip it legitimately. Those accounts belong in an exclusion list, not in a raised threshold.

What You Should Do Next

Change the default link type before anything else. If Teams chat attachments are producing anonymous links, your default is Anyone. That one setting makes more anonymous links per week than any person ever will. Set it to Specific people, and set the default permission to View rather than Edit. Sharing still works. Most people won't notice. External recipients will, because they now have to prove who they are before the file opens. That's rather the point.

It isn't retroactive, though. Every Anyone link made before the change keeps working.

Then decide whether Anyone links should exist at all. In the SharePoint admin centre, external sharing has four levels and Anyone is the most permissive. Drop to New and existing guests and every Anyone link in the tenant stops working, old ones included. It's the only setting in this post that reaches backwards. The links aren't deleted, just switched off, so if somebody turns Anyone back on next year, they all wake up again. Sharing with guests carries on. File requests in OneDrive don't, because they need Anyone. Expect one ticket about it.

If you keep Anyone, set an expiry. Anonymous links support a maximum lifetime, and thirty days turns a permanent hole into a temporary one. Know what it covers, though. New links get the limit. Existing links with a longer expiry date get cut down to it. Links made with no expiry date at all are the ones you're actually worried about, and you shouldn't assume the setting reaches them. Widen query one's lookback as far as your retention allows and remove what it finds.

Run query one and start with OwnerGone. Live links created by disabled accounts are the shortest path from this post to something worth fixing. They'll be there.

Then add link revocation to offboarding. Disabling the account isn't containment while the links survive it. Same goes for incident response. If you contained a mailbox compromise this year without checking what was shared anonymously, that containment was finished on paper.

Class dismissed.