Skip to content

bug(freeze): check-freeze.sh allows boundary escape when target parent directory does not exist and mis-resolves tilde paths #3623

Closed

Description

@Quinnod345

Summary

freeze/bin/check-freeze.sh has two boundary-check issues:

1. _resolve_path falls back to the uncanonicalized string when a parent directory does not exist (freeze/bin/check-freeze.sh:169-188)

_resolve_path only follows symlinks on the final path component (while [ -L "$_p" ]) and runs cd "$_dir" 2>/dev/null && pwd -P || printf '%s' "$_dir" on the immediate parent directory.

Whenever a parent directory does not exist yet (for example, Write or NotebookEdit creating a file in a new subdirectory), cd "$_dir" fails and falls back to the raw uncanonicalized _dir string:

  1. Boundary escape via .. through a non-existent directory:
    Passing file_path: "<boundary>/../outside/new-dir/secret.ts" fails cd on outside/new-dir, keeps the literal <boundary>/ prefix, matches "${FREEZE_DIR%/}/"* at line 194, and returns {} (allow).
  2. Boundary escape via an in-boundary directory symlink + non-existent subdirectory:
    If <boundary>/out-link is a symlink pointing outside <boundary>, passing file_path: "<boundary>/out-link/new-dir/secret.ts" fails both [ -L "$_p" ] (final component does not exist) and cd (new-dir does not exist), keeps <boundary>/out-link/..., and returns {} (allow).
  3. Boundary escape via trailing ..:
    Passing file_path: "<boundary>/.." resolves dirname to <boundary> and basename to .., reconstructing <boundary>/.. and matching "${FREEZE_DIR%/}/"* (allow).
  4. False denial on macOS for new subdirectories inside a frozen directory:
    When a frozen directory sits under a symlinked parent (/tmp -> /private/tmp or /var/folders -> /private/var/folders on macOS), FREEZE_DIR resolves via pwd -P to /private/var/folders/.../boundary, while creating <boundary>/new-subdir/Component.tsx fails cd on new-subdir and stays /var/folders/.../boundary/new-subdir/Component.tsx, falsely denying an in-boundary write.

2. Missing tilde (~/) expansion on FILE_PATH and GNU BRE \+ in sed (freeze/bin/check-freeze.sh:85-88, 143-159)

  • FREEZE_DIR expands a leading ~/ or ~ to $HOME at lines 85-88, but FILE_PATH omits tilde expansion at lines 143-149 and instead prepends $(pwd)/. When pwd is inside FREEZE_DIR, an out-of-boundary tilde path like ~/.zshrc becomes $(pwd)/~/.zshrc and is allowed; when pwd is outside FREEZE_DIR, an in-boundary tilde path like ~/project/src/index.ts is denied.
  • Line 157 uses sed 's|/\+|/|g;s|/$||', where \+ is a GNU BRE extension that macOS BSD sed reads as a literal + rather than one-or-more slashes (//* in POSIX BRE).

Reproduction

# 1. Create a freeze boundary and a state file (use pwd -P so macOS /tmp -> /private/tmp does not mask it)
mkdir -p /tmp/freeze-repro/boundary /tmp/freeze-repro/outside
T="$(cd /tmp/freeze-repro && pwd -P)"
printf '%s/boundary\n' "$T" > "$T/freeze-dir.txt"

# 2. Pass a path that traverses out of the boundary into a non-existent directory
printf '{"tool_input":{"file_path":"%s/boundary/../outside/new-dir/secret.ts"}}' "$T" \
  | GSTACK_STATE_DIR="$T" bash freeze/bin/check-freeze.sh
# Actual output on main: {} (allowed)
# Expected output: {"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny",...}}

Companion PR: #3624 (test/hook-scripts.test.ts, 315 pass, 0 fail).

Activity

  1. added
    S1
    on Oct 31, 2026
  2. capy-ai commented on Nov 1, 2026

    @capy-ai
    Contributor

    Fixed in #3758, merged as 510dd07 and released in v1.92.9.0. /freeze now resolves the whole path, including .., symlinks inside folders that don't exist yet, and ~. It blocks any edit whose path it can't resolve. Thanks @Quinnod345 for the clear report and repro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    S1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions