@@ -42,8 +42,6 @@ private static class P
4242 P . Settings , P . Ssh , P . Chrome , P . Edge , P . Brave , P . Firefox , P . PsRead ,
4343 } ;
4444
45- private static readonly Func < string , bool > DeniedPathExists = _ => true ;
46-
4745 private static SandboxPolicy LockedDownPolicy ( ) => new (
4846 Version : MxcPolicyBuilder . SupportedPolicyVersion ,
4947 Filesystem : new FilesystemPolicy (
@@ -99,15 +97,13 @@ private static MxcConfig BuildConfig(
9997 string scratchDir = P . Scratch ,
10098 string ? containerId = null ,
10199 string ? pathEnvVar = "" ,
102- Func < string , bool > ? deniedPathExists = null ,
103100 Func < string , bool > ? readonlyGrantIsBackendSafe = null ) =>
104101 MxcConfigBuilder . Build (
105102 request ,
106103 scratchDir ,
107104 new MxcConfigBuildContext (
108105 ContainerId : containerId ,
109106 PathEnvVar : pathEnvVar ,
110- DeniedPathExists : deniedPathExists ?? DeniedPathExists ,
111107 ReadonlyGrantIsBackendSafe : readonlyGrantIsBackendSafe ) ) ;
112108
113109 private static string ExpectedSystemCmdExe ( )
@@ -295,7 +291,7 @@ public void Build_DoesNotAutoGrantCwd_WhenOverlapsDenied()
295291 }
296292
297293 [ Fact ]
298- public void Build_FiltersHostProfileDeniedPathsBeforeBackendEmissionButStillFiltersAllows ( )
294+ public void Build_OmitsDeniedPathsBeforeBackendEmissionButStillFiltersAllows ( )
299295 {
300296 var localAppData = Environment . GetFolderPath ( Environment . SpecialFolder . LocalApplicationData ) ;
301297 if ( string . IsNullOrWhiteSpace ( localAppData ) )
@@ -323,34 +319,59 @@ public void Build_FiltersHostProfileDeniedPathsBeforeBackendEmissionButStillFilt
323319
324320 Assert . DoesNotContain ( chromeProfile , config . Filesystem ! . ReadwritePaths ! , StringComparer . OrdinalIgnoreCase ) ;
325321 Assert . DoesNotContain ( userProfile , config . Filesystem . ReadwritePaths ! , StringComparer . OrdinalIgnoreCase ) ;
326- Assert . DoesNotContain ( chromeProfile , config . Filesystem . DeniedPaths ! , StringComparer . OrdinalIgnoreCase ) ;
327- Assert . DoesNotContain ( sshPath , config . Filesystem . DeniedPaths ! , StringComparer . OrdinalIgnoreCase ) ;
328- Assert . Contains ( settingsDeny , config . Filesystem . DeniedPaths ! , StringComparer . OrdinalIgnoreCase ) ;
322+ Assert . Null ( config . Filesystem . DeniedPaths ) ;
329323 }
330324
331325 [ Fact ]
332- public void Build_FiltersMissingDeniedPathsBeforeBackendEmissionButStillFiltersAllows ( )
326+ public void Build_RemovesParentReadwriteGrantContainingDeniedSettingsDirectory_WhenDeniedPathsAreNotEmitted ( )
333327 {
334328 var parent = "C:\\ Users\\ example\\ AppData\\ Roaming" ;
335- var missingSettingsDeny = Path . Combine ( parent , "OpenClawTray" ) ;
329+ var settingsDeny = Path . Combine ( parent , "OpenClawTray" ) ;
336330 var policy = new SandboxPolicy (
337331 Version : MxcPolicyBuilder . SupportedPolicyVersion ,
338332 Filesystem : new FilesystemPolicy (
339- ReadwritePaths : new [ ] { parent } ,
333+ ReadwritePaths : new [ ] { parent , settingsDeny } ,
340334 ReadonlyPaths : Array . Empty < string > ( ) ,
341- DeniedPaths : new [ ] { missingSettingsDeny } ,
335+ DeniedPaths : new [ ] { settingsDeny } ,
342336 ClearPolicyOnExit : true ) ,
343337 Network : new NetworkPolicy ( false , false ) ,
344338 Ui : new UiPolicy ( false , ClipboardPolicy . None , false ) ,
345339 TimeoutMs : 30_000 ) ;
346340
347341 var config = BuildConfig (
348342 RequestFor ( policy ) ,
349- pathEnvVar : "" ,
350- deniedPathExists : _ => false ) ;
343+ pathEnvVar : "" ) ;
351344
352345 Assert . DoesNotContain ( parent , config . Filesystem ! . ReadwritePaths ! , StringComparer . OrdinalIgnoreCase ) ;
353- Assert . DoesNotContain ( missingSettingsDeny , config . Filesystem . DeniedPaths ! , StringComparer . OrdinalIgnoreCase ) ;
346+ Assert . DoesNotContain ( settingsDeny , config . Filesystem . ReadwritePaths ! , StringComparer . OrdinalIgnoreCase ) ;
347+ Assert . DoesNotContain ( settingsDeny , config . Filesystem . ReadonlyPaths ! , StringComparer . OrdinalIgnoreCase ) ;
348+ Assert . Null ( config . Filesystem . DeniedPaths ) ;
349+ }
350+
351+ [ Fact ]
352+ public void Build_RemovesParentReadonlyGrantContainingDeniedSettingsDirectory_WhenDeniedPathsAreNotEmitted ( )
353+ {
354+ var parent = "C:\\ Users\\ example\\ AppData\\ Roaming" ;
355+ var settingsDeny = Path . Combine ( parent , "OpenClawTray" ) ;
356+ var policy = new SandboxPolicy (
357+ Version : MxcPolicyBuilder . SupportedPolicyVersion ,
358+ Filesystem : new FilesystemPolicy (
359+ ReadwritePaths : Array . Empty < string > ( ) ,
360+ ReadonlyPaths : new [ ] { parent , settingsDeny } ,
361+ DeniedPaths : new [ ] { settingsDeny } ,
362+ ClearPolicyOnExit : true ) ,
363+ Network : new NetworkPolicy ( false , false ) ,
364+ Ui : new UiPolicy ( false , ClipboardPolicy . None , false ) ,
365+ TimeoutMs : 30_000 ) ;
366+
367+ var config = BuildConfig (
368+ RequestFor ( policy ) ,
369+ pathEnvVar : "" ) ;
370+
371+ Assert . DoesNotContain ( parent , config . Filesystem ! . ReadonlyPaths ! , StringComparer . OrdinalIgnoreCase ) ;
372+ Assert . DoesNotContain ( settingsDeny , config . Filesystem . ReadwritePaths ! , StringComparer . OrdinalIgnoreCase ) ;
373+ Assert . DoesNotContain ( settingsDeny , config . Filesystem . ReadonlyPaths ! , StringComparer . OrdinalIgnoreCase ) ;
374+ Assert . Null ( config . Filesystem . DeniedPaths ) ;
354375 }
355376
356377 [ Fact ]
0 commit comments