fix: expand ${CWD}/${HOME}/${TMPDIR} in --sandbox-allow path overrides (#344)

The runtime --sandbox-allow CLI override path never expanded the supported
sandbox variables (${CWD}, ${HOME}, ${TMPDIR}), so a value like
write='${CWD}/**' was treated as a literal path segment and the allow rule
never matched. Profile-loaded sandbox paths already expand these via
sandbox/util.ExpandVariables.

Expand the variables in resolveToAbsolute, the shared chokepoint for
read/write/exec overrides, before resolving to an absolute path. Glob
characters are preserved through expansion and filepath.Clean.

Fixes #257

Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
This commit is contained in:
Matt Van Horn
2026-06-18 12:17:33 +05:30
committed by GitHub
co-authored by Matt Van Horn
parent 55f3f2a252
commit c17b941ac3
2 changed files with 73 additions and 0 deletions
+6
View File
@@ -8,6 +8,7 @@ import (
"unicode"
"github.com/safedep/dry/log"
sandboxutil "github.com/safedep/pmg/sandbox/util"
)
// validSandboxAllowTypes is the set of recognized --sandbox-allow type prefixes.
@@ -217,6 +218,11 @@ func isLocalhostAddress(host string) bool {
// resolveToAbsolute resolves a path to an absolute path relative to CWD.
// Glob characters are preserved. The path is cleaned via filepath.Clean().
func resolveToAbsolute(value string) (string, error) {
value, err := sandboxutil.ExpandVariables(value)
if err != nil {
return "", err
}
if filepath.IsAbs(value) {
return filepath.Clean(value), nil
}