Skip to content

πŸš€ The fast, Pythonic way to build MCP servers and clients.

Restrict Windows CLI state access without requiring SeSecurityPrivilege (#5312)

Asem ahmedb9a874c4902c
diff --git a/fastmcp_slim/fastmcp/cli/deploy/state.py b/fastmcp_slim/fastmcp/cli/deploy/state.py
index 55cad4d74..a5563af52 100644
--- a/fastmcp_slim/fastmcp/cli/deploy/state.py
+++ b/fastmcp_slim/fastmcp/cli/deploy/state.py
@@ -25,7 +25,8 @@ _WINDOWS_ACL_SCRIPT = r"""
$ErrorActionPreference = "Stop"
$path = $env:FASTMCP_STATE_PATH
$sid = [System.Security.Principal.WindowsIdentity]::GetCurrent().User
-$acl = Get-Acl -LiteralPath $path
+$item = Get-Item -LiteralPath $path -Force
+$acl = $item.GetAccessControl("Access")
$acl.SetAccessRuleProtection($true, $false)
foreach ($existingRule in @($acl.Access)) {
$acl.RemoveAccessRuleSpecific($existingRule)
@@ -50,7 +51,7 @@ if ([System.IO.Directory]::Exists($path)) {
}
$acl.AddAccessRule($rule)
-Set-Acl -LiteralPath $path -AclObject $acl
+$item.SetAccessControl($acl)
"""
diff --git a/tests/cli/deploy/test_credentials.py b/tests/cli/deploy/test_credentials.py
index f62b3dc02..c508be028 100644
--- a/tests/cli/deploy/test_credentials.py
+++ b/tests/cli/deploy/test_credentials.py
@@ -260,7 +260,12 @@ def test_windows_acl_replaces_the_existing_access_list(
]
assert state_paths == [str(path)]
assert "$path = $env:FASTMCP_STATE_PATH" in calls[0][5]
- assert "Get-Acl -LiteralPath $path" in calls[0][5]
+ # `Set-Acl` needs SeSecurityPrivilege once the access list is protected,
+ # so a non-elevated user could not re-apply it; only the access list is
+ # read and written back.
+ assert '$item.GetAccessControl("Access")' in calls[0][5]
+ assert "$item.SetAccessControl($acl)" in calls[0][5]
+ assert "Set-Acl" not in calls[0][5]
assert "SetAccessRuleProtection($true, $false)" in calls[0][5]
assert "RemoveAccessRuleSpecific($existingRule)" in calls[0][5]