SharePoint and OneDrive External Sharing Security: Settings and Auditing

How do you restrict external sharing in SharePoint and OneDrive? Sharing levels, the default link, anonymous link expiry, domain lists and auditing open shares with PowerShell.
Technical summary
Technology
SharePoint Online, OneDrive, SharePoint Online Management Shell, Microsoft Purview audit log, Entra B2B
Topic
Tenant- and site-level external sharing settings and auditing sharing links
Level
Intermediate
Prerequisites
  • The SharePoint Administrator role
  • The SharePoint Online Management Shell module
  • The Purview audit log turned on
In this article9 sections

Data usually leaves SharePoint and OneDrive not through an attack but through a sharing link created without thinking about who can open it. The link is forwarded by email, lands in a supplier’s shared folder and still works months later. This guide explains for Microsoft 365 administrators and information security teams the external sharing levels, the relationship between tenant and site settings, link defaults, and how to report on and clean up shares opened in the past, with PowerShell examples.

External sharing levels

In the SharePoint admin center, on the Policies > Sharing page, there are four levels. If you’ll audit with scripts, you need to know their PowerShell equivalents by heart; in reports you’ll see these values, not the portal names.

Portal level PowerShell value Meaning
Anyone ExternalUserAndGuestSharing Including links used without signing in
New and existing guests ExternalUserSharingOnly External people access with authentication
Existing guests ExistingExternalUserSharingOnly Only guests already in the directory
Only people in your organization Disabled External sharing off

In a corporate environment, a reasonable starting point is usually the “New and existing guests” level. You can work with external people, but every access is tied to an identity. No identity, no trail. The “Existing guests” level makes sense in organizations where guest invitations are tied to specific roles or an approval process; the invitation and review process is explained separately in the Entra B2B guest access security article.

The relationship between tenant and site settings

Settings are assessed on three layers, and there’s one rule: a lower layer can’t be more permissive than the one above it.

  • Tenant (SharePoint): The upper limit for all sites.
  • OneDrive: Equal to or more restrictive than the tenant. Personal spaces are the most uncontrolled source of sharing in the field; keeping OneDrive one step below SharePoint is a common and sensible choice.
  • Site: Equal to or more restrictive than the tenant. A project site, an HR site and a supplier portal can sit at different levels.

This model means: you open the tenant to the most permissive level most often needed, and tighten sensitive sites one by one. The level new sites are born with, including those created through Teams, depends on the site type and the tenant setting, and is often more permissive than needed for sensitive content. Make narrowing the setting after a sensitive team’s site is created a written process step. When the number of sites reaches the hundreds, manual tracking ends. Take periodic dumps:

Connect-SPOService -Url https://contoso-admin.sharepoint.com

# Tenant and OneDrive levels
Get-SPOTenant | Select-Object SharingCapability, OneDriveSharingCapability,
  DefaultSharingLinkType, DefaultLinkPermission, RequireAnonymousLinksExpireInDays

# Sites that allow Anyone links
Get-SPOSite -Limit All |
  Where-Object SharingCapability -eq 'ExternalUserAndGuestSharing' |
  Select-Object Url, Owner, SharingCapability |
  Export-Csv .\anonymous_sharing_sites.csv -NoTypeInformation -Encoding UTF8

Save this CSV to the same place every month and compare it with the previous one. A site newly appearing on the list shows that someone opened the setting, knowingly or not.

The link type that comes up when a user presses “Share” determines how most sharing will be done, because most users don’t change the default. There are three options: specific people, people in your organization, anyone. If you make “specific people” the default, a link forwarded to the wrong person won’t open. The default permission should be “view”. Edit rights are chosen deliberately.

Set-SPOTenant -DefaultSharingLinkType Direct -DefaultLinkPermission View

# The same default at site level on a sensitive site
Set-SPOSite -Identity https://contoso.sharepoint.com/sites/hr `
  -DefaultSharingLinkType Direct -DefaultLinkPermission View

The “People in your organization” link is practical for internal sharing, but a forwarded link opens for everyone in the organization. In libraries holding personal data or salary information, this also produces unexpected access. Keep the default at “specific people” on sensitive sites and back up the content with data loss prevention (DLP) rules.

Anyone links don’t require authentication. Whoever knows the link can access the content, and the access can’t be tied to a person. If you can’t turn them off completely, at least set these limits:

  • Mandatory expiry: The link becomes invalid on its own after a set number of days.
  • View only: No edit permission is granted on file and folder links.
  • Site restriction: Anyone links stay open only on specific sites, such as external communications or marketing.
Set-SPOTenant -RequireAnonymousLinksExpireInDays 14 `
  -FileAnonymousLinkType View -FolderAnonymousLinkType View

Don’t assume how the setting affects links opened earlier. After the change, verify the expiry of existing anonymous links with a report and remove unnecessary ones. The expiry is also a risk decision: a few weeks is enough for external communications, while for sharing technical drawings, guest access should be used instead of a link.

If you also want guest access to lapse on its own, make expiry mandatory at the tenant level. With the setting below, a guest’s site access closes after the specified number of days; the site owner extends it if needed. Forgotten access then closes by itself.

Set-SPOTenant -ExternalUserExpirationRequired $true -ExternalUserExpireInDays 60

Domain allow and block lists

If external sharing is done only with specific partners, an allow list is used; if sharing to specific domains (competitors, personal email services) is to be blocked, a block list is used. The two don’t work at the same time.

Set-SPOTenant -SharingDomainRestrictionMode AllowList `
  -SharingAllowedDomainList "supplier-a.com.tr partner-b.com"

