# (L1) Ensure guest access to a site or OneDrive will expire automatically

7.2.9 (L1) Ensure guest access to a site or OneDrive will expire automatically

Source: https://maester.dev/docs/tests/CIS.M365.7.2.9

<!-- This file is generated by website/scripts/generate-test-docs.mjs. Do not edit manually. -->

<div class="test-byline"><div class="test-byline-avatars"><a class="test-byline-avatar test-byline-avatar--author" href="/contributors/mynster9361" title="-Mynster · Original author"><img src="https://github.com/Mynster9361.png" alt="-Mynster" width="28" height="28" loading="lazy" decoding="async" /></a></div><div class="test-byline-meta"><span class="test-byline-text">Contributed by <a href="/contributors/mynster9361">-Mynster</a></span><a class="test-byline-link" href="/contributors">All contributors →</a></div></div>

<p class="test-part">Part of <a href="/docs/tests/cis">CIS</a> · SharePoint · External sharing · <a href="/docs/tests">All checks</a></p>

```powershell title="Run this check"
Invoke-Maester -TestId CIS.M365.7.2.9
```

## Overview

7.2.9 (L1) Ensure guest access to a site or OneDrive will expire automatically

This policy setting configures the expiration time for each guest that is invited to the SharePoint site or with whom users share individual files and folders with.

The recommended state is **30**. This is the minimum value SharePoint allows for this setting.

## Rationale

This setting ensures that guests who no longer need access to the site or link no longer have access after a set period of time. Allowing guest access for an indefinite amount of time could lead to loss of data confidentiality and oversight.

>Note: Guest membership applies at the Microsoft 365 group level. Guests who have permission to view a SharePoint site or use a sharing link may also have access to a Microsoft Teams team or security group.

## Impact

Site collection administrators will have to renew access to guests who still need access after 30 days. They will receive an e-mail notification once per week about guest access that is about to expire.

>Note: The guest expiration policy only applies to guests who use sharing links or guests who have direct permissions to a SharePoint site after the guest policy is enabled. The guest policy does not apply to guest users that have pre-existing permissions or access through a sharing link before the guest expiration policy is applied.

## Remediation

1. Navigate to [SharePoint admin center](https://admin.microsoft.com/sharepoint)
2. Click to expand **Policies** > **Sharing**.
3. Scroll to and expand **More external sharing settings.**
4. Set **Guest access to a site or OneDrive will expire automatically after this many days** to ***30***

### PowerShell

1. Connect to SharePoint Online using `Connect-SPOService`
2. Run the following command:

```powershell
Set-SPOTenant -ExternalUserExpireInDays 30 -ExternalUserExpirationRequired $True
```

>Default Value: ExternalUserExpirationRequired $false, ExternalUserExpireInDays 60 days

## Related Links

* [Manage sharing settings for SharePoint and OneDrive in Microsoft 365](https://learn.microsoft.com/sharepoint/turn-external-sharing-on-or-off#change-the-organization-level-external-sharing-setting)
* [Managing SharePoint Online Security: A Team Effort](https://learn.microsoft.com/microsoft-365/community/sharepoint-security-a-team-effort)
* [CIS Microsoft 365 Foundations Benchmark v7.0.0 - Page 487](https://www.cisecurity.org/benchmark/microsoft_365)

## Details

<details>
<summary>Every attribute of this check</summary>

| Field | Value |
| --- | --- |
| Test ID | CIS.M365.7.2.9 |
| Severity | Medium |
| Suite | CIS |
| Product | SharePoint |
| Feature | External sharing |
| Area | External access and sharing |
| Resource type | Tenant |
| User impact | Medium |
| Implementation cost | Low |
| MITRE ATT&CK | T1213.002 Sharepoint, T1530 Data from Cloud Storage |
| Supports benchmark | CIS Microsoft 365 Foundations Benchmark (version 7.0.0), requirement 7.2.9 |
| Benchmark level | L1 |
| Benchmark profiles | E3 Level 1, E5 Level 1 |
| Supports controls | cis-m365:7.2.9, nist-800-53-r5:AC-2(2) |
| PowerShell test | [Test-MtCisSpoGuestAccessExpiry](https://github.com/maester365/maester/blob/main/tests/cis/Test.CIS.M365.7.2.9.ps1) |
| Services | SharePointOnline |

</details>

## Source

- Test: [`tests/cis/Test.CIS.M365.7.2.9.ps1`](https://github.com/maester365/maester/blob/main/tests/cis/Test.CIS.M365.7.2.9.ps1)
- Documentation: [`tests/cis/Test.CIS.M365.7.2.9.md`](https://github.com/maester365/maester/blob/main/tests/cis/Test.CIS.M365.7.2.9.md)
