Skip to content

Commit 37b154b

Browse files
committed
fix(linux): remove expensive glob expansion for mandatory deny patterns
The glob expansion using **/pattern patterns caused full filesystem walks of the current directory for each pattern (~15 patterns = ~15 walks). This caused hangs in directories with many files (e.g., node_modules). The concrete paths from getMandatoryDenyPaths() are sufficient for bwrap's --ro-bind protections. Landlock (applied via wrapper) provides additional recursive protection. Fixes #27
1 parent b14f707 commit 37b154b

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

internal/sandbox/linux.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -477,14 +477,15 @@ func WrapCommandLinuxWithOptions(cfg *config.Config, command string, bridge *Lin
477477

478478
// Apply mandatory deny patterns (make dangerous files/dirs read-only)
479479
// This overrides any writable mounts for these paths
480+
//
481+
// Note: We only use concrete paths from getMandatoryDenyPaths(), NOT glob expansion.
482+
// GetMandatoryDenyPatterns() returns expensive **/pattern globs that require walking
483+
// the entire directory tree - this can hang on large directories (see issue #27).
484+
// The concrete paths already cover dangerous files in cwd and home directory,
485+
// which is sufficient protection for bwrap's --ro-bind. Landlock (applied separately
486+
// via the wrapper) provides additional recursive protection.
480487
mandatoryDeny := getMandatoryDenyPaths(cwd)
481488

482-
// Expand glob patterns for mandatory deny
483-
allowGitConfig := cfg != nil && cfg.Filesystem.AllowGitConfig
484-
mandatoryGlobs := GetMandatoryDenyPatterns(cwd, allowGitConfig)
485-
expandedMandatory := ExpandGlobPatterns(mandatoryGlobs)
486-
mandatoryDeny = append(mandatoryDeny, expandedMandatory...)
487-
488489
// Deduplicate
489490
seen := make(map[string]bool)
490491
for _, p := range mandatoryDeny {

0 commit comments

Comments
 (0)