An allow list is a strong control from an enterprise cybersecurity standpoint, but it needs maintenance. If the list isn’t updated for a new partner, users start sending the file as an email attachment and the control is bypassed entirely. Tie list ownership to the purchasing or partner management process. Keep in mind that guest invitations can also be restricted by domain on the Entra ID side. If the two lists conflict, “the invitation went out but sharing won’t open” tickets start; in the field, the first place to look for such requests is the difference between the two lists.

Reporting on existing shares

Tightening settings doesn’t delete links opened in the past. The audit draws on three sources:

Source What it shows Note
Site sharing links report Links on the site and their types Produces a CSV per site
Purview audit log Link creation and usage events Retention period depends on the license
Data access governance reports Tenant-wide link summary Requires SharePoint Advanced Management
Get-SPOExternalUser External users with access to sites Returns paged results

In the audit log, creating and using an anonymous link are separate events. The query below lists anonymous links created and used in the last 30 days. Group the result by user and site; the areas doing the most anonymous sharing stand out immediately.

Connect-ExchangeOnline
Search-UnifiedAuditLog -StartDate (Get-Date).AddDays(-30) -EndDate (Get-Date) `
  -Operations AnonymousLinkCreated,AnonymousLinkUsed -ResultSize 5000 |
  Select-Object CreationDate, UserIds, Operations, AuditData |
  Export-Csv .\anonymous_link_events.csv -NoTypeInformation -Encoding UTF8

In a dump that hits the -ResultSize 5000 limit, the latest records are missing; in a busy tenant, split the date range into weeks. Distribute the report to site owners and ask for decisions: is the link needed, is its expiry appropriate, is the content in the right place? Anonymous links on sites without an owner are the first candidates for removal.

Restrictions for sensitive sites

Define a profile separate from the tenant default for HR, finance, R&D and legal sites:

  • External sharing Disabled or ExistingExternalUserSharingOnly.
  • Only site owners share; members send an access request.
  • Browser-only, no-download access from unmanaged devices.
  • A “Highly Confidential” site label is assigned to the site, and settings are managed through the label.
$site = "https://contoso.sharepoint.com/sites/rnd"
Set-SPOSite -Identity $site -SharingCapability Disabled
Set-SPOSite -Identity $site -DisableSharingForNonOwners
Set-SPOSite -Identity $site -ConditionalAccessPolicy AllowLimitedAccess

The unmanaged device restriction works together with a matching Conditional Access policy in Entra ID. The site setting alone isn’t enough. If you manage settings with site labels instead of applying them site by site, newly created sensitive sites fall into the same profile too; setting up the label scheme is covered in the sensitivity label design guide. For keeping the permission model simple at the site, library and item level, also see the SharePoint permission model design article. Broken permissions at the item level are the classic source of access the report can’t see.

Setting Recommendation Reason
Tenant level New and existing guests Access tied to an identity
OneDrive level Equal to or narrower than the tenant Control over personal spaces
Default link Specific people, view A forwarded link is useless
Anyone links Off, or time-limited and read-only Access that leaves no trail
Guest access period Expiry mandatory Closes forgotten access
Sensitive sites A restricted profile via site label Scalable management

For all options and their current behavior, rely on Microsoft’s external sharing management documentation. To assess sharing settings together with Conditional Access, DLP and labels, take a look at the Microsoft 365 security service page; methods for blocking external sharing based on content are in the Purview DLP policy design article.

Frequently asked questions

Not in every organization. Teams that often send large files outside may move to email attachments or personal cloud services when this link is turned off. A controlled middle ground: keep Anyone links open only on specific sites, grant view-only permission and make a short expiry mandatory.

Can a site be given more permissive sharing than the tenant?

No. The site setting can be the same as or more restrictive than the tenant setting. The OneDrive level can’t be more permissive than the SharePoint tenant level either.

Can a guest’s access expire automatically?

Yes. At the tenant level, you can require guest access to end after a certain number of days; site owners can extend access. This setting covers SharePoint and OneDrive shares. The lifecycle of the guest account in Entra ID is managed separately with access reviews.

Where can I see which file has been shared with whom?

For a single site, look at the sharing links report on the site usage page. Tenant-wide, sharing and anonymous link events are kept in the Purview audit log. If you have a SharePoint Advanced Management license, data access governance reports show sharing links in bulk per site.

Support

Contact us for support or a discovery session on this topic.

Contact form
[email protected]

Eretek Cybersecurity

Firewall, VPN, endpoint security and threat prevention. We reduce the attack surface and measure and report the risks.

Knowledge Center

Other articles