Repository navigation
feat(files): replace per-file encryption scan with Sensitivity Labels + SharePoint REST Search API - #179
Open
rishiksingh11 wants to merge 8 commits into
Conversation
rishiksingh11
force-pushed
the
feat/encrypted-files-sensitivity-labels-search
branch
2 times, most recently
from
September 17, 2026 14:03
273961e to
2f20bc3
Compare
Contributor
Author
|
@NityamPareek Could you please review this PR when you get a chance? Thanks! |
rishiksingh11
force-pushed
the
feat/encrypted-files-sensitivity-labels-search
branch
2 times, most recently
from
September 17, 2026 15:03
ee492b5 to
da945dc
Compare
Collaborator
|
Discussed offline. Let's use sharepoint rest api instead of graph query api. Code for certificate based auth can be picked up from here : https://github.com/google/migration-planner/pull/174/changes |
rishiksingh11
force-pushed
the
feat/encrypted-files-sensitivity-labels-search
branch
from
September 18, 2026 16:42
da945dc to
7165233
Compare
Contributor
Author
|
@NityamPareek Updated the PR as discussed:
|
… + SharePoint REST Search API
rishiksingh11
force-pushed
the
feat/encrypted-files-sensitivity-labels-search
branch
from
September 23, 2026 07:58
7165233 to
ac6361a
Compare
… counts in brackets) for Emails & Files
…ails and Files - Replace combined X (Y Encrypted) bracketed counts with separate, standalone stat cards: - Exchange Online: Sensitivity Labels, Encrypted Sensitivity Labels, Sensitivity Labeled Emails, and Encrypted Emails in a dedicated row - SharePoint & OneDrive Files: Sensitivity Labels, Encrypted Sensitivity Labels, Sensitivity Labeled Files, Total Encrypted File Count, and Total Encrypted File Size in a dedicated row - Store plain integer counts in Sensitivity Labeled Email Count and Sensitivity Labeled File Count CSV columns - Refresh screenshots and local GUI screencast against live Microsoft 365 tenant
…s-shallow-scan
…crypted_files_utils.py with size-sorted streaming pagination
…g sensitivity labels
Contributor
Author
|
@NityamPareek Updated PR #179 as well with all memory management, concurrency, and Deep Scan scoping fixes (
|
…screenshots and bounded memory worker pool
Contributor
Author
|
@NityamPareek Ran Scan All Sites with Scan for Encrypted Files (RMS/MIP) enabled on the
|
jessweng10
approved these changes
Nov 27, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.



Reviewer: @NityamPareek
Summary
Replaces the legacy per-file 10KB byte-range header download (
_check_file_encryption) with a server-side Sensitivity Labels API + SharePoint REST Searchpostquery(POST /_api/search/postquery) scan (_scan_encrypted_files) to detect RMS/MIP encrypted files across OneDrive and SharePoint (in both Deep Scan and Shallow Scan modes).All legacy per-file header inspection code (
_check_file_encryption,encryption_executor,processed_encryption_count, andutil/file_encryption_detector.py) has been deleted, and all certificate-based authentication (core/cert_auth.py,util/files_shallow/cert_token_manager.py,util/files_shallow/sp_rest_connector.py,ui/files_shallow/shallow_ui_helpers.py) and Shallow Scan changes from #174 are included.Architecture Comparison: Before vs. After
1. Legacy Approach (Before): Per-File 10KB Byte-Range Download
Range: bytes=0-10239) viaGET /drives/{driveId}/items/{itemId}/contentto inspect magic bytes (\xD0\xCF\x11\xE0OLE2EncryptedPackage/DRMEncryptedTransformor rawMSMAMARPCRYPTO).O(N). In a tenant with 100,000 files, this requires 100,000 HTTP content downloads (~7.5 hours) and triggers severe SharePoint/Graph429 TooManyRequeststhrottling.2. New Approach (After): Sensitivity Labels API + SharePoint REST
postquery(IndexDocIdCursor Pagination)GET /v1.0/security/dataSecurityAndGovernance/sensitivityLabels?$select=id,name,hasProtection,sublabelsonce via Microsoft Graph to identify all sensitivity label GUIDs (including nested sublabels) configured with encryption (hasProtection == True).https://{sharepoint_domain}/.default) using Microsoft Entra ID X.509 Certificate Authentication (CertTokenManager/core/cert_auth.py).POST https://{domain}/_api/search/postquery(SpRestConnector.search_encrypted_files_by_labels):IndexDocId([DocId]:ascending):RowLimit: 500,StartRow: 0,TrimDuplicates: false, andSortList: [{"Property": "DocId", "Direction": "0"}].AND IndexDocId>{last_doc_id}toQuerytextwhile keepingStartRow: 0. This walks the SharePoint search index sequentially like a database cursor, avoidingStartRowoffset limits (50,000 cap) and Microsoft Graph Search's hard 1,000-item ceiling.Path/OriginalPath/ParentLink/SPWebUrl) andSizeback to their owningdriveId/siteIdto aggregateencryptedFileCountandencryptedFileSize.SensitivityLabels.Read.All(orInformationProtectionPolicy.Read.All)Sites.Read.All(with X.509 Certificate uploaded to Microsoft Entra App Registration)Why SharePoint REST
postqueryOver Microsoft Graph Search (POST /v1.0/search/query)POST /v1.0/search/query)POST /_api/search/postquery)from + size <= 1000)IndexDocId > {last_doc_id}cursor pagination ([DocId]:ascending)25–50items500items (RowLimit: 500)InformationProtectionLabelId,DocId,Size,PathPath:"https://tenant.sharepoint.com/sites/TargetSite*"across sites, subsites, and DLsCertTokenManager/core/cert_auth.py)Live Benchmark (
rishiktest.onmicrosoft.com)O(N)— ~100,000 calls (~7.5 hrs)O(1)— ~2 calls (~1.5 sec)109.07 MB)109.07 MB)UI Screenshots
1. Configuration UI (
Scan for Encrypted Files (RMS/MIP)enabled under Advanced Settings)2. API Permission Notice Dialog
Displayed before starting the scan when

Scan for Encrypted Files (RMS/MIP)is selected, followed by the X.509 Certificate setup modal (ensure_certificates_and_prompt):3. Scan Results UI (
Total Encrypted File Count: 11,Total Encrypted File Size: 109.07 MB)3.
googlellc914Load-Test Tenant (16,285Sites) —Scan All Sites+Encrypted FilesMemory Usage Proof8c838f69-e747-41fa-a86d-e63d579f59cb(googlellc914/deal_assistant_test_app)Scan All Sites(Deep Scan,Personal Sites (OneDrive)+SharePoint Sites,Scan for Encrypted Files (RMS/MIP)enabled)16,285Sites (15,268SharePoint Team Sites +1,017OneDrive Personal Sites) |3,013,673Files (4.21 TB)psutilProcess RSS): Avg157.6 MB/ Peak227.7 MB(0.22%System RAM) — boundedO(1)worker pool (max_workers=3) with immediate per-pagedel rowscleanup and per-batch tree cleanup (del batch_adj_list, batch_parent_refs, batch_folder_nodes).googlellc914Configuration (Scan All Sites)googlellc914Data Corpus Report (16,285Sites)Live Process RSS Memory Profile (
googlellc914—16,285Sites)