-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(sharepoint): add new check related with OneDrive Sync #7589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
andoniaf
merged 4 commits into
master
from
PRWLR-5795-ensure-one-drive-sync-is-restricted-for-unmanaged-devices
Apr 30, 2025
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
05d2edf
feat(sharepoint): add check sharepoint_onedrive_sync_restricted_unman…
pedrooot 21d0b98
feat(m365): update readme and changelog
pedrooot 5a71079
chore(revision): resolve comments
pedrooot e518d0b
Merge branch 'master' into PRWLR-5795-ensure-one-drive-sync-is-restri…
andoniaf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
30 changes: 30 additions & 0 deletions
30
...ted_unmanaged_devices/sharepoint_onedrive_sync_restricted_unmanaged_devices.metadata.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"Provider": "m365", | ||
"CheckID": "sharepoint_onedrive_sync_restricted_unmanaged_devices", | ||
"CheckTitle": "Ensure OneDrive sync is restricted for unmanaged devices.", | ||
"CheckType": [], | ||
"ServiceName": "sharepoint", | ||
"SubServiceName": "", | ||
"ResourceIdTemplate": "", | ||
"Severity": "critical", | ||
"ResourceType": "Sharepoint Settings", | ||
"Description": "Microsoft OneDrive allows users to sign in their cloud tenant account and begin syncing select folders or the entire contents of OneDrive to a local computer. By default, this includes any computer with OneDrive already installed, whether it is Entra Joined, Entra Hybrid Joined or Active Directory Domain joined. The recommended state for this setting is Allow syncing only on computers joined to specific domains Enabled: Specify the AD domain GUID(s).", | ||
"Risk": "Unmanaged devices can pose a security risk by allowing users to sync sensitive data to unauthorized devices, potentially leading to data leakage or unauthorized access.", | ||
"RelatedUrl": "https://learn.microsoft.com/en-us/graph/api/resources/sharepoint?view=graph-rest-1.0", | ||
"Remediation": { | ||
"Code": { | ||
"CLI": "Set-SPOTenantSyncClientRestriction -Enable -DomainGuids '786548DD-877B-4760-A749-6B1EFBC1190A; 877564FF-877B-4760-A749-6B1EFBC1190A'", | ||
"NativeIaC": "", | ||
"Other": "1. Navigate to SharePoint admin center https://admin.microsoft.com/sharepoint 2. Click Settings then select OneDrive - Sync. 3. Check the Allow syncing only on computers joined to specific domains. 4. Use the Get-ADDomain PowerShell command on the on-premises server to obtain the GUID for each on-premises domain. 5. Click Save.", | ||
"Terraform": "" | ||
}, | ||
"Recommendation": { | ||
"Text": "Restrict OneDrive sync to managed devices to prevent unauthorized access to sensitive data.", | ||
"Url": "https://learn.microsoft.com/en-us/sharepoint/allow-syncing-only-on-specific-domains" | ||
} | ||
}, | ||
"Categories": [], | ||
"DependsOn": [], | ||
"RelatedTo": [], | ||
"Notes": "" | ||
} |
48 changes: 48 additions & 0 deletions
48
...ync_restricted_unmanaged_devices/sharepoint_onedrive_sync_restricted_unmanaged_devices.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from typing import List | ||
|
||
from prowler.lib.check.models import Check, CheckReportM365 | ||
from prowler.providers.m365.services.sharepoint.sharepoint_client import ( | ||
sharepoint_client, | ||
) | ||
|
||
|
||
class sharepoint_onedrive_sync_restricted_unmanaged_devices(Check): | ||
""" | ||
Check if OneDrive sync is restricted for unmanaged devices. | ||
This check verifies that OneDrive sync is restricted to managed devices only. | ||
Unmanaged devices can pose a security risk by allowing users to sync sensitive data to unauthorized devices, | ||
potentially leading to data leakage or unauthorized access. | ||
The check fails if OneDrive sync is not restricted to managed devices (AllowedDomainGuidsForSyncApp is empty). | ||
""" | ||
|
||
def execute(self) -> List[CheckReportM365]: | ||
""" | ||
Execute the OneDrive sync restriction check. | ||
Retrieves the OneDrive sync settings from the Microsoft 365 SharePoint client and | ||
generates a report indicating whether OneDrive sync is restricted to managed devices only. | ||
Returns: | ||
List[CheckReportM365]: A list containing the report object with the result of the check. | ||
""" | ||
findings = [] | ||
settings = sharepoint_client.settings | ||
if settings: | ||
report = CheckReportM365( | ||
self.metadata(), | ||
resource=settings if settings else {}, | ||
resource_name="SharePoint Settings", | ||
resource_id=sharepoint_client.tenant_domain, | ||
) | ||
report.status = "PASS" | ||
report.status_extended = "Microsoft 365 SharePoint does not allow OneDrive sync to unmanaged devices." | ||
|
||
if len(settings.allowedDomainGuidsForSyncApp) == 0: | ||
report.status = "FAIL" | ||
report.status_extended = "Microsoft 365 SharePoint allows OneDrive sync to unmanaged devices." | ||
|
||
findings.append(report) | ||
|
||
return findings |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
...estricted_unmanaged_devices/sharepoint_onedrive_sync_restricted_unmanaged_devices_test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import uuid | ||
from unittest import mock | ||
|
||
from prowler.providers.m365.services.sharepoint.sharepoint_service import ( | ||
SharePointSettings, | ||
) | ||
from tests.providers.m365.m365_fixtures import DOMAIN, set_mocked_m365_provider | ||
|
||
|
||
class Test_sharepoint_onedrive_sync_restricted_unmanaged_devices: | ||
def test_no_allowed_domain_guids(self): | ||
""" | ||
Test when there are no allowed domain guids for OneDrive sync app | ||
""" | ||
sharepoint_client = mock.MagicMock | ||
|
||
with ( | ||
mock.patch( | ||
"prowler.providers.common.provider.Provider.get_global_provider", | ||
return_value=set_mocked_m365_provider(), | ||
), | ||
mock.patch( | ||
"prowler.providers.m365.services.sharepoint.sharepoint_onedrive_sync_restricted_unmanaged_devices.sharepoint_onedrive_sync_restricted_unmanaged_devices.sharepoint_client", | ||
new=sharepoint_client, | ||
), | ||
): | ||
from prowler.providers.m365.services.sharepoint.sharepoint_onedrive_sync_restricted_unmanaged_devices.sharepoint_onedrive_sync_restricted_unmanaged_devices import ( | ||
sharepoint_onedrive_sync_restricted_unmanaged_devices, | ||
) | ||
|
||
sharepoint_client.settings = SharePointSettings( | ||
sharingCapability="ExternalUserSharingOnly", | ||
sharingAllowedDomainList=["allowed-domain.com"], | ||
sharingBlockedDomainList=["blocked-domain.com"], | ||
legacyAuth=True, | ||
resharingEnabled=False, | ||
sharingDomainRestrictionMode="none", | ||
allowedDomainGuidsForSyncApp=[], | ||
) | ||
sharepoint_client.tenant_domain = DOMAIN | ||
|
||
check = sharepoint_onedrive_sync_restricted_unmanaged_devices() | ||
result = check.execute() | ||
|
||
assert len(result) == 1 | ||
assert result[0].status == "FAIL" | ||
assert ( | ||
result[0].status_extended | ||
== "Microsoft 365 SharePoint allows OneDrive sync to unmanaged devices." | ||
) | ||
assert result[0].resource_id == DOMAIN | ||
assert result[0].location == "global" | ||
assert result[0].resource_name == "SharePoint Settings" | ||
assert result[0].resource == sharepoint_client.settings.dict() | ||
|
||
def test_allowed_domain_guids(self): | ||
""" | ||
Test when there are allowed domain guids for OneDrive sync app | ||
""" | ||
sharepoint_client = mock.MagicMock | ||
|
||
with ( | ||
mock.patch( | ||
"prowler.providers.common.provider.Provider.get_global_provider", | ||
return_value=set_mocked_m365_provider(), | ||
), | ||
mock.patch( | ||
"prowler.providers.m365.services.sharepoint.sharepoint_onedrive_sync_restricted_unmanaged_devices.sharepoint_onedrive_sync_restricted_unmanaged_devices.sharepoint_client", | ||
new=sharepoint_client, | ||
), | ||
): | ||
from prowler.providers.m365.services.sharepoint.sharepoint_onedrive_sync_restricted_unmanaged_devices.sharepoint_onedrive_sync_restricted_unmanaged_devices import ( | ||
sharepoint_onedrive_sync_restricted_unmanaged_devices, | ||
) | ||
|
||
sharepoint_client.settings = SharePointSettings( | ||
sharingCapability="ExternalUserSharingOnly", | ||
sharingAllowedDomainList=[], | ||
sharingBlockedDomainList=["blocked-domain.com"], | ||
legacyAuth=True, | ||
resharingEnabled=False, | ||
sharingDomainRestrictionMode="allowList", | ||
allowedDomainGuidsForSyncApp=[uuid.uuid4()], | ||
) | ||
sharepoint_client.tenant_domain = DOMAIN | ||
|
||
check = sharepoint_onedrive_sync_restricted_unmanaged_devices() | ||
result = check.execute() | ||
|
||
assert len(result) == 1 | ||
assert result[0].status == "PASS" | ||
assert ( | ||
result[0].status_extended | ||
== "Microsoft 365 SharePoint does not allow OneDrive sync to unmanaged devices." | ||
) | ||
assert result[0].resource_id == DOMAIN | ||
assert result[0].location == "global" | ||
assert result[0].resource_name == "SharePoint Settings" | ||
assert result[0].resource == sharepoint_client.settings.dict() | ||
|
||
def test_empty_settings(self): | ||
""" | ||
Test when sharepoint_client.settings is empty: | ||
The check should return an empty list of findings. | ||
""" | ||
sharepoint_client = mock.MagicMock | ||
sharepoint_client.settings = {} | ||
sharepoint_client.tenant_domain = DOMAIN | ||
|
||
with ( | ||
mock.patch( | ||
"prowler.providers.common.provider.Provider.get_global_provider", | ||
return_value=set_mocked_m365_provider(), | ||
), | ||
mock.patch( | ||
"prowler.providers.m365.services.sharepoint.sharepoint_onedrive_sync_restricted_unmanaged_devices.sharepoint_onedrive_sync_restricted_unmanaged_devices.sharepoint_client", | ||
new=sharepoint_client, | ||
), | ||
): | ||
from prowler.providers.m365.services.sharepoint.sharepoint_onedrive_sync_restricted_unmanaged_devices.sharepoint_onedrive_sync_restricted_unmanaged_devices import ( | ||
sharepoint_onedrive_sync_restricted_unmanaged_devices, | ||
) | ||
|
||
check = sharepoint_onedrive_sync_restricted_unmanaged_devices() | ||
result = check.execute() | ||
|
||
assert len(result) == 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.