Decode and predict Microsoft-managed SharePoint Embedded container URLs

Recently, I spent some hours analyzing why one of my test accounts had no personal (user-owned) Loop Workspace container. All required policies were enabled, and the account could create tenant-owned workspaces. So it was not a permission or policy issue.

image.png
The account could create tenant-owned workspaces

The cause of the missing container

I remembered my September test, where I ran simulations to transfer a user-owned container to a new principal owner.

From my September test, I saw my Test Account 2 was the principal owner of two user-owned containers. One of these containers came from Test Account 1.

image.png
User-owned SharePoint Embedded containers

I deleted both containers because the system recreates them when needed. Deleting a container also removes its content, save any data you need first.
My Test Account 1 then created a new container, as expected. So the issue was fixed.

image.png
My Test Account 1 created a new container

How the container URLs are built

That started a much more interesting investigation, which revealed how Microsoft builds the URLs for its own SharePoint Embedded containers. For user-owned containers, you can even predict them.
I looked at Loop, Designer, Work IQ, and Outlook Newsletters containers, not at self-deployed applications.

I wondered how the system knows the account already has a user-owned container. One surprising result was that I could not restore the deleted container from the container recycle bin. The SharePoint admin center returned a general error. PowerShell was more useful: reported a site collection conflict.

Restore-SPODeletedContainer: A site collection with the same Site Id or Path already exists.
image.png
There is a site collection conflict

As you may know, you cannot access the site collection behind a Microsoft-managed SharePoint Embedded container. But you can use Sentinel or Purview Audit Logs to get more insight into these containers.

There you will find an interesting result: a user-owned container of one account always uses the same URL. This causes the restore conflict.
This probably also explains my initial issue. After the transfer, the container of Test Account 1 was still there under the original URL, which is based on the account's object ID. So the system had no reason to create a new one.

image.png
A user-owned container of one account always uses the same URL

I asked Claude to analyze the string x8FNO-xtskuCRX2_fMTHLVXFrmheVItEjvHk4bPY15s to see whether it includes user and container type information. It does.

User-owned containers

First, a graphic to show how the container URL is built.

image.png
The format of user-owned container URLs

Each Base64url character holds 6 bits, and a GUID has 128 bits. A GUID therefore needs 22 characters (128 / 6 = 21.33), so the boundary between the two GUIDs falls inside a character.

  • Characters 1 to 21 contain the first 126 bits of the container type ID.
  • Character 22 contains the last 2 bits of the container type ID and the first 4 bits of the user object ID.
  • Characters 23 to 43 contain the remaining 124 bits of the user object ID, followed by 2 padding bits.

To read both GUIDs, decode the whole string to 32 bytes and split it after byte 16.
Here is a PowerShell sample to decode a user-owned container URL:

PowerShell
# ---------------------------------------------
# Decode: URL -> container type ID + object ID
# ---------------------------------------------

function ConvertFrom-SPEContainerUrl {
    param (
        [Parameter(Mandatory, ValueFromPipeline)]
        [string]$Url
    )

    process {
        # Get the last URL segment
        $Segment = ($Url.TrimEnd('/') -split '/')[-1]

        # Convert Base64url to Base64 (43 characters need one padding '=')
        $Base64 = $Segment.Replace('-', '+').Replace('_', '/') + '='
        $Bytes  = [Convert]::FromBase64String($Base64)

        # Split the 32 bytes into two GUIDs
        [pscustomobject]@{
            ContainerTypeId = [guid]::new([byte[]]$Bytes[0..15])
            UserObjectId    = [guid]::new([byte[]]$Bytes[16..31])
        }
    }
}

$ContainerUrl = "<ContainerUrl>"
ConvertFrom-SPEContainerUrl -Url $ContainerUrl

The result reveals the container type ID and the Entra ID user object ID.

image.png
Container type ID and the Entra ID user object ID

The object ID belongs to my Test Account 1, which confirms how the container URL is built.

image.png
The object ID belongs to my Test Account 1

Now you can also predict the URL for user-owned containers. I simulated this with several accounts; all results were correct.

PowerShell
# ---------------------------------------------
# Encode: container type ID + object ID -> URL
# ---------------------------------------------

function ConvertTo-SPEContainerUrl {
    param (
        # Tenant name, e.g. "contoso" for contoso.sharepoint.com
        [Parameter(Mandatory)]
        [string]$Tenant,

        # Entra ID user object ID
        [Parameter(Mandatory)]
        [guid]$UserObjectId,

        # Default: Loop. Designer: 136c8272-9d43-4a22-aeda-e10e0a770739
        [guid]$ContainerTypeId = "3b4dc1c7-6dec-4bb2-8245-7dbf7cc4c72d"
    )

    # Combine both GUIDs and encode them as Base64url
    $Bytes   = [byte[]]($ContainerTypeId.ToByteArray() + $UserObjectId.ToByteArray())
    $Segment = [Convert]::ToBase64String($Bytes).TrimEnd('=').Replace('+', '-').Replace('/', '_')

    "https://$Tenant.sharepoint.com/contentstorage/$Segment"
}

ConvertTo-SPEContainerUrl -Tenant $Tenant -UserObjectId $UserObjectId
image.png
Encoded user-owned container URL

Tenant-, group- and application-owned containers

These containers use a different URL format:

Text
https://<Tenant>.sharepoint.com/contentstorage/CSP_<GUID>

The GUID is the container's site collection ID.
You find the same ID in the first 16 bytes of the container ID. The URL contains neither the container type ID nor a user object ID.

image.png
The format of tenant-, group- and application-owned container URLs

Here is a PowerShell sample to build the CSP_ URL from a container ID.

Text
function ConvertFrom-SPEContainerId {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]
        [ValidatePattern('^b![A-Za-z0-9_-]{64}$')]
        [string]$ContainerId,

        # Tenant name, e.g. "contoso" for contoso.sharepoint.com
        [Parameter(Mandatory)]
        [string]$Tenant
    )

    process {
        # Remove "b!" and convert Base64url to Base64
        $Base64 = $ContainerId.Substring(2).Replace('-', '+').Replace('_', '/')
        $Bytes  = [Convert]::FromBase64String($Base64)

        # Split the 48 bytes into three GUIDs
        $SiteId    = [guid]::new([byte[]]$Bytes[0..15])
        $WebId     = [guid]::new([byte[]]$Bytes[16..31])
        $LibraryId = [guid]::new([byte[]]$Bytes[32..47])

        [pscustomobject]@{
            CSPUrl    = "https://$Tenant.sharepoint.com/contentstorage/CSP_$SiteId"
            SiteId    = $SiteId
            WebId     = $WebId
            LibraryId = $LibraryId
        }
    }
}

ConvertFrom-SPEContainerId -Tenant $Tenant -ContainerId $ContainerId 
image.png
Tenant-owned container ID decoded
Share this post:

About the Author

Tobias Asböck

Tobias Asböck

Tobias is a Senior System Engineer with more than 10 years of professional experience with Microsoft 365 products such as SharePoint Online, OneDrive for Business, Teams Collaboration, Entra ID, Information Protection, Universal Print, and Microsoft 365 Licensing. He also has 15+ years of experience planning, administering, and operating SharePoint Server environments. In his spare time, Tobias is busy with updates in the Microsoft 365 world or on the road with his road bike and other sports activities. If you have additional questions, please contact me via LinkedIn or support@topedia.com.

No comments yet