This was a fun one

For me at least, the clients were freaking the fuck out.

They had all of their data on the root SharePoint site, public site, anyone with access can see.

Turns out a lot of that information was pretty sensitive, also turns out one of their employees had been implicated in something that made them want to restrict their access severely and urgently. This was a new client I didn’t know shit about them, walking into it blind.

No worries, make a group in the site with those who can see, break the inheritance on the library, allow only the group to see. Give the potential espionage enjoy access to only a select subset.

Done easy, I’m a chad. See SharePoint - Restrict a User to a Few Folders

Next day it’s alllll fucked up, there’s large swaths of folders that can’t be seen, perms are in place, they can get the folders through share links in the teams chat but not browse to it in their files. Operate term there was ‘share links’.

They’d been using the share button to send files among themselves for God knows how long, creating ‘Anyone with Link Can Open’ share links every time. Bad for two reasons

  1. 5000 files and folders with broken permissions scattered around the whole file set. No wonder my fancy pants exclusionary group didn’t propagate.

  2. 5000 open URL links with no expiries had been created and then abandoned. I’m not cybersecurity consultant but that’s a tut tut and finder wag right there.

See the process of fixing below. They’re all good now and we’re in the process of completely redesigning and rebuilding their SharePoint storage and permissions.

Symptom

Users say some subfolders “aren’t accessible”, even though everyone on the team should have access to everything. Looking at permissions, inheritance is broken all over the library.

Cause

Staff use the Share button to send each other files internally. Each share makes a sharing link, and every link breaks inheritance on that item. If the default link type is Anyone, you also end up with thousands of anonymous “anyone with the link can view” links that nobody needed.

One 4-person team: 65,843 items scanned, 2,578 with unique permissions, about 90% of them from share links.

Fix

1. Stop new ones

  • SharePoint admin center > Policies > Sharing > default link type → People in your organization.
  • Better, if the team never shares outside: set the site’s sharing to Only people in your organization, so Anyone links can’t be made at all.
  • If Anyone links have to stay: Anyone links must expire within N days (same page, tenant-wide). Per site:
    Set-SPOSite -Identity https://tenant.sharepoint.com/sites/X -AnonymousLinkExpirationInDays 30

2. Find and reset the existing ones

This is a script job, not a click-through job. Use PnP PowerShell (with a PnP app registration in the tenant) to walk the library, list every item with HasUniqueRoleAssignments, and export who has access to a CSV. Then reset the ones you want to inherit from the library again.

The script I use (Reset-SPLibraryInheritance.ps1):

  • Default run is report-only. It exports a CSV of every item with unique permissions and who had access. Read it before changing anything.
  • -Apply resets every item to inherit from the library.
Reset-SPLibraryInheritance.ps1 -SiteUrl https://tenant.sharepoint.com/sites/X -Library "Documents" -ClientId <pnp-app-guid>

Gotchas

  • Resetting inheritance deletes the sharing links on those items. That’s the point, but warn the client that any link they’ve sent outside will stop working.
  • It also wipes deliberate unique permissions. If someone’s been restricted to certain folders on purpose (see SharePoint - Restrict a User to a Few Folders), exclude those folders or re-grant them after.
  • Existing Anyone links keep working after you change the default. Only new links get the new type.
  • Summarise the CSV rather than reading it. Grouping by link type or by who has access shows the pattern fast.

Keeping it clean

The report-only run is the audit. Run it monthly for a bit and compare the counts to see if the new default has stuck.

Types of SharePoint Sites